2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_VIDEO_GL_RENDERER_HPP
18 #define HEADER_SUPERTUX_VIDEO_GL_RENDERER_HPP
20 #include "math/size.hpp"
21 #include "video/drawing_request.hpp"
22 #include "video/renderer.hpp"
28 inline void intern_draw(float left, float top, float right, float bottom,
29 float uv_left, float uv_top,
30 float uv_right, float uv_bottom,
31 float angle, float alpha,
36 if(effect & HORIZONTAL_FLIP)
37 std::swap(uv_left, uv_right);
39 if(effect & VERTICAL_FLIP)
40 std::swap(uv_top, uv_bottom);
42 glBlendFunc(blend.sfactor, blend.dfactor);
43 glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
53 glVertexPointer(2, GL_FLOAT, 0, vertices);
61 glTexCoordPointer(2, GL_FLOAT, 0, uvs);
63 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
66 float center_x = (left + right) / 2;
67 float center_y = (top + bottom) / 2;
69 float sa = sinf(angle/180.0f*M_PI);
70 float ca = cosf(angle/180.0f*M_PI);
79 left*ca - top*sa + center_x, left*sa + top*ca + center_y,
80 right*ca - top*sa + center_x, right*sa + top*ca + center_y,
81 right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
82 left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
84 glVertexPointer(2, GL_FLOAT, 0, vertices);
92 glTexCoordPointer(2, GL_FLOAT, 0, uvs);
94 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
97 // FIXME: find a better way to restore the blend mode
98 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
99 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
106 class GLRenderer : public Renderer
111 bool fullscreen_active;
119 void draw_surface(const DrawingRequest& request);
120 void draw_surface_part(const DrawingRequest& request);
121 void draw_text(const DrawingRequest& request);
122 void draw_gradient(const DrawingRequest& request);
123 void draw_filled_rect(const DrawingRequest& request);
124 void draw_inverse_ellipse(const DrawingRequest& request);
125 void do_take_screenshot();
127 void resize(int w, int h);
129 void apply_video_mode(const Size& size, bool fullscreen);