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/>.
20 #include <bear/debug.h>
21 #include <bear/mathw.h>
35 /// ***** Private Method Headers *****
37 void glDrawCircle(int);
38 void glDrawPolygon( const std::vector<Vector2>& points );
42 /// ***** Initializers/Cleaners *****
50 void graphics::clean()
55 /// ***** Public Methods *****
57 void graphics::drawCircle(float radius, const Vector2& pos, const float* color)
59 glMatrixMode(GL_MODELVIEW);
61 glTranslatef(pos.m_fX, pos.m_fY, -1);
62 glScalef(radius, radius, radius);
70 void graphics::drawPolygon
72 const std::vector<Vector2>& points,
76 glMatrixMode(GL_MODELVIEW);
82 glDrawPolygon(points);
85 /// ***** Private Methods *****
87 void glDrawCircle(int pieces)
90 for(int n = 0; n < pieces; n++)
92 float angle = 2 * PI * n / pieces;
93 float ix = cos(angle);
94 float iy = sin(angle);
96 glVertex3f(ix, iy, 0);
101 void glDrawPolygon( const std::vector<Vector2>& points )
104 for(unsigned int n = 0; n < points.size(); n++)
106 const Vector2& vec = points.at(n);
108 glVertex3f(vec.m_fX, vec.m_fY, 0);
115 if(SDL_Init(SDL_INIT_VIDEO) < 0)
117 cerr << "SDL_Init failed: " << SDL_GetError() << endl;
121 // In order to use SDL_OPENGLBLIT we have to
122 // set GL attributes first
123 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
124 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
126 if(SDL_SetVideoMode(800, 600, 16, SDL_OPENGL) < 0)
128 cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << endl;
135 glClearColor(0.0, 0.0, 0.0, 0.0);
137 glMatrixMode(GL_PROJECTION);
140 glOrtho(0, 800.0, 600.0, 0.0, -0.01, 1.01);
142 glMatrixMode(GL_MODELVIEW);
145 glEnable(GL_DEPTH_TEST);
150 glEnable(GL_POLYGON_SMOOTH_HINT);
152 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
154 glHint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);