… | |
… | |
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 | #include "shader.h" |
|
|
19 | |
18 | /**********************************************************************/ |
20 | /**********************************************************************/ |
19 | |
21 | |
20 | view camera; |
22 | view camera; |
21 | vec3 camera_velocity; |
23 | vec3 camera_velocity; |
22 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
24 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
… | |
… | |
26 | HotKey_ToggleFullScreen (void) |
28 | HotKey_ToggleFullScreen (void) |
27 | { |
29 | { |
28 | SDL_Surface *screen; |
30 | SDL_Surface *screen; |
29 | |
31 | |
30 | screen = SDL_GetVideoSurface (); |
32 | screen = SDL_GetVideoSurface (); |
|
|
33 | |
31 | if (SDL_WM_ToggleFullScreen (screen)) |
34 | if (SDL_WM_ToggleFullScreen (screen)) |
32 | printf ("Toggled fullscreen mode - now %s\n", |
35 | printf ("Toggled fullscreen mode - now %s\n", |
33 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
36 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
34 | else |
37 | else |
35 | printf ("Unable to toggle fullscreen mode\n"); |
38 | printf ("Unable to toggle fullscreen mode\n"); |
… | |
… | |
40 | { |
43 | { |
41 | SDL_GrabMode mode; |
44 | SDL_GrabMode mode; |
42 | |
45 | |
43 | printf ("Ctrl-G: toggling input grab!\n"); |
46 | printf ("Ctrl-G: toggling input grab!\n"); |
44 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
47 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
|
|
48 | |
45 | if (mode == SDL_GRAB_ON) |
49 | if (mode == SDL_GRAB_ON) |
46 | printf ("Grab was on\n"); |
50 | printf ("Grab was on\n"); |
47 | else |
51 | else |
48 | printf ("Grab was off\n"); |
52 | printf ("Grab was off\n"); |
49 | |
53 | |
50 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
54 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
|
|
55 | |
51 | if (mode == SDL_GRAB_ON) |
56 | if (mode == SDL_GRAB_ON) |
52 | printf ("Grab is now on\n"); |
57 | printf ("Grab is now on\n"); |
53 | else |
58 | else |
54 | printf ("Grab is now off\n"); |
59 | printf ("Grab is now off\n"); |
55 | } |
60 | } |
… | |
… | |
65 | HandleEvent (SDL_Event * event) |
70 | HandleEvent (SDL_Event * event) |
66 | { |
71 | { |
67 | int done; |
72 | int done; |
68 | |
73 | |
69 | done = 0; |
74 | done = 0; |
|
|
75 | |
70 | switch (event->type) |
76 | switch (event->type) |
71 | { |
77 | { |
72 | case SDL_ACTIVEEVENT: |
78 | case SDL_ACTIVEEVENT: |
73 | /* See what happened */ |
79 | /* See what happened */ |
74 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
80 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
… | |
… | |
243 | } |
249 | } |
244 | |
250 | |
245 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
251 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
246 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
252 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
247 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
253 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
248 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
254 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
249 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
255 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
250 | |
256 | |
251 | if (fsaa) |
257 | if (fsaa) |
252 | { |
258 | { |
253 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
259 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
… | |
… | |
259 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
265 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
260 | SDL_Quit (); |
266 | SDL_Quit (); |
261 | exit (1); |
267 | exit (1); |
262 | } |
268 | } |
263 | |
269 | |
264 | printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
270 | //printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
265 | printf ("\n"); |
271 | //printf ("\n"); |
266 | printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
272 | //printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
267 | printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
273 | //printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
268 | printf ("Version : %s\n", glGetString (GL_VERSION)); |
274 | //printf ("Version : %s\n", glGetString (GL_VERSION)); |
269 | printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
275 | //printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
270 | printf ("\n"); |
276 | printf ("\n"); |
271 | |
277 | |
272 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
278 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
273 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
279 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
274 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
280 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
… | |
… | |
297 | SDL_SetGamma (gamma, gamma, gamma); |
303 | SDL_SetGamma (gamma, gamma, gamma); |
298 | |
304 | |
299 | entity *planet = new entity (new geometry_sphere (10)); |
305 | entity *planet = new entity (new geometry_sphere (10)); |
300 | planet->move (vec3 (0, 0, -20)); |
306 | planet->move (vec3 (0, 0, -20)); |
301 | planet->show (); |
307 | planet->show (); |
|
|
308 | |
|
|
309 | shader::debdebdebdebug ();//D |
302 | |
310 | |
303 | #if 1 |
311 | #if 1 |
304 | for (int i = 0; i < 20; i++) |
312 | for (int i = 0; i < 20; i++) |
305 | { |
313 | { |
306 | // load a entity |
314 | // load a entity |
… | |
… | |
331 | entity *planet = new entity (new geometry_sphere (4e15)); |
339 | entity *planet = new entity (new geometry_sphere (4e15)); |
332 | planet->move (vec3 (0, 0, 1e17)); |
340 | planet->move (vec3 (0, 0, 1e17)); |
333 | planet->show (); |
341 | planet->show (); |
334 | } |
342 | } |
335 | |
343 | |
336 | draw_floor (10, -500, -10, -1000); |
344 | //draw_floor (10, -500, -10, -1000); |
337 | draw_level (); |
345 | draw_level (); |
|
|
346 | |
|
|
347 | |
|
|
348 | { |
|
|
349 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
|
|
350 | entity *e = new entity (hf); |
|
|
351 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
|
|
352 | e->show (); |
|
|
353 | } |
|
|
354 | |
338 | //draw_test_nurb (); |
355 | //draw_test_nurb (); |
339 | #endif |
356 | #endif |
340 | |
357 | |
341 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
358 | //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; |
359 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
… | |
… | |
348 | |
365 | |
349 | glEnable (GL_CULL_FACE); |
366 | glEnable (GL_CULL_FACE); |
350 | glDisable (GL_ALPHA_TEST); |
367 | glDisable (GL_ALPHA_TEST); |
351 | glDisable (GL_BLEND); |
368 | glDisable (GL_BLEND); |
352 | |
369 | |
353 | init_shaders (); |
370 | test_material test_mat; |
354 | |
|
|
355 | osama_material osa_mat; |
|
|
356 | |
371 | |
357 | /* Loop until done. */ |
372 | /* Loop until done. */ |
358 | frames = 0; |
373 | frames = 0; |
359 | |
374 | |
360 | while (!done) |
375 | while (!done) |
… | |
… | |
372 | camera.u = cross (camera.d, right); |
387 | camera.u = cross (camera.d, right); |
373 | |
388 | |
374 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
389 | 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; |
390 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
376 | |
391 | |
377 | osa_mat.begin (); |
|
|
378 | |
392 | |
379 | camera.begin (); |
393 | camera.begin (); |
380 | camera.render (view::DEPTH); |
394 | camera.render (view::DEPTH, pass_depth); |
381 | camera.render (view::POSTDEPTH); |
395 | camera.render (view::POSTDEPTH, pass_depth); |
|
|
396 | test_mat.enable (camera); |
382 | camera.render (view::LIGHTED); |
397 | camera.render (view::LIGHTED, pass_depth); |
|
|
398 | test_mat.disable (camera); |
383 | camera.end (); |
399 | camera.end (); |
384 | |
400 | |
385 | SDL_GL_SwapBuffers (); |
401 | SDL_GL_SwapBuffers (); |
386 | timer.frame (); |
402 | timer.frame (); |
387 | |
|
|
388 | osa_mat.end (); |
|
|
389 | |
403 | |
390 | #if 0 |
404 | #if 0 |
391 | /* Check for error conditions. */ |
405 | /* Check for error conditions. */ |
392 | gl_error = glGetError (); |
406 | gl_error = glGetError (); |
393 | |
407 | |
… | |
… | |
407 | |
421 | |
408 | /* Check if there's a pending event. */ |
422 | /* Check if there's a pending event. */ |
409 | while (SDL_PollEvent (&event)) |
423 | while (SDL_PollEvent (&event)) |
410 | done = HandleEvent (&event); |
424 | done = HandleEvent (&event); |
411 | |
425 | |
412 | |
|
|
413 | ++frames; |
426 | ++frames; |
414 | } |
427 | } |
415 | |
428 | |
416 | if (global_image) |
429 | if (global_image) |
417 | { |
430 | { |
418 | SDL_FreeSurface (global_image); |
431 | SDL_FreeSurface (global_image); |
419 | global_image = NULL; |
432 | global_image = NULL; |
420 | } |
433 | } |
|
|
434 | |
421 | if (global_texture) |
435 | if (global_texture) |
422 | { |
436 | { |
423 | glDeleteTextures (1, &global_texture); |
437 | glDeleteTextures (1, &global_texture); |
424 | global_texture = 0; |
438 | global_texture = 0; |
425 | } |
439 | } |
… | |
… | |
437 | int slowly; |
451 | int slowly; |
438 | float gamma = 0.0; |
452 | float gamma = 0.0; |
439 | int noframe = 0; |
453 | int noframe = 0; |
440 | int fsaa = 0; |
454 | int fsaa = 0; |
441 | |
455 | |
442 | shader::debdebdebdebug ();//D |
|
|
443 | |
|
|
444 | logo = 0; |
456 | logo = 0; |
445 | slowly = 0; |
457 | slowly = 0; |
446 | numtests = 1; |
458 | numtests = 1; |
447 | for (i = 1; argv[i]; ++i) |
459 | for (i = 1; argv[i]; ++i) |
448 | { |
460 | { |