4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 #ifndef SUPERTUX_TEXTURE_H
22 #define SUPERTUX_TEXTURE_H
27 #include <SDL_opengl.h>
34 SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha);
40 /** This class holds all the data necessary to construct a surface */
44 enum ConstructorType { LOAD, LOAD_PART, SURFACE };
54 SurfaceData(SDL_Surface* surf, int use_alpha_);
55 SurfaceData(const std::string& file_, int use_alpha_);
56 SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_);
59 SurfaceSDL* create_SurfaceSDL();
60 SurfaceOpenGL* create_SurfaceOpenGL();
61 SurfaceImpl* create();
64 /** Container class that holds a surface, necessary so that we can
65 switch Surface implementations (OpenGL, SDL) on the fly */
74 typedef std::list<Surface*> Surfaces;
75 static Surfaces surfaces;
77 static void reload_all();
78 static void debug_check();
80 Surface(SDL_Surface* surf, int use_alpha);
81 Surface(const std::string& file, int use_alpha);
82 Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
85 /** Captures the screen and returns it as Surface*, the user is expected to call the destructor. */
86 static Surface* CaptureScreen();
88 /** Reload the surface, which is necesarry in case of a mode swich */
91 void draw(float x, float y, Uint8 alpha = 255, bool update = false);
92 void draw_bg(Uint8 alpha = 255, bool update = false);
93 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
94 void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false);
95 void resize(int w_, int h_);
97 /// conveniance function
98 void draw(const Vector& pos, Uint8 alpha = 255, bool update = false)
100 draw(pos.x, pos.y, alpha, update);
104 /** Surface implementation, all implementation have to inherit from
109 SDL_Surface* sdl_surface;
117 virtual ~SurfaceImpl();
119 /** Return 0 on success, -2 if surface needs to be reloaded */
120 virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
121 virtual int draw_bg(Uint8 alpha, bool update) = 0;
122 virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
123 virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
124 int resize(int w_, int h_);
126 SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
129 class SurfaceSDL : public SurfaceImpl
132 SurfaceSDL(SDL_Surface* surf, int use_alpha);
133 SurfaceSDL(const std::string& file, int use_alpha);
134 SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
135 virtual ~SurfaceSDL();
137 int draw(float x, float y, Uint8 alpha, bool update);
138 int draw_bg(Uint8 alpha, bool update);
139 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
140 int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
144 class SurfaceOpenGL : public SurfaceImpl
150 SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
151 SurfaceOpenGL(const std::string& file, int use_alpha);
152 SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
153 virtual ~SurfaceOpenGL();
155 int draw(float x, float y, Uint8 alpha, bool update);
156 int draw_bg(Uint8 alpha, bool update);
157 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
158 int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
161 void create_gl(SDL_Surface * surf, GLuint * tex);
165 #endif /*SUPERTUX_TEXTURE_H*/
167 /* Local Variables: */