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/>.
29 /// ***** Private Method Headers *****
31 void glDrawCircle(int);
35 /// ***** Initializers/Cleaners *****
43 void graphics::clean()
48 /// ***** Public Methods *****
50 void graphics::drawCircle(float radius, const Vector2& pos, const float* color)
52 glMatrixMode(GL_MODELVIEW);
54 glTranslatef(pos.x, pos.y, -1);
55 glScalef(radius, radius, radius);
63 /// ***** Private Methods *****
65 void glDrawCircle(int pieces)
68 for(int n = 0; n < pieces; n++)
70 float angle = 2 * PI * n / pieces;
71 float ix = cos(angle);
72 float iy = sin(angle);
74 glVertex3f(ix, iy, 0);
81 if(SDL_Init(SDL_INIT_VIDEO) < 0)
83 cerr << "SDL_Init failed: " << SDL_GetError() << endl;
87 // In order to use SDL_OPENGLBLIT we have to
88 // set GL attributes first
89 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
90 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
92 if(SDL_SetVideoMode(800, 600, 16, SDL_OPENGL) < 0)
94 cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << endl;
101 glClearColor(0.0, 0.0, 0.0, 0.0);
103 glMatrixMode(GL_PROJECTION);
106 glOrtho(0, 800.0, 600.0, 0.0, -0.01, 1.01);
108 glMatrixMode(GL_MODELVIEW);
111 glEnable(GL_DEPTH_TEST);
116 glEnable(GL_POLYGON_SMOOTH_HINT);
118 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
120 glHint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);