1 |
root |
1.1 |
#include <stdlib.h> |
2 |
|
|
#include <stdio.h> |
3 |
|
|
#include <string.h> |
4 |
|
|
#include <math.h> |
5 |
root |
1.94 |
#include <list> |
6 |
root |
1.1 |
|
7 |
root |
1.62 |
#include "opengl.h" |
8 |
|
|
|
9 |
root |
1.1 |
#include "SDL.h" |
10 |
|
|
#include "SDL_opengl.h" |
11 |
|
|
|
12 |
|
|
static SDL_Surface *global_image = NULL; |
13 |
|
|
static GLuint global_texture = 0; |
14 |
|
|
|
15 |
root |
1.29 |
#include "util.h" |
16 |
root |
1.2 |
#include "entity.h" |
17 |
root |
1.29 |
#include "txtprt_import.h" |
18 |
|
|
|
19 |
root |
1.84 |
bool doom3parse (const char *f); |
20 |
|
|
|
21 |
root |
1.70 |
#include "shader.h" |
22 |
|
|
|
23 |
root |
1.94 |
#include "physics.h" |
24 |
|
|
|
25 |
root |
1.1 |
/**********************************************************************/ |
26 |
|
|
|
27 |
root |
1.6 |
view camera; |
28 |
root |
1.18 |
vec3 camera_velocity; |
29 |
root |
1.51 |
float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
30 |
root |
1.50 |
float camera_velocity_factor = 80; |
31 |
root |
1.6 |
|
32 |
root |
1.1 |
void |
33 |
|
|
HotKey_ToggleFullScreen (void) |
34 |
|
|
{ |
35 |
|
|
SDL_Surface *screen; |
36 |
|
|
|
37 |
|
|
screen = SDL_GetVideoSurface (); |
38 |
root |
1.73 |
|
39 |
root |
1.1 |
if (SDL_WM_ToggleFullScreen (screen)) |
40 |
root |
1.5 |
printf ("Toggled fullscreen mode - now %s\n", |
41 |
|
|
(screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
42 |
root |
1.1 |
else |
43 |
root |
1.5 |
printf ("Unable to toggle fullscreen mode\n"); |
44 |
root |
1.1 |
} |
45 |
|
|
|
46 |
|
|
void |
47 |
|
|
HotKey_ToggleGrab (void) |
48 |
|
|
{ |
49 |
|
|
SDL_GrabMode mode; |
50 |
|
|
|
51 |
|
|
printf ("Ctrl-G: toggling input grab!\n"); |
52 |
|
|
mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
53 |
root |
1.73 |
|
54 |
root |
1.1 |
if (mode == SDL_GRAB_ON) |
55 |
root |
1.5 |
printf ("Grab was on\n"); |
56 |
root |
1.1 |
else |
57 |
root |
1.5 |
printf ("Grab was off\n"); |
58 |
root |
1.1 |
|
59 |
|
|
mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
60 |
root |
1.73 |
|
61 |
root |
1.1 |
if (mode == SDL_GRAB_ON) |
62 |
root |
1.5 |
printf ("Grab is now on\n"); |
63 |
root |
1.1 |
else |
64 |
root |
1.5 |
printf ("Grab is now off\n"); |
65 |
root |
1.1 |
} |
66 |
|
|
|
67 |
|
|
void |
68 |
|
|
HotKey_Iconify (void) |
69 |
|
|
{ |
70 |
|
|
printf ("Ctrl-Z: iconifying window!\n"); |
71 |
|
|
SDL_WM_IconifyWindow (); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
int |
75 |
|
|
HandleEvent (SDL_Event * event) |
76 |
|
|
{ |
77 |
|
|
int done; |
78 |
|
|
|
79 |
|
|
done = 0; |
80 |
root |
1.73 |
|
81 |
root |
1.1 |
switch (event->type) |
82 |
|
|
{ |
83 |
|
|
case SDL_ACTIVEEVENT: |
84 |
|
|
/* See what happened */ |
85 |
|
|
printf ("app %s ", event->active.gain ? "gained" : "lost"); |
86 |
|
|
if (event->active.state & SDL_APPACTIVE) |
87 |
root |
1.62 |
printf ("active "); |
88 |
root |
1.1 |
else if (event->active.state & SDL_APPMOUSEFOCUS) |
89 |
root |
1.62 |
printf ("mouse "); |
90 |
root |
1.1 |
else if (event->active.state & SDL_APPINPUTFOCUS) |
91 |
root |
1.62 |
printf ("input "); |
92 |
root |
1.1 |
|
93 |
|
|
printf ("focus\n"); |
94 |
|
|
break; |
95 |
|
|
|
96 |
|
|
case SDL_KEYDOWN: |
97 |
root |
1.51 |
if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
98 |
|
|
if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
99 |
|
|
if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle++; |
100 |
|
|
if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle--; |
101 |
|
|
if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2++; |
102 |
|
|
if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2--; |
103 |
|
|
if (event->key.keysym.sym == SDLK_e) camera_velocity.y--; |
104 |
|
|
if (event->key.keysym.sym == SDLK_q) camera_velocity.y++; |
105 |
|
|
if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
106 |
|
|
if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; |
107 |
root |
1.6 |
|
108 |
root |
1.1 |
if (event->key.keysym.sym == SDLK_ESCAPE) |
109 |
root |
1.6 |
done = 1; |
110 |
root |
1.1 |
|
111 |
|
|
if ((event->key.keysym.sym == SDLK_g) && |
112 |
|
|
(event->key.keysym.mod & KMOD_CTRL)) |
113 |
root |
1.6 |
HotKey_ToggleGrab (); |
114 |
root |
1.1 |
|
115 |
|
|
if ((event->key.keysym.sym == SDLK_z) && |
116 |
|
|
(event->key.keysym.mod & KMOD_CTRL)) |
117 |
root |
1.6 |
HotKey_Iconify (); |
118 |
root |
1.1 |
|
119 |
|
|
if ((event->key.keysym.sym == SDLK_RETURN) && |
120 |
|
|
(event->key.keysym.mod & KMOD_ALT)) |
121 |
root |
1.6 |
HotKey_ToggleFullScreen (); |
122 |
root |
1.1 |
|
123 |
|
|
break; |
124 |
|
|
|
125 |
root |
1.18 |
case SDL_KEYUP: |
126 |
root |
1.19 |
if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
127 |
|
|
if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
128 |
root |
1.50 |
if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle++; |
129 |
|
|
if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle--; |
130 |
root |
1.51 |
if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2--; |
131 |
|
|
if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2++; |
132 |
root |
1.50 |
if (event->key.keysym.sym == SDLK_e) camera_velocity.y++; |
133 |
|
|
if (event->key.keysym.sym == SDLK_q) camera_velocity.y--; |
134 |
root |
1.18 |
break; |
135 |
|
|
|
136 |
root |
1.1 |
case SDL_QUIT: |
137 |
|
|
done = 1; |
138 |
|
|
break; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
return (done); |
142 |
|
|
} |
143 |
|
|
|
144 |
root |
1.47 |
void draw_floor (int size, int dx, int dy, int dz) |
145 |
|
|
{ |
146 |
|
|
int x, z, ry; |
147 |
|
|
|
148 |
root |
1.60 |
for (x = 0; x < 10; x++) |
149 |
root |
1.47 |
{ |
150 |
root |
1.60 |
for (z = 0; z < 10; z++) |
151 |
root |
1.47 |
{ |
152 |
root |
1.62 |
vector<vertex_t2f_n3f_v3f> pts; |
153 |
|
|
pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, 0), vec3 (0, 1, 0), tex2 (0, 0))); |
154 |
|
|
pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
155 |
|
|
pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
156 |
|
|
pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
157 |
root |
1.47 |
|
158 |
|
|
geometry_quads *q = new geometry_quads; |
159 |
root |
1.78 |
//q->m = new simple_material; |
160 |
root |
1.47 |
q->set (pts); |
161 |
|
|
entity *e = new entity (q); |
162 |
|
|
e->move (vec3 (dx + x * size, dy, dz + z * size)); |
163 |
|
|
e->show (); |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
} |
167 |
|
|
|
168 |
root |
1.52 |
void draw_test_nurb () |
169 |
|
|
{ |
170 |
root |
1.49 |
geometry_nurbs *q = new geometry_nurbs; |
171 |
|
|
q->set (); |
172 |
|
|
entity *e = new entity (q); |
173 |
|
|
e->move (vec3 (10, 3, -4)); |
174 |
|
|
e->show (); |
175 |
|
|
} |
176 |
|
|
|
177 |
root |
1.66 |
void fisch (vec3 center, GLfloat radius, int depth) |
178 |
|
|
{ |
179 |
root |
1.80 |
entity *planet = new entity (new geometry_sphere (testmat, radius)); |
180 |
root |
1.66 |
planet->move (center); |
181 |
|
|
planet->show (); |
182 |
|
|
|
183 |
|
|
if (--depth) |
184 |
|
|
{ |
185 |
|
|
GLfloat r2 = radius * .1F; |
186 |
|
|
GLfloat r3 = radius + r2; |
187 |
|
|
|
188 |
|
|
fisch (center + vec3 (r3, 0, 0), r2, depth); |
189 |
|
|
fisch (center + vec3 (0, 0, r3), r2, depth); |
190 |
|
|
fisch (center + vec3 (-r3, 0, 0), r2, depth); |
191 |
|
|
} |
192 |
|
|
} |
193 |
|
|
|
194 |
root |
1.54 |
extern void draw_level (); |
195 |
root |
1.92 |
|
196 |
root |
1.94 |
std::list<entity_moveable *> moveables; |
197 |
|
|
|
198 |
|
|
void perfom_moves () |
199 |
|
|
{ |
200 |
|
|
for (std::list<entity_moveable *>::iterator i = moveables.begin (); i != moveables.end (); ++i) |
201 |
|
|
{ |
202 |
|
|
(*i)->perform_step (timer.diff); |
203 |
|
|
} |
204 |
|
|
} |
205 |
|
|
|
206 |
root |
1.1 |
int |
207 |
|
|
RunGLTest (int argc, char *argv[], |
208 |
|
|
int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
209 |
|
|
{ |
210 |
|
|
int i; |
211 |
|
|
int rgb_size[3]; |
212 |
|
|
int w = 640; |
213 |
|
|
int h = 480; |
214 |
|
|
int done = 0; |
215 |
|
|
int frames; |
216 |
root |
1.2 |
Uint32 video_flags; |
217 |
root |
1.1 |
int value; |
218 |
root |
1.45 |
GLenum gl_error; |
219 |
root |
1.1 |
|
220 |
|
|
if (SDL_Init (SDL_INIT_VIDEO) < 0) |
221 |
|
|
{ |
222 |
|
|
fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
223 |
|
|
exit (1); |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
/* See if we should detect the display depth */ |
227 |
|
|
if (bpp == 0) |
228 |
|
|
{ |
229 |
|
|
if (SDL_GetVideoInfo ()->vfmt->BitsPerPixel <= 8) |
230 |
root |
1.3 |
bpp = 8; |
231 |
root |
1.1 |
else |
232 |
root |
1.3 |
bpp = 16; /* More doesn't seem to work */ |
233 |
root |
1.1 |
} |
234 |
|
|
|
235 |
root |
1.2 |
video_flags = SDL_OPENGL; |
236 |
|
|
|
237 |
root |
1.1 |
for (i = 1; argv[i]; ++i) |
238 |
root |
1.3 |
if (strcmp (argv[1], "-fullscreen") == 0) |
239 |
|
|
video_flags |= SDL_FULLSCREEN; |
240 |
root |
1.1 |
|
241 |
|
|
if (noframe) |
242 |
root |
1.3 |
video_flags |= SDL_NOFRAME; |
243 |
root |
1.1 |
|
244 |
|
|
/* Initialize the display */ |
245 |
|
|
switch (bpp) |
246 |
|
|
{ |
247 |
|
|
case 8: |
248 |
|
|
rgb_size[0] = 3; |
249 |
|
|
rgb_size[1] = 3; |
250 |
|
|
rgb_size[2] = 2; |
251 |
|
|
break; |
252 |
root |
1.3 |
|
253 |
root |
1.1 |
case 15: |
254 |
|
|
case 16: |
255 |
|
|
rgb_size[0] = 5; |
256 |
|
|
rgb_size[1] = 5; |
257 |
|
|
rgb_size[2] = 5; |
258 |
|
|
break; |
259 |
root |
1.3 |
|
260 |
root |
1.1 |
default: |
261 |
|
|
rgb_size[0] = 8; |
262 |
|
|
rgb_size[1] = 8; |
263 |
|
|
rgb_size[2] = 8; |
264 |
|
|
break; |
265 |
|
|
} |
266 |
root |
1.18 |
|
267 |
root |
1.1 |
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
268 |
|
|
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
269 |
|
|
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
270 |
root |
1.69 |
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
271 |
root |
1.1 |
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
272 |
root |
1.3 |
|
273 |
root |
1.1 |
if (fsaa) |
274 |
|
|
{ |
275 |
|
|
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
276 |
|
|
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, fsaa); |
277 |
|
|
} |
278 |
root |
1.3 |
|
279 |
root |
1.1 |
if (SDL_SetVideoMode (w, h, bpp, video_flags) == NULL) |
280 |
|
|
{ |
281 |
|
|
fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
282 |
|
|
SDL_Quit (); |
283 |
|
|
exit (1); |
284 |
|
|
} |
285 |
|
|
|
286 |
root |
1.69 |
//printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
287 |
|
|
//printf ("\n"); |
288 |
|
|
//printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
289 |
|
|
//printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
290 |
|
|
//printf ("Version : %s\n", glGetString (GL_VERSION)); |
291 |
|
|
//printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
292 |
root |
1.1 |
printf ("\n"); |
293 |
|
|
|
294 |
|
|
SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
295 |
|
|
printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
296 |
|
|
SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
297 |
|
|
printf ("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value); |
298 |
|
|
SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value); |
299 |
|
|
printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value); |
300 |
|
|
SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); |
301 |
|
|
printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value); |
302 |
|
|
SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); |
303 |
|
|
printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); |
304 |
root |
1.3 |
|
305 |
root |
1.1 |
if (fsaa) |
306 |
|
|
{ |
307 |
|
|
SDL_GL_GetAttribute (SDL_GL_MULTISAMPLEBUFFERS, &value); |
308 |
|
|
printf ("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); |
309 |
|
|
SDL_GL_GetAttribute (SDL_GL_MULTISAMPLESAMPLES, &value); |
310 |
|
|
printf ("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, |
311 |
|
|
value); |
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
/* Set the window manager title bar */ |
315 |
root |
1.12 |
SDL_WM_SetCaption ("libgender rendering test", "gendertest"); |
316 |
root |
1.1 |
|
317 |
|
|
/* Set the gamma for the window */ |
318 |
|
|
if (gamma != 0.0) |
319 |
root |
1.3 |
SDL_SetGamma (gamma, gamma, gamma); |
320 |
root |
1.1 |
|
321 |
root |
1.79 |
testmat = new test_material; |
322 |
|
|
|
323 |
root |
1.94 |
entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat, 10)); |
324 |
root |
1.78 |
planet->move (vec3 (0, 0, -20)); |
325 |
|
|
planet->show (); |
326 |
root |
1.84 |
|
327 |
root |
1.94 |
planet->v = vec3 (10, 0, 0); |
328 |
|
|
moveables.push_back (planet); |
329 |
|
|
|
330 |
root |
1.89 |
doom3parse ("test.proc"); |
331 |
|
|
|
332 |
root |
1.56 |
for (int i = 0; i < 20; i++) |
333 |
root |
1.17 |
{ |
334 |
root |
1.40 |
// load a entity |
335 |
root |
1.17 |
txtprt_parser p; |
336 |
root |
1.47 |
geometry *g; |
337 |
root |
1.17 |
try |
338 |
root |
1.40 |
{ |
339 |
root |
1.47 |
g = p.read ("test.blasc"); |
340 |
root |
1.40 |
} |
341 |
|
|
catch (txtprt_i_exception & e) |
342 |
|
|
{ |
343 |
|
|
cout << "ERR: " << e.msg << endl; |
344 |
|
|
} |
345 |
|
|
|
346 |
root |
1.47 |
entity *e = new entity (g); |
347 |
|
|
e->move (vec3 (i*5, -3, -i*10)); |
348 |
|
|
e->show (); |
349 |
root |
1.17 |
} |
350 |
root |
1.47 |
|
351 |
root |
1.89 |
{ |
352 |
|
|
fisch (vec3 (0, 0, -2e9), 1e9, 8); |
353 |
|
|
//entity *planet = new entity (new geometry_sphere (1e9)); |
354 |
|
|
//planet->move (vec3 (0, 0, -1.5e9)); |
355 |
|
|
//planet->show (); |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
{ |
359 |
|
|
entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
360 |
|
|
planet->move (vec3 (0, 0, 1e17)); |
361 |
|
|
planet->show (); |
362 |
|
|
} |
363 |
root |
1.60 |
|
364 |
root |
1.75 |
//draw_floor (10, -500, -10, -1000); |
365 |
root |
1.54 |
draw_level (); |
366 |
root |
1.73 |
|
367 |
root |
1.83 |
#if 0 |
368 |
root |
1.73 |
{ |
369 |
root |
1.75 |
geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
370 |
|
|
entity *e = new entity (hf); |
371 |
|
|
e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
372 |
root |
1.73 |
e->show (); |
373 |
|
|
} |
374 |
root |
1.83 |
#endif |
375 |
root |
1.73 |
|
376 |
root |
1.60 |
//draw_test_nurb (); |
377 |
root |
1.47 |
|
378 |
root |
1.55 |
//camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
379 |
|
|
camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
380 |
root |
1.6 |
camera.p = point (0, 0, 10); |
381 |
|
|
camera.d = vec3 (0, 0, -1); |
382 |
|
|
camera.u = vec3 (0, 1, 0); |
383 |
|
|
camera.w = w; camera.h = h; |
384 |
root |
1.67 |
camera.fov = 40.; |
385 |
root |
1.1 |
|
386 |
root |
1.65 |
glDisable (GL_ALPHA_TEST); |
387 |
root |
1.29 |
|
388 |
root |
1.1 |
/* Loop until done. */ |
389 |
|
|
frames = 0; |
390 |
root |
1.16 |
|
391 |
root |
1.90 |
linear_light mylight, mylight2; |
392 |
|
|
|
393 |
root |
1.78 |
mylight.radius = 100000; |
394 |
root |
1.79 |
mylight.c = colour (1., 1, 1, 1.); |
395 |
root |
1.80 |
mylight.intensity = 1.F; |
396 |
root |
1.78 |
|
397 |
root |
1.90 |
mylight2.radius = 100000; |
398 |
|
|
mylight2.c = colour (1., 0, 0, 1.); |
399 |
|
|
mylight2.intensity = 1.F; |
400 |
|
|
|
401 |
root |
1.91 |
pass_data pass_light (&mylight); |
402 |
|
|
pass_data pass_light2 (&mylight2); |
403 |
root |
1.78 |
|
404 |
root |
1.1 |
while (!done) |
405 |
|
|
{ |
406 |
|
|
char *sdl_error; |
407 |
|
|
SDL_Event event; |
408 |
|
|
|
409 |
root |
1.88 |
camera_angle += 90 * camera_velocity_angle * timer.diff; |
410 |
|
|
camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
411 |
root |
1.51 |
|
412 |
|
|
vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
413 |
|
|
vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
414 |
|
|
|
415 |
|
|
camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
416 |
|
|
camera.u = cross (camera.d, right); |
417 |
|
|
|
418 |
root |
1.50 |
camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
419 |
|
|
camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
420 |
root |
1.18 |
|
421 |
root |
1.78 |
mylight.orig = camera.orig; |
422 |
|
|
mylight.p = camera.p; |
423 |
root |
1.1 |
|
424 |
root |
1.90 |
mylight2.orig = camera.orig; |
425 |
|
|
mylight2.p = camera.p + vec3 (sin (timer.now * 2) * 100, 1, cos (timer.now * 2) * 100); |
426 |
|
|
|
427 |
root |
1.79 |
//mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
428 |
|
|
|
429 |
root |
1.34 |
camera.begin (); |
430 |
root |
1.91 |
camera.render (pass_depth); |
431 |
|
|
camera.render (pass_postdepth); |
432 |
|
|
camera.render (pass_light); |
433 |
root |
1.90 |
//camera.render (view::LIGHTED, pass_light2); |
434 |
root |
1.34 |
camera.end (); |
435 |
root |
1.94 |
|
436 |
|
|
perfom_moves (); |
437 |
root |
1.1 |
|
438 |
|
|
SDL_GL_SwapBuffers (); |
439 |
root |
1.15 |
timer.frame (); |
440 |
root |
1.62 |
|
441 |
|
|
#if 0 |
442 |
root |
1.1 |
/* Check for error conditions. */ |
443 |
|
|
gl_error = glGetError (); |
444 |
|
|
|
445 |
root |
1.45 |
if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
446 |
root |
1.1 |
|
447 |
|
|
sdl_error = SDL_GetError (); |
448 |
|
|
|
449 |
|
|
if (sdl_error[0] != '\0') |
450 |
|
|
{ |
451 |
|
|
fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
452 |
|
|
SDL_ClearError (); |
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
/* Allow the user to see what's happening */ |
456 |
root |
1.51 |
//SDL_Delay (40); |
457 |
root |
1.62 |
#endif |
458 |
root |
1.1 |
|
459 |
|
|
/* Check if there's a pending event. */ |
460 |
|
|
while (SDL_PollEvent (&event)) |
461 |
root |
1.18 |
done = HandleEvent (&event); |
462 |
root |
1.20 |
|
463 |
root |
1.1 |
++frames; |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
if (global_image) |
467 |
|
|
{ |
468 |
|
|
SDL_FreeSurface (global_image); |
469 |
|
|
global_image = NULL; |
470 |
|
|
} |
471 |
root |
1.73 |
|
472 |
root |
1.1 |
if (global_texture) |
473 |
|
|
{ |
474 |
|
|
glDeleteTextures (1, &global_texture); |
475 |
|
|
global_texture = 0; |
476 |
|
|
} |
477 |
|
|
|
478 |
|
|
/* Destroy our GL context, etc. */ |
479 |
|
|
SDL_Quit (); |
480 |
|
|
return (0); |
481 |
|
|
} |
482 |
|
|
int |
483 |
|
|
main (int argc, char *argv[]) |
484 |
|
|
{ |
485 |
|
|
int i, logo; |
486 |
|
|
int numtests; |
487 |
|
|
int bpp = 0; |
488 |
|
|
int slowly; |
489 |
|
|
float gamma = 0.0; |
490 |
|
|
int noframe = 0; |
491 |
|
|
int fsaa = 0; |
492 |
root |
1.68 |
|
493 |
root |
1.1 |
logo = 0; |
494 |
|
|
slowly = 0; |
495 |
|
|
numtests = 1; |
496 |
|
|
for (i = 1; argv[i]; ++i) |
497 |
|
|
{ |
498 |
|
|
if (strcmp (argv[i], "-twice") == 0) |
499 |
|
|
{ |
500 |
|
|
++numtests; |
501 |
|
|
} |
502 |
|
|
if (strcmp (argv[i], "-slow") == 0) |
503 |
|
|
{ |
504 |
|
|
slowly = 1; |
505 |
|
|
} |
506 |
|
|
if (strcmp (argv[i], "-bpp") == 0) |
507 |
|
|
{ |
508 |
|
|
bpp = atoi (argv[++i]); |
509 |
|
|
} |
510 |
|
|
if (strcmp (argv[i], "-gamma") == 0) |
511 |
|
|
{ |
512 |
|
|
gamma = (float) atof (argv[++i]); |
513 |
|
|
} |
514 |
|
|
if (strcmp (argv[i], "-noframe") == 0) |
515 |
|
|
{ |
516 |
|
|
noframe = 1; |
517 |
|
|
} |
518 |
|
|
if (strcmp (argv[i], "-fsaa") == 0) |
519 |
|
|
{ |
520 |
|
|
++fsaa; |
521 |
|
|
} |
522 |
|
|
if (strncmp (argv[i], "-h", 2) == 0) |
523 |
|
|
{ |
524 |
|
|
printf |
525 |
|
|
("Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa]\n", |
526 |
|
|
argv[0]); |
527 |
|
|
exit (0); |
528 |
|
|
} |
529 |
|
|
} |
530 |
root |
1.17 |
|
531 |
root |
1.1 |
for (i = 0; i < numtests; ++i) |
532 |
root |
1.17 |
RunGLTest (argc, argv, logo, slowly, bpp, gamma, noframe, fsaa); |
533 |
|
|
|
534 |
root |
1.1 |
return 0; |
535 |
|
|
} |