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>
33 SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha);
39 /** This class holds all the data necessary to construct a surface */
43 enum ConstructorType { LOAD, LOAD_PART, SURFACE };
53 SurfaceData(SDL_Surface* surf, int use_alpha_);
54 SurfaceData(const std::string& file_, int use_alpha_);
55 SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_);
58 SurfaceSDL* create_SurfaceSDL();
59 SurfaceOpenGL* create_SurfaceOpenGL();
60 SurfaceImpl* create();
63 /** Container class that holds a surface, necessary so that we can
64 switch Surface implementations (OpenGL, SDL) on the fly */
73 typedef std::list<Surface*> Surfaces;
74 static Surfaces surfaces;
76 static void reload_all();
77 static void debug_check();
79 Surface(SDL_Surface* surf, int use_alpha);
80 Surface(const std::string& file, int use_alpha);
81 Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
84 /** Captures the screen and returns it as Surface*, the user is expected to call the destructor. */
85 static Surface* CaptureScreen();
87 /** Reload the surface, which is necesarry in case of a mode swich */
90 void draw(float x, float y, Uint8 alpha = 255, bool update = false);
91 void draw_bg(Uint8 alpha = 255, bool update = false);
92 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
93 void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false);
94 void resize(int w_, int h_);
97 /** Surface implementation, all implementation have to inherit from
102 SDL_Surface* sdl_surface;
110 virtual ~SurfaceImpl();
112 /** Return 0 on success, -2 if surface needs to be reloaded */
113 virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
114 virtual int draw_bg(Uint8 alpha, bool update) = 0;
115 virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
116 virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
117 int resize(int w_, int h_);
119 SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
122 class SurfaceSDL : public SurfaceImpl
125 SurfaceSDL(SDL_Surface* surf, int use_alpha);
126 SurfaceSDL(const std::string& file, int use_alpha);
127 SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
128 virtual ~SurfaceSDL();
130 int draw(float x, float y, Uint8 alpha, bool update);
131 int draw_bg(Uint8 alpha, bool update);
132 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
133 int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
137 class SurfaceOpenGL : public SurfaceImpl
143 SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
144 SurfaceOpenGL(const std::string& file, int use_alpha);
145 SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
146 virtual ~SurfaceOpenGL();
148 int draw(float x, float y, Uint8 alpha, bool update);
149 int draw_bg(Uint8 alpha, bool update);
150 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
151 int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
154 void create_gl(SDL_Surface * surf, GLuint * tex);
158 #endif /*SUPERTUX_TEXTURE_H*/
160 /* Local Variables: */