… | |
… | |
13 | |
13 | |
14 | #include "util.h" |
14 | #include "util.h" |
15 | #include "entity.h" |
15 | #include "entity.h" |
16 | #include "txtprt_import.h" |
16 | #include "txtprt_import.h" |
17 | |
17 | |
|
|
18 | bool doom3parse (const char *f); |
|
|
19 | |
|
|
20 | #include "shader.h" |
|
|
21 | |
18 | /**********************************************************************/ |
22 | /**********************************************************************/ |
19 | |
23 | |
20 | view camera; |
24 | view camera; |
21 | vec3 camera_velocity; |
25 | vec3 camera_velocity; |
22 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
26 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
… | |
… | |
26 | HotKey_ToggleFullScreen (void) |
30 | HotKey_ToggleFullScreen (void) |
27 | { |
31 | { |
28 | SDL_Surface *screen; |
32 | SDL_Surface *screen; |
29 | |
33 | |
30 | screen = SDL_GetVideoSurface (); |
34 | screen = SDL_GetVideoSurface (); |
|
|
35 | |
31 | if (SDL_WM_ToggleFullScreen (screen)) |
36 | if (SDL_WM_ToggleFullScreen (screen)) |
32 | printf ("Toggled fullscreen mode - now %s\n", |
37 | printf ("Toggled fullscreen mode - now %s\n", |
33 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
38 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
34 | else |
39 | else |
35 | printf ("Unable to toggle fullscreen mode\n"); |
40 | printf ("Unable to toggle fullscreen mode\n"); |
… | |
… | |
40 | { |
45 | { |
41 | SDL_GrabMode mode; |
46 | SDL_GrabMode mode; |
42 | |
47 | |
43 | printf ("Ctrl-G: toggling input grab!\n"); |
48 | printf ("Ctrl-G: toggling input grab!\n"); |
44 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
49 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
|
|
50 | |
45 | if (mode == SDL_GRAB_ON) |
51 | if (mode == SDL_GRAB_ON) |
46 | printf ("Grab was on\n"); |
52 | printf ("Grab was on\n"); |
47 | else |
53 | else |
48 | printf ("Grab was off\n"); |
54 | printf ("Grab was off\n"); |
49 | |
55 | |
50 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
56 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
|
|
57 | |
51 | if (mode == SDL_GRAB_ON) |
58 | if (mode == SDL_GRAB_ON) |
52 | printf ("Grab is now on\n"); |
59 | printf ("Grab is now on\n"); |
53 | else |
60 | else |
54 | printf ("Grab is now off\n"); |
61 | printf ("Grab is now off\n"); |
55 | } |
62 | } |
… | |
… | |
65 | HandleEvent (SDL_Event * event) |
72 | HandleEvent (SDL_Event * event) |
66 | { |
73 | { |
67 | int done; |
74 | int done; |
68 | |
75 | |
69 | done = 0; |
76 | done = 0; |
|
|
77 | |
70 | switch (event->type) |
78 | switch (event->type) |
71 | { |
79 | { |
72 | case SDL_ACTIVEEVENT: |
80 | case SDL_ACTIVEEVENT: |
73 | /* See what happened */ |
81 | /* See what happened */ |
74 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
82 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
… | |
… | |
143 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
151 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
144 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
152 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
145 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
153 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
146 | |
154 | |
147 | geometry_quads *q = new geometry_quads; |
155 | geometry_quads *q = new geometry_quads; |
148 | q->m = new simple_material; |
156 | //q->m = new simple_material; |
149 | q->set (pts); |
157 | q->set (pts); |
150 | entity *e = new entity (q); |
158 | entity *e = new entity (q); |
151 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
159 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
152 | e->show (); |
160 | e->show (); |
153 | } |
161 | } |
… | |
… | |
163 | e->show (); |
171 | e->show (); |
164 | } |
172 | } |
165 | |
173 | |
166 | void fisch (vec3 center, GLfloat radius, int depth) |
174 | void fisch (vec3 center, GLfloat radius, int depth) |
167 | { |
175 | { |
168 | entity *planet = new entity (new geometry_sphere (radius)); |
176 | entity *planet = new entity (new geometry_sphere (testmat, radius)); |
169 | planet->move (center); |
177 | planet->move (center); |
170 | planet->show (); |
178 | planet->show (); |
171 | |
179 | |
172 | if (--depth) |
180 | if (--depth) |
173 | { |
181 | { |
… | |
… | |
179 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
187 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
180 | } |
188 | } |
181 | } |
189 | } |
182 | |
190 | |
183 | extern void draw_level (); |
191 | extern void draw_level (); |
|
|
192 | |
|
|
193 | octant *optimize (octant *o)//D |
|
|
194 | { |
|
|
195 | if (!o) |
|
|
196 | return o; |
|
|
197 | |
|
|
198 | for (int i = 8; --i; ) |
|
|
199 | o->sub[i] = optimize (o->sub[i]); |
|
|
200 | |
|
|
201 | if (o->fill != 1 || o->size ()) |
|
|
202 | return o; |
|
|
203 | |
|
|
204 | printf ("skipped\n"); |
|
|
205 | |
|
|
206 | for (int i = 8; --i; ) |
|
|
207 | if (o->sub[i]) |
|
|
208 | return o->sub[i]; |
|
|
209 | |
|
|
210 | abort (); |
|
|
211 | } |
|
|
212 | |
184 | int |
213 | int |
185 | RunGLTest (int argc, char *argv[], |
214 | RunGLTest (int argc, char *argv[], |
186 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
215 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
187 | { |
216 | { |
188 | int i; |
217 | int i; |
… | |
… | |
243 | } |
272 | } |
244 | |
273 | |
245 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
274 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
246 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
275 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
247 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
276 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
248 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
277 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
249 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
278 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
250 | |
279 | |
251 | if (fsaa) |
280 | if (fsaa) |
252 | { |
281 | { |
253 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
282 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
… | |
… | |
259 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
288 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
260 | SDL_Quit (); |
289 | SDL_Quit (); |
261 | exit (1); |
290 | exit (1); |
262 | } |
291 | } |
263 | |
292 | |
264 | printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
293 | //printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
265 | printf ("\n"); |
294 | //printf ("\n"); |
266 | printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
295 | //printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
267 | printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
296 | //printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
268 | printf ("Version : %s\n", glGetString (GL_VERSION)); |
297 | //printf ("Version : %s\n", glGetString (GL_VERSION)); |
269 | printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
298 | //printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
270 | printf ("\n"); |
299 | printf ("\n"); |
271 | |
300 | |
272 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
301 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
273 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
302 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
274 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
303 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
… | |
… | |
294 | |
323 | |
295 | /* Set the gamma for the window */ |
324 | /* Set the gamma for the window */ |
296 | if (gamma != 0.0) |
325 | if (gamma != 0.0) |
297 | SDL_SetGamma (gamma, gamma, gamma); |
326 | SDL_SetGamma (gamma, gamma, gamma); |
298 | |
327 | |
|
|
328 | testmat = new test_material; |
|
|
329 | |
299 | entity *planet = new entity (new geometry_sphere (10)); |
330 | entity *planet = new entity (new geometry_sphere (testmat, 10)); |
300 | planet->move (vec3 (0, 0, -20)); |
331 | planet->move (vec3 (0, 0, -20)); |
301 | planet->show (); |
332 | planet->show (); |
302 | |
333 | |
303 | #if 1 |
334 | doom3parse ("test.proc"); |
|
|
335 | |
|
|
336 | for (int i = 8; --i; ) |
|
|
337 | world.sub[i] = optimize (world.sub[i]);//D |
|
|
338 | |
304 | for (int i = 0; i < 20; i++) |
339 | for (int i = 0; i < 20; i++) |
305 | { |
340 | { |
306 | // load a entity |
341 | // load a entity |
307 | txtprt_parser p; |
342 | txtprt_parser p; |
308 | geometry *g; |
343 | geometry *g; |
… | |
… | |
318 | entity *e = new entity (g); |
353 | entity *e = new entity (g); |
319 | e->move (vec3 (i*5, -3, -i*10)); |
354 | e->move (vec3 (i*5, -3, -i*10)); |
320 | e->show (); |
355 | e->show (); |
321 | } |
356 | } |
322 | |
357 | |
323 | { |
358 | { |
324 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
359 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
325 | //entity *planet = new entity (new geometry_sphere (1e9)); |
360 | //entity *planet = new entity (new geometry_sphere (1e9)); |
326 | //planet->move (vec3 (0, 0, -1.5e9)); |
361 | //planet->move (vec3 (0, 0, -1.5e9)); |
327 | //planet->show (); |
362 | //planet->show (); |
328 | } |
363 | } |
329 | |
364 | |
330 | { |
365 | { |
331 | entity *planet = new entity (new geometry_sphere (4e15)); |
366 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
332 | planet->move (vec3 (0, 0, 1e17)); |
367 | planet->move (vec3 (0, 0, 1e17)); |
333 | planet->show (); |
368 | planet->show (); |
334 | } |
369 | } |
335 | |
370 | |
336 | draw_floor (10, -500, -10, -1000); |
371 | //draw_floor (10, -500, -10, -1000); |
337 | draw_level (); |
372 | draw_level (); |
|
|
373 | |
|
|
374 | #if 0 |
|
|
375 | { |
|
|
376 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
|
|
377 | entity *e = new entity (hf); |
|
|
378 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
|
|
379 | e->show (); |
|
|
380 | } |
|
|
381 | #endif |
|
|
382 | |
338 | //draw_test_nurb (); |
383 | //draw_test_nurb (); |
339 | #endif |
|
|
340 | |
384 | |
341 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
385 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
342 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
386 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
343 | camera.p = point (0, 0, 10); |
387 | camera.p = point (0, 0, 10); |
344 | camera.d = vec3 (0, 0, -1); |
388 | camera.d = vec3 (0, 0, -1); |
345 | camera.u = vec3 (0, 1, 0); |
389 | camera.u = vec3 (0, 1, 0); |
346 | camera.w = w; camera.h = h; |
390 | camera.w = w; camera.h = h; |
347 | camera.fov = 40.; |
391 | camera.fov = 40.; |
348 | |
392 | |
349 | glEnable (GL_CULL_FACE); |
|
|
350 | glDisable (GL_ALPHA_TEST); |
393 | glDisable (GL_ALPHA_TEST); |
351 | glDisable (GL_BLEND); |
|
|
352 | |
|
|
353 | init_shaders (); |
|
|
354 | |
|
|
355 | osama_material osa_mat; |
|
|
356 | |
394 | |
357 | /* Loop until done. */ |
395 | /* Loop until done. */ |
358 | frames = 0; |
396 | frames = 0; |
359 | |
397 | |
|
|
398 | linear_light mylight, mylight2; |
|
|
399 | |
|
|
400 | mylight.radius = 100000; |
|
|
401 | mylight.c = colour (1., 1, 1, 1.); |
|
|
402 | mylight.intensity = 1.F; |
|
|
403 | |
|
|
404 | mylight2.radius = 100000; |
|
|
405 | mylight2.c = colour (1., 0, 0, 1.); |
|
|
406 | mylight2.intensity = 1.F; |
|
|
407 | |
|
|
408 | pass_data pass_light (&mylight); |
|
|
409 | pass_data pass_light2 (&mylight2); |
|
|
410 | |
360 | while (!done) |
411 | while (!done) |
361 | { |
412 | { |
362 | char *sdl_error; |
413 | char *sdl_error; |
363 | SDL_Event event; |
414 | SDL_Event event; |
364 | |
415 | |
365 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
416 | camera_angle += 90 * camera_velocity_angle * timer.diff; |
366 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
417 | camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
367 | |
418 | |
368 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
419 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
369 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
420 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
370 | |
421 | |
371 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
422 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
372 | camera.u = cross (camera.d, right); |
423 | camera.u = cross (camera.d, right); |
373 | |
424 | |
374 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
425 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
375 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
426 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
376 | |
427 | |
377 | osa_mat.begin (); |
428 | mylight.orig = camera.orig; |
|
|
429 | mylight.p = camera.p; |
378 | |
430 | |
|
|
431 | mylight2.orig = camera.orig; |
|
|
432 | mylight2.p = camera.p + vec3 (sin (timer.now * 2) * 100, 1, cos (timer.now * 2) * 100); |
|
|
433 | |
|
|
434 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
|
|
435 | |
379 | camera.begin (); |
436 | camera.begin (); |
380 | camera.render (view::DEPTH); |
437 | camera.render (pass_depth); |
381 | camera.render (view::POSTDEPTH); |
438 | camera.render (pass_postdepth); |
|
|
439 | camera.render (pass_light); |
382 | camera.render (view::LIGHTED); |
440 | //camera.render (view::LIGHTED, pass_light2); |
383 | camera.end (); |
441 | camera.end (); |
384 | |
442 | |
385 | SDL_GL_SwapBuffers (); |
443 | SDL_GL_SwapBuffers (); |
386 | timer.frame (); |
444 | timer.frame (); |
387 | |
|
|
388 | osa_mat.end (); |
|
|
389 | |
445 | |
390 | #if 0 |
446 | #if 0 |
391 | /* Check for error conditions. */ |
447 | /* Check for error conditions. */ |
392 | gl_error = glGetError (); |
448 | gl_error = glGetError (); |
393 | |
449 | |
… | |
… | |
407 | |
463 | |
408 | /* Check if there's a pending event. */ |
464 | /* Check if there's a pending event. */ |
409 | while (SDL_PollEvent (&event)) |
465 | while (SDL_PollEvent (&event)) |
410 | done = HandleEvent (&event); |
466 | done = HandleEvent (&event); |
411 | |
467 | |
412 | |
|
|
413 | ++frames; |
468 | ++frames; |
414 | } |
469 | } |
415 | |
470 | |
416 | if (global_image) |
471 | if (global_image) |
417 | { |
472 | { |
418 | SDL_FreeSurface (global_image); |
473 | SDL_FreeSurface (global_image); |
419 | global_image = NULL; |
474 | global_image = NULL; |
420 | } |
475 | } |
|
|
476 | |
421 | if (global_texture) |
477 | if (global_texture) |
422 | { |
478 | { |
423 | glDeleteTextures (1, &global_texture); |
479 | glDeleteTextures (1, &global_texture); |
424 | global_texture = 0; |
480 | global_texture = 0; |
425 | } |
481 | } |
… | |
… | |
437 | int slowly; |
493 | int slowly; |
438 | float gamma = 0.0; |
494 | float gamma = 0.0; |
439 | int noframe = 0; |
495 | int noframe = 0; |
440 | int fsaa = 0; |
496 | int fsaa = 0; |
441 | |
497 | |
442 | shader::debdebdebdebug ();//D |
|
|
443 | |
|
|
444 | logo = 0; |
498 | logo = 0; |
445 | slowly = 0; |
499 | slowly = 0; |
446 | numtests = 1; |
500 | numtests = 1; |
447 | for (i = 1; argv[i]; ++i) |
501 | for (i = 1; argv[i]; ++i) |
448 | { |
502 | { |