{
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();
}
}
}
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);
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);
}
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;
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
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);
}
};
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;
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);
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);