src/video/gl/gl_renderer.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
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   // unrotated blit
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     // rotated blit
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   // FIXME: find a better way to restore the blend mode
00098   glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00099   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00100 }
00101 
00102 } // namespace
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 /* EOF */

Generated on Mon Jun 9 03:38:24 2014 for SuperTux by  doxygen 1.5.1