From: Ricardo Cruz Date: Fri, 28 May 2004 14:51:56 +0000 (+0000) Subject: Removed vertical flipping drawing hacks. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f8dcfa6e322b891d4ee1ea96825f86eb897493d6;p=supertux.git Removed vertical flipping drawing hacks. Anyway, can we remove the update argument from the drawing functions? It is not used anywhere and OpenGL doesn't support it. SVN-Revision: 1347 --- diff --git a/src/texture.cpp b/src/texture.cpp index 4efdf6899..ae09bb358 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -211,11 +211,7 @@ Surface::draw(float x, float y, Uint8 alpha, bool upside_down, bool update) { if (impl) { - if(upside_down) // FIXME: this should be done by the SDL and OpenGL draw() - for(float sy = 0; sy < h; sy++) - impl->draw_part(0, sy, x, y+(h-sy), w, 1, alpha, update); - - else if (impl->draw(x, y, alpha, update) == -2) + if (impl->draw(x, y, alpha, upside_down, update) == -2) reload(); } } @@ -539,7 +535,7 @@ SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex) } int -SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update) +SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool upside_down, bool update) { float pw = power_of_two(w); float ph = power_of_two(h); @@ -553,13 +549,34 @@ SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update) glBindTexture(GL_TEXTURE_2D, gl_texture); glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(x, y); - glTexCoord2f((float)w / pw, 0); - glVertex2f((float)w+x, y); - glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)w+x, (float)h+y); - glTexCoord2f(0, (float)h / ph); - glVertex2f(x, (float)h+y); + if(upside_down) + { + glTexCoord2f(0, 0); + glVertex2f(x, (float)h+y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)w+x, y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, y); + } + else + { + glTexCoord2f(0, 0); + glVertex2f(x, y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)w+x, y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, (float)h+y); + } glEnd(); glDisable(GL_TEXTURE_2D); @@ -691,7 +708,7 @@ SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, int } int -SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update) +SurfaceSDL::draw(float x, float y, Uint8 alpha, bool upside_down, bool update) { SDL_Rect dest; @@ -700,6 +717,14 @@ SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update) dest.w = w; dest.h = h; + if(upside_down) // FIXME: feel free to replace this hack + { + for(float sy = 0; sy < h; sy++) + if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, update) == -2) + return -2; + return 0; + } + if(alpha != 255) { /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha diff --git a/src/texture.h b/src/texture.h index da4c8dc06..0e68e7000 100644 --- a/src/texture.h +++ b/src/texture.h @@ -95,9 +95,9 @@ public: void resize(int w_, int h_); /// conveniance function - void draw(const Vector& pos, Uint8 alpha = 255, bool update = false) + void draw(const Vector& pos, Uint8 alpha = 255, bool upside_down = false, bool update = false) { - draw(pos.x, pos.y, alpha, update); + draw(pos.x, pos.y, alpha, upside_down, update); } }; @@ -117,7 +117,7 @@ public: virtual ~SurfaceImpl(); /** Return 0 on success, -2 if surface needs to be reloaded */ - virtual int draw(float x, float y, Uint8 alpha, bool update) = 0; + virtual int draw(float x, float y, Uint8 alpha, bool upside_down, bool update) = 0; virtual int draw_bg(Uint8 alpha, bool update) = 0; virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0; virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0; @@ -134,7 +134,7 @@ public: SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha); virtual ~SurfaceSDL(); - int draw(float x, float y, Uint8 alpha, bool update); + int draw(float x, float y, Uint8 alpha, bool upside_down, bool update); int draw_bg(Uint8 alpha, bool update); int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update); @@ -152,7 +152,7 @@ public: SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha); virtual ~SurfaceOpenGL(); - int draw(float x, float y, Uint8 alpha, bool update); + int draw(float x, float y, Uint8 alpha, bool upside_down, bool update); int draw_bg(Uint8 alpha, bool update); int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);