1 /*============================================================================= 2 Blobby Volley 2 3 Copyright (C) 2006 Jonathan Sieber (jonathan_sieber@yahoo.de) 4 Copyright (C) 2006 Daniel Knobe (daniel-knobe@web.de) 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 =============================================================================*/ 20 21 #pragma once 22 23 #if HAVE_LIBGL 24 25 #include <SDL2/SDL.h> 26 27 #if __MACOSX__ 28 #include <OpenGL/gl.h> 29 #include <OpenGL/glext.h> 30 #else 31 #include <GL/gl.h> 32 #include <GL/glext.h> 33 #endif 34 35 #include <vector> 36 #include <list> 37 #include <set> 38 39 #include "RenderManager.h" 40 41 /*! \class RenderManagerGL2D 42 \brief RenderManager on top of OpenGL 43 \details This render manager uses OpenGL for drawing, SDL is only used for loading 44 the images. 45 */ 46 class RenderManagerGL2D : public RenderManager 47 { 48 public: 49 RenderManagerGL2D(); 50 51 virtual void init(int xResolution, int yResolution, bool fullscreen); 52 virtual void deinit(); 53 virtual void draw(); 54 virtual void refresh(); 55 56 virtual bool setBackground(const std::string& filename); 57 virtual void setBlobColor(int player, Color color); 58 virtual void showShadow(bool shadow); 59 60 virtual void setBall(const Vector2& position, float rotation); 61 virtual void setBlob(int player, const Vector2& position, 62 float animationState); 63 64 virtual void drawText(const std::string& text, Vector2 position, unsigned int flags = TF_NORMAL); 65 virtual void drawImage(const std::string& filename, Vector2 position, Vector2 size); 66 virtual void drawOverlay(float opacity, Vector2 pos1, Vector2 pos2, Color col); 67 virtual void drawBlob(const Vector2& pos, const Color& col); 68 virtual void startDrawParticles(); 69 virtual void drawParticle(const Vector2& pos, int player); 70 virtual void endDrawParticles(); 71 72 private: 73 // Make sure this object is created before any opengl call 74 SDL_GLContext mGlContext; 75 76 struct Texture 77 { 78 float indices[8]; 79 float w, h ; 80 GLuint texture; 81 82 Texture( GLuint tex, int x, int y, int w, int h, int tw, int th ); 83 }; 84 85 GLuint mBackground; 86 GLuint mBallShadow; 87 88 std::vector<GLuint> mBall; 89 std::vector<GLuint> mBlob; 90 std::vector<GLuint> mBlobSpecular; 91 std::vector<GLuint> mBlobShadow; 92 std::vector<Texture> mFont; 93 std::vector<Texture> mHighlightFont; 94 GLuint mParticle; 95 96 std::list<Vector2> mLastBallStates; 97 98 Vector2 mBallPosition; 99 float mBallRotation; 100 Vector2 mLeftBlobPosition; 101 float mLeftBlobAnimationState; 102 Vector2 mRightBlobPosition; 103 float mRightBlobAnimationState; 104 105 bool mShowShadow; 106 107 Color mLeftBlobColor; 108 Color mRightBlobColor; 109 110 void drawQuad(float x, float y, float width, float height); 111 void drawQuad(float x, float y, const Texture& tex); 112 GLuint loadTexture(SDL_Surface* surface, bool specular); 113 int getNextPOT(int npot); 114 115 void glEnable(unsigned int flag); 116 void glDisable(unsigned int flag); 117 void glBindTexture(GLuint texture); 118 119 GLuint mCurrentTexture; 120 std::set<unsigned int> mCurrentFlags; 121 }; 122 123 124 #endif 125