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_);
47 SurfaceSDL* create_SurfaceSDL();
48 SurfaceOpenGL* create_SurfaceOpenGL();
49 SurfaceImpl* create();
52 /** Container class that holds a surface, necessary so that we can
53 switch Surface implementations (OpenGL, SDL) on the fly */
62 typedef std::list<Surface*> Surfaces;
63 static Surfaces surfaces;
65 static void reload_all();
67 Surface(SDL_Surface* surf, int use_alpha);
68 Surface(const std::string& file, int use_alpha);
69 Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
72 /** Reload the surface, which is necesarry in case of a mode swich */
75 void draw(float x, float y, Uint8 alpha = 255, bool update = false);
76 void draw_bg(Uint8 alpha = 255, bool update = false);
77 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
80 /** Surface implementation, all implementation have to inherit from
85 SDL_Surface* sdl_surface;
90 virtual void draw(float x, float y, Uint8 alpha, bool update) = 0;
91 virtual void draw_bg(Uint8 alpha, bool update) = 0;
92 virtual void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
95 class SurfaceSDL : public SurfaceImpl
100 SurfaceSDL(SDL_Surface* surf, int use_alpha);
101 SurfaceSDL(const std::string& file, int use_alpha);
102 SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
103 virtual ~SurfaceSDL();
105 void draw(float x, float y, Uint8 alpha, bool update);
106 void draw_bg(Uint8 alpha, bool update);
107 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
110 class SurfaceOpenGL : public SurfaceImpl
116 SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
117 SurfaceOpenGL(const std::string& file, int use_alpha);
118 SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
119 virtual ~SurfaceOpenGL();
121 void draw(float x, float y, Uint8 alpha, bool update);
122 void draw_bg(Uint8 alpha, bool update);
123 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
126 void create_gl(SDL_Surface * surf, GLuint * tex);
129 #endif /*SUPERTUX_TEXTURE_H*/
131 /* Local Variables: */