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.81 by root, Thu Nov 4 04:49:04 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 }
163 e->show (); 169 e->show ();
164} 170}
165 171
166void fisch (vec3 center, GLfloat radius, int depth) 172void fisch (vec3 center, GLfloat radius, int depth)
167{ 173{
168 entity *planet = new entity (new geometry_sphere (radius)); 174 entity *planet = new entity (new geometry_sphere (testmat, radius));
169 planet->move (center); 175 planet->move (center);
170 planet->show (); 176 planet->show ();
171 177
172 if (--depth) 178 if (--depth)
173 { 179 {
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 testmat = new test_material;
306
299 entity *planet = new entity (new geometry_sphere (10)); 307 entity *planet = new entity (new geometry_sphere (testmat, 10));
300 planet->move (vec3 (0, 0, -20)); 308 planet->move (vec3 (0, 0, -20));
301 planet->show (); 309 planet->show ();
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;
326 //planet->move (vec3 (0, 0, -1.5e9)); 333 //planet->move (vec3 (0, 0, -1.5e9));
327 //planet->show (); 334 //planet->show ();
328 } 335 }
329 336
330 { 337 {
331 entity *planet = new entity (new geometry_sphere (4e15)); 338 entity *planet = new entity (new geometry_sphere (testmat, 4e15));
332 planet->move (vec3 (0, 0, 1e17)); 339 planet->move (vec3 (0, 0, 1e17));
333 planet->show (); 340 planet->show ();
334 } 341 }
335 342
336 draw_floor (10, -500, -10, -1000); 343 //draw_floor (10, -500, -10, -1000);
337 draw_level (); 344 draw_level ();
345
346
347#if 0
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.radius = 100000;
375 mylight.c = colour (1., 1, 1, 1.);
376 mylight.intensity = 1.F;
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
400 //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F);
401
379 camera.begin (); 402 camera.begin ();
380 camera.render (view::DEPTH); 403 camera.render (view::DEPTH, pass_depth);
381 camera.render (view::POSTDEPTH); 404 camera.render (view::POSTDEPTH, pass_depth);
382 camera.render (view::LIGHTED); 405 camera.render (view::LIGHTED, pass_light);
383 camera.end (); 406 camera.end ();
384 407
385 SDL_GL_SwapBuffers (); 408 SDL_GL_SwapBuffers ();
386 timer.frame (); 409 timer.frame ();
387
388 osa_mat.end ();
389 410
390#if 0 411#if 0
391 /* Check for error conditions. */ 412 /* Check for error conditions. */
392 gl_error = glGetError (); 413 gl_error = glGetError ();
393 414
407 428
408 /* Check if there's a pending event. */ 429 /* Check if there's a pending event. */
409 while (SDL_PollEvent (&event)) 430 while (SDL_PollEvent (&event))
410 done = HandleEvent (&event); 431 done = HandleEvent (&event);
411 432
412
413 ++frames; 433 ++frames;
414 } 434 }
415 435
416 if (global_image) 436 if (global_image)
417 { 437 {
418 SDL_FreeSurface (global_image); 438 SDL_FreeSurface (global_image);
419 global_image = NULL; 439 global_image = NULL;
420 } 440 }
441
421 if (global_texture) 442 if (global_texture)
422 { 443 {
423 glDeleteTextures (1, &global_texture); 444 glDeleteTextures (1, &global_texture);
424 global_texture = 0; 445 global_texture = 0;
425 } 446 }
437 int slowly; 458 int slowly;
438 float gamma = 0.0; 459 float gamma = 0.0;
439 int noframe = 0; 460 int noframe = 0;
440 int fsaa = 0; 461 int fsaa = 0;
441 462
442 shader::debdebdebdebug ();//D
443
444 logo = 0; 463 logo = 0;
445 slowly = 0; 464 slowly = 0;
446 numtests = 1; 465 numtests = 1;
447 for (i = 1; argv[i]; ++i) 466 for (i = 1; argv[i]; ++i)
448 { 467 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines