Commit | Line | Data |
---|---|---|
ad9f1fb6 PG |
1 | #include "graphics.h" |
2 | ||
3 | #include <GL/gl.h> | |
4 | #include <GL/glu.h> | |
5 | #include <SDL/SDL.h> | |
6 | #include <cmath> | |
7 | ||
8 | #include <iostream> | |
9 | using std::cerr; | |
10 | using std::cout; | |
11 | using std::endl; | |
12 | ||
13 | ||
14 | static const float PI = 3.1415926535897; | |
15 | ||
16 | /// ***** Private Method Headers ***** | |
17 | void sdlInit(); | |
18 | void glInit(); | |
19 | ||
20 | /// ***** Public Methods ***** | |
21 | ||
22 | void graphicsInit() | |
23 | { | |
24 | sdlInit(); | |
25 | glInit(); | |
26 | } | |
27 | ||
28 | void graphicsCleanUp() | |
29 | { | |
30 | ||
31 | } | |
32 | ||
33 | void glDrawCircle() | |
34 | { | |
35 | int num = 32; | |
36 | ||
37 | glBegin(GL_POLYGON); | |
38 | for(int n = 0; n < num; n++) | |
39 | { | |
40 | float angle = 2 * PI * n / num; | |
41 | float x = cos(angle); | |
42 | float y = sin(angle); | |
43 | ||
44 | glVertex3f(x, y, -1); | |
45 | } | |
46 | glEnd(); | |
47 | } | |
48 | ||
49 | /// ***** Private Methods ***** | |
50 | void sdlInit() | |
51 | { | |
52 | if(SDL_Init(SDL_INIT_VIDEO) < 0) | |
53 | { | |
54 | cerr << "SDL_Init failed: " << SDL_GetError() << endl; | |
55 | exit(1); | |
56 | } | |
57 | ||
58 | // In order to use SDL_OPENGLBLIT we have to | |
59 | // set GL attributes first | |
60 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); | |
61 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
62 | ||
63 | if(SDL_SetVideoMode(800, 600, 16, SDL_OPENGL) < 0) | |
64 | { | |
65 | cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << endl; | |
66 | exit(1); | |
67 | } | |
68 | } | |
69 | ||
70 | void glInit() | |
71 | { | |
72 | glClearColor(0.0, 0.0, 0.0, 0.0); | |
73 | ||
74 | glMatrixMode(GL_PROJECTION); | |
75 | glLoadIdentity(); | |
76 | ||
77 | glOrtho(-20.0, 20.0, -15.0, 15.0, -0.01, 1.01); | |
78 | ||
79 | glMatrixMode(GL_MODELVIEW); | |
80 | glLoadIdentity(); | |
81 | ||
82 | glEnable(GL_DEPTH_TEST); | |
83 | } |