… | |
… | |
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 | { |
… | |
… | |
243 | } |
251 | } |
244 | |
252 | |
245 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
253 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
246 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
254 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
247 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
255 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
248 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
256 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
249 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
257 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
250 | |
258 | |
251 | if (fsaa) |
259 | if (fsaa) |
252 | { |
260 | { |
253 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
261 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
… | |
… | |
259 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
267 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
260 | SDL_Quit (); |
268 | SDL_Quit (); |
261 | exit (1); |
269 | exit (1); |
262 | } |
270 | } |
263 | |
271 | |
264 | printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
272 | //printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
265 | printf ("\n"); |
273 | //printf ("\n"); |
266 | printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
274 | //printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
267 | printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
275 | //printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
268 | printf ("Version : %s\n", glGetString (GL_VERSION)); |
276 | //printf ("Version : %s\n", glGetString (GL_VERSION)); |
269 | printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
277 | //printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
270 | printf ("\n"); |
278 | printf ("\n"); |
271 | |
279 | |
272 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
280 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
273 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
281 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
274 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
282 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
… | |
… | |
294 | |
302 | |
295 | /* Set the gamma for the window */ |
303 | /* Set the gamma for the window */ |
296 | if (gamma != 0.0) |
304 | if (gamma != 0.0) |
297 | SDL_SetGamma (gamma, gamma, gamma); |
305 | SDL_SetGamma (gamma, gamma, gamma); |
298 | |
306 | |
|
|
307 | |
|
|
308 | |
|
|
309 | testmat = new test_material; |
|
|
310 | |
299 | entity *planet = new entity (new geometry_sphere (10)); |
311 | entity *planet = new entity (new geometry_sphere (testmat, 10)); |
300 | planet->move (vec3 (0, 0, -20)); |
312 | planet->move (vec3 (0, 0, -20)); |
301 | planet->show (); |
313 | planet->show (); |
302 | |
314 | |
303 | #if 1 |
315 | //doom3parse ("test.proc"); |
|
|
316 | |
304 | for (int i = 0; i < 20; i++) |
317 | for (int i = 0; i < 20; i++) |
305 | { |
318 | { |
306 | // load a entity |
319 | // load a entity |
307 | txtprt_parser p; |
320 | txtprt_parser p; |
308 | geometry *g; |
321 | geometry *g; |
… | |
… | |
326 | //planet->move (vec3 (0, 0, -1.5e9)); |
339 | //planet->move (vec3 (0, 0, -1.5e9)); |
327 | //planet->show (); |
340 | //planet->show (); |
328 | } |
341 | } |
329 | |
342 | |
330 | { |
343 | { |
331 | entity *planet = new entity (new geometry_sphere (4e15)); |
344 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
332 | planet->move (vec3 (0, 0, 1e17)); |
345 | planet->move (vec3 (0, 0, 1e17)); |
333 | planet->show (); |
346 | planet->show (); |
334 | } |
347 | } |
335 | |
348 | |
336 | draw_floor (10, -500, -10, -1000); |
349 | //draw_floor (10, -500, -10, -1000); |
337 | 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 | |
338 | //draw_test_nurb (); |
362 | //draw_test_nurb (); |
339 | #endif |
|
|
340 | |
363 | |
341 | //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; |
342 | 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; |
343 | camera.p = point (0, 0, 10); |
366 | camera.p = point (0, 0, 10); |
344 | camera.d = vec3 (0, 0, -1); |
367 | camera.d = vec3 (0, 0, -1); |
… | |
… | |
348 | |
371 | |
349 | glEnable (GL_CULL_FACE); |
372 | glEnable (GL_CULL_FACE); |
350 | glDisable (GL_ALPHA_TEST); |
373 | glDisable (GL_ALPHA_TEST); |
351 | glDisable (GL_BLEND); |
374 | glDisable (GL_BLEND); |
352 | |
375 | |
353 | init_shaders (); |
|
|
354 | |
|
|
355 | osama_material osa_mat; |
|
|
356 | |
|
|
357 | /* Loop until done. */ |
376 | /* Loop until done. */ |
358 | frames = 0; |
377 | frames = 0; |
359 | |
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 | |
360 | while (!done) |
386 | while (!done) |
361 | { |
387 | { |
362 | char *sdl_error; |
388 | char *sdl_error; |
363 | SDL_Event event; |
389 | SDL_Event event; |
364 | |
390 | |
… | |
… | |
372 | camera.u = cross (camera.d, right); |
398 | camera.u = cross (camera.d, right); |
373 | |
399 | |
374 | 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; |
375 | 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; |
376 | |
402 | |
377 | osa_mat.begin (); |
403 | mylight.orig = camera.orig; |
|
|
404 | mylight.p = camera.p; |
378 | |
405 | |
|
|
406 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
|
|
407 | |
379 | camera.begin (); |
408 | camera.begin (); |
380 | camera.render (view::DEPTH); |
409 | camera.render (view::DEPTH, pass_depth); |
381 | camera.render (view::POSTDEPTH); |
410 | camera.render (view::POSTDEPTH, pass_depth); |
382 | camera.render (view::LIGHTED); |
411 | camera.render (view::LIGHTED, pass_light); |
383 | camera.end (); |
412 | camera.end (); |
384 | |
413 | |
385 | SDL_GL_SwapBuffers (); |
414 | SDL_GL_SwapBuffers (); |
386 | timer.frame (); |
415 | timer.frame (); |
387 | |
|
|
388 | osa_mat.end (); |
|
|
389 | |
416 | |
390 | #if 0 |
417 | #if 0 |
391 | /* Check for error conditions. */ |
418 | /* Check for error conditions. */ |
392 | gl_error = glGetError (); |
419 | gl_error = glGetError (); |
393 | |
420 | |
… | |
… | |
407 | |
434 | |
408 | /* Check if there's a pending event. */ |
435 | /* Check if there's a pending event. */ |
409 | while (SDL_PollEvent (&event)) |
436 | while (SDL_PollEvent (&event)) |
410 | done = HandleEvent (&event); |
437 | done = HandleEvent (&event); |
411 | |
438 | |
412 | |
|
|
413 | ++frames; |
439 | ++frames; |
414 | } |
440 | } |
415 | |
441 | |
416 | if (global_image) |
442 | if (global_image) |
417 | { |
443 | { |
418 | SDL_FreeSurface (global_image); |
444 | SDL_FreeSurface (global_image); |
419 | global_image = NULL; |
445 | global_image = NULL; |
420 | } |
446 | } |
|
|
447 | |
421 | if (global_texture) |
448 | if (global_texture) |
422 | { |
449 | { |
423 | glDeleteTextures (1, &global_texture); |
450 | glDeleteTextures (1, &global_texture); |
424 | global_texture = 0; |
451 | global_texture = 0; |
425 | } |
452 | } |
… | |
… | |
437 | int slowly; |
464 | int slowly; |
438 | float gamma = 0.0; |
465 | float gamma = 0.0; |
439 | int noframe = 0; |
466 | int noframe = 0; |
440 | int fsaa = 0; |
467 | int fsaa = 0; |
441 | |
468 | |
442 | shader::debdebdebdebug ();//D |
|
|
443 | |
|
|
444 | logo = 0; |
469 | logo = 0; |
445 | slowly = 0; |
470 | slowly = 0; |
446 | numtests = 1; |
471 | numtests = 1; |
447 | for (i = 1; argv[i]; ++i) |
472 | for (i = 1; argv[i]; ++i) |
448 | { |
473 | { |