00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_VIDEO_GL_RENDERER_HPP
00018 #define HEADER_SUPERTUX_VIDEO_GL_RENDERER_HPP
00019
00020 #include "math/size.hpp"
00021 #include "video/drawing_request.hpp"
00022 #include "video/renderer.hpp"
00023
00024 #include <math.h>
00025
00026 namespace {
00027
00028 inline void intern_draw(float left, float top, float right, float bottom,
00029 float uv_left, float uv_top,
00030 float uv_right, float uv_bottom,
00031 float angle, float alpha,
00032 const Color& color,
00033 const Blend& blend,
00034 DrawingEffect effect)
00035 {
00036 if(effect & HORIZONTAL_FLIP)
00037 std::swap(uv_left, uv_right);
00038
00039 if(effect & VERTICAL_FLIP)
00040 std::swap(uv_top, uv_bottom);
00041
00042 glBlendFunc(blend.sfactor, blend.dfactor);
00043 glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
00044
00045
00046 if (angle == 0.0f) {
00047 float vertices[] = {
00048 left, top,
00049 right, top,
00050 right, bottom,
00051 left, bottom,
00052 };
00053 glVertexPointer(2, GL_FLOAT, 0, vertices);
00054
00055 float uvs[] = {
00056 uv_left, uv_top,
00057 uv_right, uv_top,
00058 uv_right, uv_bottom,
00059 uv_left, uv_bottom,
00060 };
00061 glTexCoordPointer(2, GL_FLOAT, 0, uvs);
00062
00063 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
00064 } else {
00065
00066 float center_x = (left + right) / 2;
00067 float center_y = (top + bottom) / 2;
00068
00069 float sa = sinf(angle/180.0f*M_PI);
00070 float ca = cosf(angle/180.0f*M_PI);
00071
00072 left -= center_x;
00073 right -= center_x;
00074
00075 top -= center_y;
00076 bottom -= center_y;
00077
00078 float vertices[] = {
00079 left*ca - top*sa + center_x, left*sa + top*ca + center_y,
00080 right*ca - top*sa + center_x, right*sa + top*ca + center_y,
00081 right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
00082 left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
00083 };
00084 glVertexPointer(2, GL_FLOAT, 0, vertices);
00085
00086 float uvs[] = {
00087 uv_left, uv_top,
00088 uv_right, uv_top,
00089 uv_right, uv_bottom,
00090 uv_left, uv_bottom,
00091 };
00092 glTexCoordPointer(2, GL_FLOAT, 0, uvs);
00093
00094 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
00095 }
00096
00097
00098 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00099 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00100 }
00101
00102 }
00103
00104
00105
00106 class GLRenderer : public Renderer
00107 {
00108 private:
00109 Size desktop_size;
00110 Size screen_size;
00111 bool fullscreen_active;
00112
00113 public:
00114 GLRenderer();
00115 ~GLRenderer();
00116
00117 void draw_surface(const DrawingRequest& request);
00118 void draw_surface_part(const DrawingRequest& request);
00119 void draw_text(const DrawingRequest& request);
00120 void draw_gradient(const DrawingRequest& request);
00121 void draw_filled_rect(const DrawingRequest& request);
00122 void draw_inverse_ellipse(const DrawingRequest& request);
00123 void do_take_screenshot();
00124 void flip();
00125 void resize(int w, int h);
00126 void apply_config();
00127 void apply_video_mode(const Size& size, bool fullscreen);
00128 };
00129
00130 #endif
00131
00132