ddnet/src/engine/client/graphics.h

148 lines
3.6 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_CLIENT_GRAPHICS_H
#define ENGINE_CLIENT_GRAPHICS_H
2009-10-29 12:14:31 +00:00
2010-05-29 07:25:38 +00:00
class CGraphics_OpenGL : public IEngineGraphics
2009-10-29 12:14:31 +00:00
{
protected:
2010-05-29 07:25:38 +00:00
class IStorage *m_pStorage;
class IConsole *m_pConsole;
2010-05-29 07:25:38 +00:00
//
typedef struct { float x, y, z; } CPoint;
typedef struct { float u, v; } CTexCoord;
typedef struct { float r, g, b, a; } CColor;
typedef struct
{
CPoint m_Pos;
CTexCoord m_Tex;
CColor m_Color;
} CVertex;
2010-05-29 07:25:38 +00:00
enum
{
MAX_VERTICES = 32*1024,
MAX_TEXTURES = 1024*4,
2010-05-29 07:25:38 +00:00
DRAWING_QUADS=1,
DRAWING_LINES=2
2010-05-29 07:25:38 +00:00
};
CVertex m_aVertices[MAX_VERTICES];
int m_NumVertices;
CColor m_aColor[4];
CTexCoord m_aTexture[4];
bool m_RenderEnable;
float m_Rotation;
int m_Drawing;
bool m_DoScreenshot;
char m_aScreenshotName[128];
2010-05-29 07:25:38 +00:00
float m_ScreenX0;
float m_ScreenY0;
float m_ScreenX1;
float m_ScreenY1;
int m_InvalidTexture;
struct CTexture
{
GLuint m_Tex;
int m_MemSize;
int m_Flags;
int m_Next;
};
CTexture m_aTextures[MAX_TEXTURES];
int m_FirstFreeTexture;
int m_TextureMemoryUsage;
void Flush();
void AddVertices(int Count);
2010-08-05 18:55:51 +00:00
void Rotate4(const CPoint &rCenter, CVertex *pPoints);
2010-05-29 07:25:38 +00:00
static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset);
public:
CGraphics_OpenGL();
2010-05-29 07:25:38 +00:00
virtual void ClipEnable(int x, int y, int w, int h);
virtual void ClipDisable();
2010-05-29 07:25:38 +00:00
virtual void BlendNone();
virtual void BlendNormal();
virtual void BlendAdditive();
virtual int MemoryUsage() const;
2010-05-29 07:25:38 +00:00
virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY);
virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY);
virtual void LinesBegin();
virtual void LinesEnd();
virtual void LinesDraw(const CLineItem *pArray, int Num);
2010-05-29 07:25:38 +00:00
virtual int UnloadTexture(int Index);
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);
// simple uncompressed RGBA loaders
2010-10-06 21:07:35 +00:00
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags);
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType);
2010-05-29 07:25:38 +00:00
void ScreenshotDirect(const char *pFilename);
virtual void TextureSet(int TextureID);
virtual void Clear(float r, float g, float b);
virtual void QuadsBegin();
virtual void QuadsEnd();
virtual void QuadsSetRotation(float Angle);
virtual void SetColorVertex(const CColorVertex *pArray, int Num);
virtual void SetColor(float r, float g, float b, float a);
virtual void QuadsSetSubset(float TlU, float TlV, float BrU, float BrV);
virtual void QuadsSetSubsetFree(
float x0, float y0, float x1, float y1,
float x2, float y2, float x3, float y3);
virtual void QuadsDraw(CQuadItem *pArray, int Num);
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num);
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num);
virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText);
2010-05-29 07:25:38 +00:00
virtual bool Init();
2009-10-29 12:14:31 +00:00
};
2010-05-29 07:25:38 +00:00
class CGraphics_SDL : public CGraphics_OpenGL
2009-10-29 12:14:31 +00:00
{
SDL_Surface *m_pScreenSurface;
2010-05-29 07:25:38 +00:00
int TryInit();
int InitWindow();
public:
CGraphics_SDL();
virtual bool Init();
virtual void Shutdown();
virtual void Minimize();
virtual void Maximize();
virtual int WindowActive();
virtual int WindowOpen();
virtual void TakeScreenshot(const char *pFilename);
2010-05-29 07:25:38 +00:00
virtual void Swap();
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes);
2009-10-29 12:14:31 +00:00
};
2010-05-29 07:25:38 +00:00
#endif