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"
29 inline void intern_draw(float left, float top, float right, float bottom,
30 float uv_left, float uv_top,
31 float uv_right, float uv_bottom,
32 float angle, float alpha,
37 if(effect & HORIZONTAL_FLIP)
38 std::swap(uv_left, uv_right);
40 if(effect & VERTICAL_FLIP)
41 std::swap(uv_top, uv_bottom);
43 glBlendFunc(blend.sfactor, blend.dfactor);
44 glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
54 glVertexPointer(2, GL_FLOAT, 0, vertices);
62 glTexCoordPointer(2, GL_FLOAT, 0, uvs);
64 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
67 float center_x = (left + right) / 2;
68 float center_y = (top + bottom) / 2;
70 float sa = sinf(angle/180.0f*M_PI);
71 float ca = cosf(angle/180.0f*M_PI);
80 left*ca - top*sa + center_x, left*sa + top*ca + center_y,
81 right*ca - top*sa + center_x, right*sa + top*ca + center_y,
82 right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
83 left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
85 glVertexPointer(2, GL_FLOAT, 0, vertices);
93 glTexCoordPointer(2, GL_FLOAT, 0, uvs);
95 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
98 // FIXME: find a better way to restore the blend mode
99 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
100 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
107 class GLRenderer : public Renderer
111 SDL_GLContext glcontext;
115 bool fullscreen_active;
123 void draw_surface(const DrawingRequest& request);
124 void draw_surface_part(const DrawingRequest& request);
125 void draw_gradient(const DrawingRequest& request);
126 void draw_filled_rect(const DrawingRequest& request);
127 void draw_inverse_ellipse(const DrawingRequest& request);
128 void do_take_screenshot();
130 void resize(int w, int h);
132 void apply_video_mode(const Size& size, bool fullscreen);
133 Vector to_logical(int physical_x, int physical_y);
134 void set_gamma(float gamma);
135 SDL_Window* get_window() const { return window; }