Rev 3 | Rev 7 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | tom | 1 | #include "SDL/SDL.h" |
4 | tom | 2 | #include "SDL/SDL_image.h" |
3 | tom | 3 | #include "SDL/SDL_opengl.h" |
4 | |||
4 | tom | 5 | #include <iostream> |
6 | |||
7 | using namespace std; |
||
8 | |||
9 | #include "texture.hpp" |
||
1 | tom | 10 | #include "sssnakesss.hpp" |
11 | |||
12 | SSSNAKESSS::SSSNAKESSS() |
||
13 | { |
||
2 | tom | 14 | running = false; |
1 | tom | 15 | } |
16 | |||
17 | SSSNAKESSS::~SSSNAKESSS() |
||
18 | { |
||
19 | |||
20 | } |
||
21 | |||
22 | bool SSSNAKESSS::init() |
||
23 | { |
||
24 | if (!initSDL()) |
||
25 | { |
||
26 | return false; |
||
27 | } |
||
28 | |||
29 | if (!initOpenGL()) |
||
30 | { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | initData(); |
||
35 | |||
36 | return true; |
||
37 | } |
||
38 | |||
39 | bool SSSNAKESSS::initSDL() |
||
40 | { |
||
3 | tom | 41 | if (SDL_Init(SDL_INIT_EVERYTHING) != 0) |
42 | { |
||
43 | return false; |
||
44 | } |
||
45 | |||
46 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
||
47 | |||
48 | screen = SDL_SetVideoMode(640, 480, 16, SDL_OPENGL); |
||
49 | if (!screen) |
||
50 | { |
||
51 | return false; |
||
52 | } |
||
53 | |||
1 | tom | 54 | return true; |
55 | } |
||
56 | |||
57 | bool SSSNAKESSS::initOpenGL() |
||
58 | { |
||
3 | tom | 59 | glEnable(GL_TEXTURE_2D); |
60 | |||
61 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
||
62 | |||
63 | glViewport(0, 0, 640, 480); |
||
64 | |||
65 | glClear(GL_COLOR_BUFFER_BIT); |
||
66 | |||
67 | glMatrixMode(GL_PROJECTION); |
||
68 | glLoadIdentity(); |
||
69 | |||
70 | glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f); |
||
71 | |||
72 | glMatrixMode(GL_MODELVIEW); |
||
73 | glLoadIdentity(); |
||
74 | |||
1 | tom | 75 | return true; |
76 | } |
||
77 | |||
78 | void SSSNAKESSS::initData() |
||
79 | { |
||
80 | } |
||
81 | |||
82 | void SSSNAKESSS::run() |
||
83 | { |
||
2 | tom | 84 | running = true; |
85 | |||
86 | while (running) |
||
87 | { |
||
88 | checkEvents(); |
||
89 | update(); |
||
90 | draw(); |
||
91 | } |
||
1 | tom | 92 | } |
93 | |||
2 | tom | 94 | void SSSNAKESSS::checkEvents() |
95 | { |
||
3 | tom | 96 | SDL_Event event; |
97 | |||
98 | while (SDL_PollEvent(&event)) |
||
99 | { |
||
100 | switch (event.type) |
||
101 | { |
||
102 | case SDL_QUIT: |
||
103 | running = false; |
||
104 | break; |
||
105 | } |
||
106 | } |
||
2 | tom | 107 | } |
108 | |||
109 | void SSSNAKESSS::update() |
||
110 | { |
||
111 | } |
||
112 | |||
113 | void SSSNAKESSS::draw() |
||
114 | { |
||
115 | } |
||
116 | |||
1 | tom | 117 | void SSSNAKESSS::end() |
118 | { |
||
119 | } |