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>
37 /** This class holds all the data necessary to construct a surface */
41 enum ConstructorType { LOAD, LOAD_PART, SURFACE };
51 SurfaceData(SDL_Surface* surf, int use_alpha_);
52 SurfaceData(const std::string& file_, int use_alpha_);
53 SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_);
56 SurfaceSDL* create_SurfaceSDL();
57 SurfaceOpenGL* create_SurfaceOpenGL();
58 SurfaceImpl* create();
61 /** Container class that holds a surface, necessary so that we can
62 switch Surface implementations (OpenGL, SDL) on the fly */
71 typedef std::list<Surface*> Surfaces;
72 static Surfaces surfaces;
74 static void reload_all();
76 Surface(SDL_Surface* surf, int use_alpha);
77 Surface(const std::string& file, int use_alpha);
78 Surface(const std::string& file, int x, int y, int w, int h, int use_alpha);
81 /** Reload the surface, which is necesarry in case of a mode swich */
84 void draw(float x, float y, Uint8 alpha = 255, bool update = false);
85 void draw_bg(Uint8 alpha = 255, bool update = false);
86 void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
89 /** Surface implementation, all implementation have to inherit from
94 SDL_Surface* sdl_surface;
99 /** Return 0 on success, -2 if surface needs to be reloaded */
100 virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
101 virtual int draw_bg(Uint8 alpha, bool update) = 0;
102 virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
105 class SurfaceSDL : public SurfaceImpl
110 SurfaceSDL(SDL_Surface* surf, int use_alpha);
111 SurfaceSDL(const std::string& file, int use_alpha);
112 SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
113 virtual ~SurfaceSDL();
115 int draw(float x, float y, Uint8 alpha, bool update);
116 int draw_bg(Uint8 alpha, bool update);
117 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
120 class SurfaceOpenGL : public SurfaceImpl
126 SurfaceOpenGL(SDL_Surface* surf, int use_alpha);
127 SurfaceOpenGL(const std::string& file, int use_alpha);
128 SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
129 virtual ~SurfaceOpenGL();
131 int draw(float x, float y, Uint8 alpha, bool update);
132 int draw_bg(Uint8 alpha, bool update);
133 int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
136 void create_gl(SDL_Surface * surf, GLuint * tex);
139 #endif /*SUPERTUX_TEXTURE_H*/
141 /* Local Variables: */