ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/test.C
(Generate patch)

Comparing libgender/test.C (file contents):
Revision 1.68 by root, Thu Oct 21 21:20:09 2004 UTC vs.
Revision 1.78 by root, Wed Nov 3 03:35:13 2004 UTC

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
20view camera; 22view camera;
21vec3 camera_velocity; 23vec3 camera_velocity;
22float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; 24float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2;
26HotKey_ToggleFullScreen (void) 28HotKey_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}
65HandleEvent (SDL_Event * event) 70HandleEvent (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");
143 pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); 149 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))); 150 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))); 151 pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0)));
146 152
147 geometry_quads *q = new geometry_quads; 153 geometry_quads *q = new geometry_quads;
148 q->m = new simple_material; 154 //q->m = new simple_material;
149 q->set (pts); 155 q->set (pts);
150 entity *e = new entity (q); 156 entity *e = new entity (q);
151 e->move (vec3 (dx + x * size, dy, dz + z * size)); 157 e->move (vec3 (dx + x * size, dy, dz + z * size));
152 e->show (); 158 e->show ();
153 } 159 }
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);
294 300
295 /* Set the gamma for the window */ 301 /* Set the gamma for the window */
296 if (gamma != 0.0) 302 if (gamma != 0.0)
297 SDL_SetGamma (gamma, gamma, gamma); 303 SDL_SetGamma (gamma, gamma, gamma);
298 304
305#if 0
299 entity *planet = new entity (new geometry_sphere (10)); 306 entity *planet = new entity (new geometry_sphere (10));
300 planet->move (vec3 (0, 0, -20)); 307 planet->move (vec3 (0, 0, -20));
301 planet->show (); 308 planet->show ();
309#endif
302 310
303#if 1
304 for (int i = 0; i < 20; i++) 311 for (int i = 0; i < 20; i++)
305 { 312 {
306 // load a entity 313 // load a entity
307 txtprt_parser p; 314 txtprt_parser p;
308 geometry *g; 315 geometry *g;
318 entity *e = new entity (g); 325 entity *e = new entity (g);
319 e->move (vec3 (i*5, -3, -i*10)); 326 e->move (vec3 (i*5, -3, -i*10));
320 e->show (); 327 e->show ();
321 } 328 }
322 329
330#if 0
323 { 331 {
324 fisch (vec3 (0, 0, -2e9), 1e9, 8); 332 fisch (vec3 (0, 0, -2e9), 1e9, 8);
325 //entity *planet = new entity (new geometry_sphere (1e9)); 333 //entity *planet = new entity (new geometry_sphere (1e9));
326 //planet->move (vec3 (0, 0, -1.5e9)); 334 //planet->move (vec3 (0, 0, -1.5e9));
327 //planet->show (); 335 //planet->show ();
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 ();
354
355 osama_material osa_mat;
356
357 /* Loop until done. */ 370 /* Loop until done. */
358 frames = 0; 371 frames = 0;
359 372
373 linear_light mylight;
374 mylight.c = colour (1., 0, 0, 1.);
375 mylight.intensity = 0.4;
376 mylight.radius = 100000;
377
378 pass pass_light (&mylight);
379
360 while (!done) 380 while (!done)
361 { 381 {
362 char *sdl_error; 382 char *sdl_error;
363 SDL_Event event; 383 SDL_Event event;
364 384
372 camera.u = cross (camera.d, right); 392 camera.u = cross (camera.d, right);
373 393
374 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; 394 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; 395 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y;
376 396
377 osa_mat.begin (); 397 mylight.orig = camera.orig;
398 mylight.p = camera.p;
378 399
379 camera.begin (); 400 camera.begin ();
380 camera.render (view::DEPTH); 401 camera.render (view::DEPTH, pass_depth);
381 camera.render (view::POSTDEPTH); 402 camera.render (view::POSTDEPTH, pass_depth);
382 camera.render (view::LIGHTED); 403 camera.render (view::LIGHTED, pass_light);
383 camera.end (); 404 camera.end ();
384 405
385 SDL_GL_SwapBuffers (); 406 SDL_GL_SwapBuffers ();
386 timer.frame (); 407 timer.frame ();
387
388 osa_mat.end ();
389 408
390#if 0 409#if 0
391 /* Check for error conditions. */ 410 /* Check for error conditions. */
392 gl_error = glGetError (); 411 gl_error = glGetError ();
393 412
407 426
408 /* Check if there's a pending event. */ 427 /* Check if there's a pending event. */
409 while (SDL_PollEvent (&event)) 428 while (SDL_PollEvent (&event))
410 done = HandleEvent (&event); 429 done = HandleEvent (&event);
411 430
412
413 ++frames; 431 ++frames;
414 } 432 }
415 433
416 if (global_image) 434 if (global_image)
417 { 435 {
418 SDL_FreeSurface (global_image); 436 SDL_FreeSurface (global_image);
419 global_image = NULL; 437 global_image = NULL;
420 } 438 }
439
421 if (global_texture) 440 if (global_texture)
422 { 441 {
423 glDeleteTextures (1, &global_texture); 442 glDeleteTextures (1, &global_texture);
424 global_texture = 0; 443 global_texture = 0;
425 } 444 }
437 int slowly; 456 int slowly;
438 float gamma = 0.0; 457 float gamma = 0.0;
439 int noframe = 0; 458 int noframe = 0;
440 int fsaa = 0; 459 int fsaa = 0;
441 460
442 shader::debdebdebdebug ();//D
443
444 logo = 0; 461 logo = 0;
445 slowly = 0; 462 slowly = 0;
446 numtests = 1; 463 numtests = 1;
447 for (i = 1; argv[i]; ++i) 464 for (i = 1; argv[i]; ++i)
448 { 465 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines