X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvideo%2Fsurface.cpp;h=ff89f8c6f0a9d45b654c76cda2cce5ee96c90555;hb=d84d73b701cc7fa2bd74f3490b9be1bf8b6f705a;hp=7414564bc4c0def0e8d8ce9b6095b4a5a5ef0e2e;hpb=9b58f72e1c6900540c0ee00a800ed57d2c1f4974;p=supertux.git diff --git a/src/video/surface.cpp b/src/video/surface.cpp index 7414564bc..ff89f8c6f 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -32,6 +32,8 @@ #include "gameconfig.hpp" #include "physfs/physfs_sdl.hpp" #include "video/surface.hpp" +#include "video/drawing_context.hpp" +#include "video/color.hpp" #include "image_texture.hpp" #include "texture_manager.hpp" @@ -130,6 +132,72 @@ static inline void intern_draw(float left, float top, float right, float bottom, glEnd(); } +static inline void intern_draw2(float left, float top, float right, float bottom, + float uv_left, float uv_top, + float uv_right, float uv_bottom, + float angle, + const Color& color, + const Blend& blend, + DrawingEffect effect) +{ + if(effect & HORIZONTAL_FLIP) + std::swap(uv_left, uv_right); + if(effect & VERTICAL_FLIP) { + std::swap(uv_top, uv_bottom); + } + + float center_x = (left + right) / 2; + float center_y = (top + bottom) / 2; + + float sa = sinf(angle/180.0f*M_PI); + float ca = cosf(angle/180.0f*M_PI); + + left -= center_x; + right -= center_x; + + top -= center_y; + bottom -= center_y; + + glBlendFunc(blend.sfactor, blend.dfactor); + glColor4f(color.red, color.green, color.blue, color.alpha); + glBegin(GL_QUADS); + glTexCoord2f(uv_left, uv_top); + glVertex2f(left*ca - top*sa + center_x, + left*sa + top*ca + center_y); + + glTexCoord2f(uv_right, uv_top); + glVertex2f(right*ca - top*sa + center_x, + right*sa + top*ca + center_y); + + glTexCoord2f(uv_right, uv_bottom); + glVertex2f(right*ca - bottom*sa + center_x, + right*sa + bottom*ca + center_y); + + glTexCoord2f(uv_left, uv_bottom); + glVertex2f(left*ca - bottom*sa + center_x, + left*sa + bottom*ca + center_y); + glEnd(); + + // FIXME: find a better way to restore the blend mode + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + +void +Surface::draw(float x, float y, float alpha, float angle, const Color& color, const Blend& blend, DrawingEffect effect) const +{ + glColor4f(1.0f, 1.0f, 1.0f, alpha); + glBindTexture(GL_TEXTURE_2D, texture->get_handle()); + + intern_draw2(x, y, + x + width, y + height, + uv_left, uv_top, uv_right, uv_bottom, + angle, + color, + blend, + effect); +} + void Surface::draw(float x, float y, float alpha, DrawingEffect effect) const {