massive cleaning of file section headers
[physics.git] / src / graphics / graphics.cpp
CommitLineData
ad9f1fb6 1#include "graphics.h"
617dcc71 2#include "../debug.h"
ad9f1fb6
PG
3
4#include <GL/gl.h>
5#include <GL/glu.h>
6#include <SDL/SDL.h>
7#include <cmath>
8
617dcc71 9#include "../mathw.h"
ad9f1fb6
PG
10
11/// ***** Private Method Headers *****
617dcc71 12
f7b3b2eb 13void drawCircle(int);
ad9f1fb6
PG
14void sdlInit();
15void glInit();
16
617dcc71 17/// ***** Initializers/Cleaners *****
ad9f1fb6
PG
18
19void graphicsInit()
20{
21 sdlInit();
22 glInit();
23}
24
617dcc71 25void graphicsClean()
ad9f1fb6
PG
26{
27
28}
29
617dcc71
PG
30/// ***** Public Methods *****
31
89ca62b2 32void glDrawCircle(float radius, const Vector2& vec, const float* color)
ad9f1fb6 33{
f7b3b2eb
PG
34 glMatrixMode(GL_MODELVIEW);
35 glLoadIdentity();
89ca62b2 36 glTranslatef(vec.x, vec.y, -1);
f7b3b2eb
PG
37 glScalef(radius, radius, radius);
38
39 if(color != NULL)
40 glColor3fv(color);
41
42 drawCircle(32);
43}
44
45/// ***** Private Methods *****
ad9f1fb6 46
f7b3b2eb
PG
47void drawCircle(int pieces)
48{
ad9f1fb6 49 glBegin(GL_POLYGON);
f7b3b2eb 50 for(int n = 0; n < pieces; n++)
ad9f1fb6 51 {
f7b3b2eb
PG
52 float angle = 2 * PI * n / pieces;
53 float ix = cos(angle);
54 float iy = sin(angle);
ad9f1fb6 55
f7b3b2eb 56 glVertex3f(ix, iy, 0);
ad9f1fb6
PG
57 }
58 glEnd();
59}
60
ad9f1fb6
PG
61void sdlInit()
62{
63 if(SDL_Init(SDL_INIT_VIDEO) < 0)
64 {
65 cerr << "SDL_Init failed: " << SDL_GetError() << endl;
66 exit(1);
67 }
68
69 // In order to use SDL_OPENGLBLIT we have to
70 // set GL attributes first
71 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
72 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
73
74 if(SDL_SetVideoMode(800, 600, 16, SDL_OPENGL) < 0)
75 {
76 cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << endl;
77 exit(1);
78 }
79}
80
81void glInit()
82{
83 glClearColor(0.0, 0.0, 0.0, 0.0);
84
85 glMatrixMode(GL_PROJECTION);
86 glLoadIdentity();
87
f7b3b2eb 88 glOrtho(0, 800.0, 600.0, 0.0, -0.01, 1.01);
ad9f1fb6
PG
89
90 glMatrixMode(GL_MODELVIEW);
91 glLoadIdentity();
92
93 glEnable(GL_DEPTH_TEST);
94}