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.87 by root, Sat Nov 6 00:56:18 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
18bool doom3parse (const char *f);
19
20#include "shader.h"
21
18/**********************************************************************/ 22/**********************************************************************/
19 23
20view camera; 24view camera;
21vec3 camera_velocity; 25vec3 camera_velocity;
22float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; 26float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2;
26HotKey_ToggleFullScreen (void) 30HotKey_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}
65HandleEvent (SDL_Event * event) 72HandleEvent (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
166void fisch (vec3 center, GLfloat radius, int depth) 174void 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
315 doom3parse ("test.proc");
316
303#if 1 317#if 0
304 for (int i = 0; i < 20; i++) 318 for (int i = 0; i < 20; i++)
305 { 319 {
306 // load a entity 320 // load a entity
307 txtprt_parser p; 321 txtprt_parser p;
308 geometry *g; 322 geometry *g;
326 //planet->move (vec3 (0, 0, -1.5e9)); 340 //planet->move (vec3 (0, 0, -1.5e9));
327 //planet->show (); 341 //planet->show ();
328 } 342 }
329 343
330 { 344 {
331 entity *planet = new entity (new geometry_sphere (4e15)); 345 entity *planet = new entity (new geometry_sphere (testmat, 4e15));
332 planet->move (vec3 (0, 0, 1e17)); 346 planet->move (vec3 (0, 0, 1e17));
333 planet->show (); 347 planet->show ();
334 } 348 }
335 349
336 draw_floor (10, -500, -10, -1000); 350 //draw_floor (10, -500, -10, -1000);
337 draw_level (); 351 draw_level ();
352#endif
353
354
355#if 0
356 {
357 geometry_heightfield *hf = new geometry_heightfield (100000., 100000.);
358 entity *e = new entity (hf);
359 e->move (vec3 (-100000, -100000 * 0.01, -100000));
360 e->show ();
361 }
362#endif
363
338 //draw_test_nurb (); 364 //draw_test_nurb ();
339#endif
340 365
341 //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; 366 //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; 367 camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0;
343 camera.p = point (0, 0, 10); 368 camera.p = point (0, 0, 10);
344 camera.d = vec3 (0, 0, -1); 369 camera.d = vec3 (0, 0, -1);
348 373
349 glEnable (GL_CULL_FACE); 374 glEnable (GL_CULL_FACE);
350 glDisable (GL_ALPHA_TEST); 375 glDisable (GL_ALPHA_TEST);
351 glDisable (GL_BLEND); 376 glDisable (GL_BLEND);
352 377
353 init_shaders ();
354
355 osama_material osa_mat;
356
357 /* Loop until done. */ 378 /* Loop until done. */
358 frames = 0; 379 frames = 0;
359 380
381 linear_light mylight;
382 mylight.radius = 100000;
383 mylight.c = colour (1., 1, 1, 1.);
384 mylight.intensity = 1.F;
385
386 pass pass_light (&mylight);
387
360 while (!done) 388 while (!done)
361 { 389 {
362 char *sdl_error; 390 char *sdl_error;
363 SDL_Event event; 391 SDL_Event event;
364 392
372 camera.u = cross (camera.d, right); 400 camera.u = cross (camera.d, right);
373 401
374 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; 402 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; 403 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y;
376 404
377 osa_mat.begin (); 405 mylight.orig = camera.orig;
406 mylight.p = camera.p;
378 407
408 //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F);
409
379 camera.begin (); 410 camera.begin ();
380 camera.render (view::DEPTH); 411 camera.render (view::DEPTH, pass_depth);
381 camera.render (view::POSTDEPTH); 412 camera.render (view::POSTDEPTH, pass_depth);
382 camera.render (view::LIGHTED); 413 camera.render (view::LIGHTED, pass_light);
383 camera.end (); 414 camera.end ();
384 415
385 SDL_GL_SwapBuffers (); 416 SDL_GL_SwapBuffers ();
386 timer.frame (); 417 timer.frame ();
387
388 osa_mat.end ();
389 418
390#if 0 419#if 0
391 /* Check for error conditions. */ 420 /* Check for error conditions. */
392 gl_error = glGetError (); 421 gl_error = glGetError ();
393 422
407 436
408 /* Check if there's a pending event. */ 437 /* Check if there's a pending event. */
409 while (SDL_PollEvent (&event)) 438 while (SDL_PollEvent (&event))
410 done = HandleEvent (&event); 439 done = HandleEvent (&event);
411 440
412
413 ++frames; 441 ++frames;
414 } 442 }
415 443
416 if (global_image) 444 if (global_image)
417 { 445 {
418 SDL_FreeSurface (global_image); 446 SDL_FreeSurface (global_image);
419 global_image = NULL; 447 global_image = NULL;
420 } 448 }
449
421 if (global_texture) 450 if (global_texture)
422 { 451 {
423 glDeleteTextures (1, &global_texture); 452 glDeleteTextures (1, &global_texture);
424 global_texture = 0; 453 global_texture = 0;
425 } 454 }
437 int slowly; 466 int slowly;
438 float gamma = 0.0; 467 float gamma = 0.0;
439 int noframe = 0; 468 int noframe = 0;
440 int fsaa = 0; 469 int fsaa = 0;
441 470
442 shader::debdebdebdebug ();//D
443
444 logo = 0; 471 logo = 0;
445 slowly = 0; 472 slowly = 0;
446 numtests = 1; 473 numtests = 1;
447 for (i = 1; argv[i]; ++i) 474 for (i = 1; argv[i]; ++i)
448 { 475 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines