2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
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/>.
34 /// ***** Private Method Headers *****
36 void glDrawCircle(int);
37 void glDrawPolygon( const std::vector<Vector2>& points );
41 /// ***** Initializers/Cleaners *****
49 void graphics::clean()
54 /// ***** Public Methods *****
56 void graphics::drawCircle(float radius, const Vector2& pos, const float* color)
58 glMatrixMode(GL_MODELVIEW);
60 glTranslatef(pos.x, pos.y, -1);
61 glScalef(radius, radius, radius);
69 void graphics::drawPolygon
71 const std::vector<Vector2>& points,
75 glMatrixMode(GL_MODELVIEW);
81 glDrawPolygon(points);
84 /// ***** Private Methods *****
86 void glDrawCircle(int pieces)
89 for(int n = 0; n < pieces; n++)
91 float angle = 2 * PI * n / pieces;
92 float ix = cos(angle);
93 float iy = sin(angle);
95 glVertex3f(ix, iy, 0);
100 void glDrawPolygon( const std::vector<Vector2>& points )
103 for(unsigned int n = 0; n < points.size(); n++)
105 const Vector2& vec = points.at(n);
107 glVertex3f(vec.x, vec.y, 0);
114 if(SDL_Init(SDL_INIT_VIDEO) < 0)
116 cerr << "SDL_Init failed: " << SDL_GetError() << endl;
120 // In order to use SDL_OPENGLBLIT we have to
121 // set GL attributes first
122 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
123 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
125 if(SDL_SetVideoMode(800, 600, 16, SDL_OPENGL) < 0)
127 cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << endl;
134 glClearColor(0.0, 0.0, 0.0, 0.0);
136 glMatrixMode(GL_PROJECTION);
139 glOrtho(0, 800.0, 600.0, 0.0, -0.01, 1.01);
141 glMatrixMode(GL_MODELVIEW);
144 glEnable(GL_DEPTH_TEST);
149 glEnable(GL_POLYGON_SMOOTH_HINT);
151 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
153 glHint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);