9 #include <SDL/SDL_opengl.h>
11 #define GRID_SIZE 64.0
13 typedef SDL_Surface Screen;
14 typedef SDL_Rect Rectangle;
15 typedef short unsigned int SUint;
16 typedef unsigned char Uint8;
40 Colour(float red=0, float green=0, float blue=0, float alpha=0) : r(red), g(green), b(blue), a(alpha) {}
41 Colour(const Colour & cpy) : r(cpy.r), g(cpy.g), b(cpy.b), a(cpy.a) {}
43 Colour & operator=(const Colour & s) {r = s.r; g = s.g; b = s.b; a = s.a; return *this;}
44 bool operator==(const Colour & s) const {return (r == s.r && g == s.g && b == s.b && a == s.a);}
45 bool operator!=(const Colour & s) const {return !operator==(s);}
52 static int ScreenWidth() {return screenWidth;}
53 static int ScreenHeight() {return screenHeight;}
55 static void Initialise(const char * caption, int width=640, int height=480);
56 static void Destroy();
58 static SDL_Surface * LoadTextureBMP(const char * file);
59 static void SaveTextureBMP(SDL_Surface * tex, const char * file);
61 static void ClearScreen();
62 static void UpdateScreen();
63 static void DrawGrid(int gridWidth, int gridHeight, Colour colour);
64 static Uint8 MakeColour(int R, int G, int B, int Alpha = 0);
65 static Colour ConvertColour(Uint8 colour);
67 static void DrawTexture(SDL_Surface * src, int destX, int destY, int srcX=0, int srcY=0, int width=-1, int height=-1);
68 static void DrawTexture(SDL_Surface * src, int destX, int destY, double rotate, double scale);
69 static void DrawPixel(int x, int y, Colour colour);
71 static Colour GetPixel(int x, int y);
72 static void DrawLine(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0);
73 static void DrawLineDashed(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0);
74 static void DrawRectangle(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0);
76 static void GetColourData(SDL_Surface * src, std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
77 static void GetColourData(SDL_Surface * src, std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
79 static void DrawColourData(int destX, int destY, std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL) {DrawColourData(screen, destX, destY, R, G, B, A);}
81 static void DrawColourData(int destX, int destY, std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL) {DrawColourData(screen, destX, destY, R, G, B, A);}
83 static SDL_Surface * TextureFromColours(std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
84 static SDL_Surface * TextureFromColours(std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
86 static void Wait(int n);
93 virtual ~TextureManager() {}
95 virtual Texture & operator[](const T & at) = 0;
98 static bool Initialised() {return initialised;}
99 static void ScreenShot(const char * fileName);
101 static void DrawColourData(SDL_Surface * dest, int destX, int destY, std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
102 static void DrawColourData(SDL_Surface * dest, int destX, int destY, std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
103 static void DrawTexture(SDL_Surface * dest, SDL_Surface * src, int srcX, int srcY, int destX, int destY, int width, int height);
104 static void DrawPixel(SDL_Surface * dest, int x, int y, Colour colour);
105 static Colour GetPixel(SDL_Surface * dest, int x, int y);
106 static void DrawLine(SDL_Surface * dest, int x1, int y1, int x2, int y2, Colour colour);
111 static std::list<SDL_Surface*> allTextures;
112 static Screen * screen;
114 static int screenWidth;
115 static int screenHeight;
116 static bool initialised;
120 typedef Graphics::Colour Colour;
125 Texture(const char * fileName, bool newDrawCentred = true);
128 void Draw(int x, int y, double angle=0, double scale=1);
129 void DrawColour(int x, int y, double angle, double scale, Colour colour);
131 int width() const {return surface->w;}
132 int height() const {return surface->h;}
135 SDL_Surface * surface;
143 class Font : private Texture
146 Font(const char * fileName, int newWidth, int newHeight);
149 void DrawTextColour(const char * string, int x, int y, double angle, double scale, Colour colour);
150 void DrawText(const char * string, int x, int y, double angle=0, double scale=1);
161 #endif //BUILD_GRAPHICS