… | |
… | |
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 | |
18 | #include "shader.h" |
20 | #include "shader.h" |
19 | |
21 | |
20 | /**********************************************************************/ |
22 | /**********************************************************************/ |
21 | |
23 | |
22 | view camera; |
24 | view camera; |
… | |
… | |
28 | HotKey_ToggleFullScreen (void) |
30 | HotKey_ToggleFullScreen (void) |
29 | { |
31 | { |
30 | SDL_Surface *screen; |
32 | SDL_Surface *screen; |
31 | |
33 | |
32 | screen = SDL_GetVideoSurface (); |
34 | screen = SDL_GetVideoSurface (); |
|
|
35 | |
33 | if (SDL_WM_ToggleFullScreen (screen)) |
36 | if (SDL_WM_ToggleFullScreen (screen)) |
34 | printf ("Toggled fullscreen mode - now %s\n", |
37 | printf ("Toggled fullscreen mode - now %s\n", |
35 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
38 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
36 | else |
39 | else |
37 | printf ("Unable to toggle fullscreen mode\n"); |
40 | printf ("Unable to toggle fullscreen mode\n"); |
… | |
… | |
42 | { |
45 | { |
43 | SDL_GrabMode mode; |
46 | SDL_GrabMode mode; |
44 | |
47 | |
45 | printf ("Ctrl-G: toggling input grab!\n"); |
48 | printf ("Ctrl-G: toggling input grab!\n"); |
46 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
49 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
|
|
50 | |
47 | if (mode == SDL_GRAB_ON) |
51 | if (mode == SDL_GRAB_ON) |
48 | printf ("Grab was on\n"); |
52 | printf ("Grab was on\n"); |
49 | else |
53 | else |
50 | printf ("Grab was off\n"); |
54 | printf ("Grab was off\n"); |
51 | |
55 | |
52 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
56 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
|
|
57 | |
53 | if (mode == SDL_GRAB_ON) |
58 | if (mode == SDL_GRAB_ON) |
54 | printf ("Grab is now on\n"); |
59 | printf ("Grab is now on\n"); |
55 | else |
60 | else |
56 | printf ("Grab is now off\n"); |
61 | printf ("Grab is now off\n"); |
57 | } |
62 | } |
… | |
… | |
67 | HandleEvent (SDL_Event * event) |
72 | HandleEvent (SDL_Event * event) |
68 | { |
73 | { |
69 | int done; |
74 | int done; |
70 | |
75 | |
71 | done = 0; |
76 | done = 0; |
|
|
77 | |
72 | switch (event->type) |
78 | switch (event->type) |
73 | { |
79 | { |
74 | case SDL_ACTIVEEVENT: |
80 | case SDL_ACTIVEEVENT: |
75 | /* See what happened */ |
81 | /* See what happened */ |
76 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
82 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
… | |
… | |
145 | 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))); |
146 | 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))); |
147 | 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))); |
148 | |
154 | |
149 | geometry_quads *q = new geometry_quads; |
155 | geometry_quads *q = new geometry_quads; |
150 | q->m = new simple_material; |
156 | //q->m = new simple_material; |
151 | q->set (pts); |
157 | q->set (pts); |
152 | entity *e = new entity (q); |
158 | entity *e = new entity (q); |
153 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
159 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
154 | e->show (); |
160 | e->show (); |
155 | } |
161 | } |
… | |
… | |
165 | e->show (); |
171 | e->show (); |
166 | } |
172 | } |
167 | |
173 | |
168 | void fisch (vec3 center, GLfloat radius, int depth) |
174 | void fisch (vec3 center, GLfloat radius, int depth) |
169 | { |
175 | { |
170 | entity *planet = new entity (new geometry_sphere (radius)); |
176 | entity *planet = new entity (new geometry_sphere (testmat, radius)); |
171 | planet->move (center); |
177 | planet->move (center); |
172 | planet->show (); |
178 | planet->show (); |
173 | |
179 | |
174 | if (--depth) |
180 | if (--depth) |
175 | { |
181 | { |
… | |
… | |
296 | |
302 | |
297 | /* Set the gamma for the window */ |
303 | /* Set the gamma for the window */ |
298 | if (gamma != 0.0) |
304 | if (gamma != 0.0) |
299 | SDL_SetGamma (gamma, gamma, gamma); |
305 | SDL_SetGamma (gamma, gamma, gamma); |
300 | |
306 | |
|
|
307 | |
|
|
308 | |
|
|
309 | testmat = new test_material; |
|
|
310 | |
301 | entity *planet = new entity (new geometry_sphere (10)); |
311 | entity *planet = new entity (new geometry_sphere (testmat, 10)); |
302 | planet->move (vec3 (0, 0, -20)); |
312 | planet->move (vec3 (0, 0, -20)); |
303 | planet->show (); |
313 | planet->show (); |
304 | |
314 | |
305 | shader::debdebdebdebug ();//D |
315 | //doom3parse ("test.proc"); |
306 | |
316 | |
307 | #if 1 |
|
|
308 | for (int i = 0; i < 20; i++) |
317 | for (int i = 0; i < 20; i++) |
309 | { |
318 | { |
310 | // load a entity |
319 | // load a entity |
311 | txtprt_parser p; |
320 | txtprt_parser p; |
312 | geometry *g; |
321 | geometry *g; |
… | |
… | |
330 | //planet->move (vec3 (0, 0, -1.5e9)); |
339 | //planet->move (vec3 (0, 0, -1.5e9)); |
331 | //planet->show (); |
340 | //planet->show (); |
332 | } |
341 | } |
333 | |
342 | |
334 | { |
343 | { |
335 | entity *planet = new entity (new geometry_sphere (4e15)); |
344 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
336 | planet->move (vec3 (0, 0, 1e17)); |
345 | planet->move (vec3 (0, 0, 1e17)); |
337 | planet->show (); |
346 | planet->show (); |
338 | } |
347 | } |
339 | |
348 | |
340 | draw_floor (10, -500, -10, -1000); |
349 | //draw_floor (10, -500, -10, -1000); |
341 | draw_level (); |
350 | draw_level (); |
|
|
351 | |
|
|
352 | |
|
|
353 | #if 0 |
|
|
354 | { |
|
|
355 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
|
|
356 | entity *e = new entity (hf); |
|
|
357 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
|
|
358 | e->show (); |
|
|
359 | } |
|
|
360 | #endif |
|
|
361 | |
342 | //draw_test_nurb (); |
362 | //draw_test_nurb (); |
343 | #endif |
|
|
344 | |
363 | |
345 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
364 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
346 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
365 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
347 | camera.p = point (0, 0, 10); |
366 | camera.p = point (0, 0, 10); |
348 | camera.d = vec3 (0, 0, -1); |
367 | camera.d = vec3 (0, 0, -1); |
… | |
… | |
352 | |
371 | |
353 | glEnable (GL_CULL_FACE); |
372 | glEnable (GL_CULL_FACE); |
354 | glDisable (GL_ALPHA_TEST); |
373 | glDisable (GL_ALPHA_TEST); |
355 | glDisable (GL_BLEND); |
374 | glDisable (GL_BLEND); |
356 | |
375 | |
357 | init_shaders (); |
|
|
358 | |
|
|
359 | osama_material osa_mat; |
|
|
360 | |
|
|
361 | /* Loop until done. */ |
376 | /* Loop until done. */ |
362 | frames = 0; |
377 | frames = 0; |
363 | |
378 | |
|
|
379 | linear_light mylight; |
|
|
380 | mylight.radius = 100000; |
|
|
381 | mylight.c = colour (1., 1, 1, 1.); |
|
|
382 | mylight.intensity = 1.F; |
|
|
383 | |
|
|
384 | pass pass_light (&mylight); |
|
|
385 | |
364 | while (!done) |
386 | while (!done) |
365 | { |
387 | { |
366 | char *sdl_error; |
388 | char *sdl_error; |
367 | SDL_Event event; |
389 | SDL_Event event; |
368 | |
390 | |
… | |
… | |
376 | camera.u = cross (camera.d, right); |
398 | camera.u = cross (camera.d, right); |
377 | |
399 | |
378 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
400 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
379 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
401 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
380 | |
402 | |
381 | osa_mat.begin (); |
403 | mylight.orig = camera.orig; |
|
|
404 | mylight.p = camera.p; |
382 | |
405 | |
|
|
406 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
|
|
407 | |
383 | camera.begin (); |
408 | camera.begin (); |
384 | camera.render (view::DEPTH); |
409 | camera.render (view::DEPTH, pass_depth); |
385 | camera.render (view::POSTDEPTH); |
410 | camera.render (view::POSTDEPTH, pass_depth); |
386 | camera.render (view::LIGHTED); |
411 | camera.render (view::LIGHTED, pass_light); |
387 | camera.end (); |
412 | camera.end (); |
388 | |
413 | |
389 | SDL_GL_SwapBuffers (); |
414 | SDL_GL_SwapBuffers (); |
390 | timer.frame (); |
415 | timer.frame (); |
391 | |
|
|
392 | osa_mat.end (); |
|
|
393 | |
416 | |
394 | #if 0 |
417 | #if 0 |
395 | /* Check for error conditions. */ |
418 | /* Check for error conditions. */ |
396 | gl_error = glGetError (); |
419 | gl_error = glGetError (); |
397 | |
420 | |
… | |
… | |
411 | |
434 | |
412 | /* Check if there's a pending event. */ |
435 | /* Check if there's a pending event. */ |
413 | while (SDL_PollEvent (&event)) |
436 | while (SDL_PollEvent (&event)) |
414 | done = HandleEvent (&event); |
437 | done = HandleEvent (&event); |
415 | |
438 | |
416 | |
|
|
417 | ++frames; |
439 | ++frames; |
418 | } |
440 | } |
419 | |
441 | |
420 | if (global_image) |
442 | if (global_image) |
421 | { |
443 | { |
422 | SDL_FreeSurface (global_image); |
444 | SDL_FreeSurface (global_image); |
423 | global_image = NULL; |
445 | global_image = NULL; |
424 | } |
446 | } |
|
|
447 | |
425 | if (global_texture) |
448 | if (global_texture) |
426 | { |
449 | { |
427 | glDeleteTextures (1, &global_texture); |
450 | glDeleteTextures (1, &global_texture); |
428 | global_texture = 0; |
451 | global_texture = 0; |
429 | } |
452 | } |