2 // C Interface: texture
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
13 #ifndef SUPERTUX_TEXTURE_H
14 #define SUPERTUX_TEXTURE_H
19 #include <SDL_opengl.h>
29 /** This class holds all the data necessary to construct a surface */
33 enum ConstructorType { LOAD, LOAD_PART, SURFACE };
43 SurfaceData(SDL_Surface* surf, int use_alpha_);
44 SurfaceData(const std::string& file_, int use_alpha_);
45 SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_);
48 SurfaceSDL* create_SurfaceSDL();
49 SurfaceOpenGL* create_SurfaceOpenGL();
50 SurfaceImpl* create();
53 /** Container class that holds a surface, necessary so that we can
54 switch Surface implementations (OpenGL, SDL) on the fly */
63 typedef std::list<Surface*> Surfaces;
64 static Surfaces surfaces;
66 static void reload_all();
68 Surface(SDL_Surface* surf, int use_alpha);
69 Surface(const std::string& file, int use_alpha);
70 Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
73 /** Reload the surface, which is necesarry in case of a mode swich */
76 void draw(float x, float y, Uint8 alpha = 255, bool update = false);
77 void draw_bg(Uint8 alpha = 255, bool update = false);
78 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
81 /** Surface implementation, all implementation have to inherit from
86 SDL_Surface* sdl_surface;
91 /** Return 0 on success, -2 if surface needs to be reloaded */
92 virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
93 virtual int draw_bg(Uint8 alpha, bool update) = 0;
94 virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
97 class SurfaceSDL : public SurfaceImpl
102 SurfaceSDL(SDL_Surface* surf, int use_alpha);
103 SurfaceSDL(const std::string& file, int use_alpha);
104 SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
105 virtual ~SurfaceSDL();
107 int draw(float x, float y, Uint8 alpha, bool update);
108 int draw_bg(Uint8 alpha, bool update);
109 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
112 class SurfaceOpenGL : public SurfaceImpl
118 SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
119 SurfaceOpenGL(const std::string& file, int use_alpha);
120 SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
121 virtual ~SurfaceOpenGL();
123 int draw(float x, float y, Uint8 alpha, bool update);
124 int draw_bg(Uint8 alpha, bool update);
125 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
128 void create_gl(SDL_Surface * surf, GLuint * tex);
131 #endif /*SUPERTUX_TEXTURE_H*/
133 /* Local Variables: */