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

Comparing libgender/test.C (file contents):
Revision 1.59 by root, Sun Oct 10 20:22:33 2004 UTC vs.
Revision 1.68 by root, Thu Oct 21 21:20:09 2004 UTC

1#include <stdlib.h> 1#include <stdlib.h>
2#include <stdio.h> 2#include <stdio.h>
3#include <string.h> 3#include <string.h>
4#include <math.h> 4#include <math.h>
5
6#include "opengl.h"
5 7
6#include "SDL.h" 8#include "SDL.h"
7#include "SDL_opengl.h" 9#include "SDL_opengl.h"
8 10
9static SDL_Surface *global_image = NULL; 11static SDL_Surface *global_image = NULL;
69 { 71 {
70 case SDL_ACTIVEEVENT: 72 case SDL_ACTIVEEVENT:
71 /* See what happened */ 73 /* See what happened */
72 printf ("app %s ", event->active.gain ? "gained" : "lost"); 74 printf ("app %s ", event->active.gain ? "gained" : "lost");
73 if (event->active.state & SDL_APPACTIVE) 75 if (event->active.state & SDL_APPACTIVE)
74 {
75 printf ("active "); 76 printf ("active ");
76 }
77 else if (event->active.state & SDL_APPMOUSEFOCUS) 77 else if (event->active.state & SDL_APPMOUSEFOCUS)
78 {
79 printf ("mouse "); 78 printf ("mouse ");
80 }
81 else if (event->active.state & SDL_APPINPUTFOCUS) 79 else if (event->active.state & SDL_APPINPUTFOCUS)
82 {
83 printf ("input "); 80 printf ("input ");
84 }
85 81
86 printf ("focus\n"); 82 printf ("focus\n");
87 break; 83 break;
88 84
89 case SDL_KEYDOWN: 85 case SDL_KEYDOWN:
136 132
137void draw_floor (int size, int dx, int dy, int dz) 133void draw_floor (int size, int dx, int dy, int dz)
138{ 134{
139 int x, z, ry; 135 int x, z, ry;
140 136
141 for (x = 0; x < 100; x++) 137 for (x = 0; x < 10; x++)
142 { 138 {
143 for (z = 0; z < 100; z++) 139 for (z = 0; z < 10; z++)
144 { 140 {
145 vector<vertex2d> pts; 141 vector<vertex_t2f_n3f_v3f> pts;
146 pts.push_back (vertex2d (point ( 0, 0, 0), vec3 (0, 1, 0), texc (0, 0))); 142 pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, 0), vec3 (0, 1, 0), tex2 (0, 0)));
147 pts.push_back (vertex2d (point ( 0, 0, size), vec3 (0, 1, 0), texc (0, 1))); 143 pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1)));
148 pts.push_back (vertex2d (point (size, 0, size), vec3 (0, 1, 0), texc (1, 1))); 144 pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1)));
149 pts.push_back (vertex2d (point (size, 0, 0), vec3 (0, 1, 0), texc (1, 0))); 145 pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0)));
150 146
151 geometry_quads *q = new geometry_quads; 147 geometry_quads *q = new geometry_quads;
152 q->m = new simple_material; 148 q->m = new simple_material;
153 q->set (pts); 149 q->set (pts);
154 entity *e = new entity (q); 150 entity *e = new entity (q);
165 entity *e = new entity (q); 161 entity *e = new entity (q);
166 e->move (vec3 (10, 3, -4)); 162 e->move (vec3 (10, 3, -4));
167 e->show (); 163 e->show ();
168} 164}
169 165
166void fisch (vec3 center, GLfloat radius, int depth)
167{
168 entity *planet = new entity (new geometry_sphere (radius));
169 planet->move (center);
170 planet->show ();
171
172 if (--depth)
173 {
174 GLfloat r2 = radius * .1F;
175 GLfloat r3 = radius + r2;
176
177 fisch (center + vec3 (r3, 0, 0), r2, depth);
178 fisch (center + vec3 (0, 0, r3), r2, depth);
179 fisch (center + vec3 (-r3, 0, 0), r2, depth);
180 }
181}
182
170extern void draw_level (); 183extern void draw_level ();
171int 184int
172RunGLTest (int argc, char *argv[], 185RunGLTest (int argc, char *argv[],
173 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) 186 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa)
174{ 187{
176 int rgb_size[3]; 189 int rgb_size[3];
177 int w = 640; 190 int w = 640;
178 int h = 480; 191 int h = 480;
179 int done = 0; 192 int done = 0;
180 int frames; 193 int frames;
181 Uint32 start_time, this_time;
182 Uint32 video_flags; 194 Uint32 video_flags;
183 int value; 195 int value;
184 GLenum gl_error; 196 GLenum gl_error;
185 197
186 if (SDL_Init (SDL_INIT_VIDEO) < 0) 198 if (SDL_Init (SDL_INIT_VIDEO) < 0)
282 294
283 /* Set the gamma for the window */ 295 /* Set the gamma for the window */
284 if (gamma != 0.0) 296 if (gamma != 0.0)
285 SDL_SetGamma (gamma, gamma, gamma); 297 SDL_SetGamma (gamma, gamma, gamma);
286 298
299 entity *planet = new entity (new geometry_sphere (10));
300 planet->move (vec3 (0, 0, -20));
301 planet->show ();
302
303#if 1
287 for (int i = 0; i < 20; i++) 304 for (int i = 0; i < 20; i++)
288 { 305 {
289 // load a entity 306 // load a entity
290 txtprt_parser p; 307 txtprt_parser p;
291 geometry *g; 308 geometry *g;
301 entity *e = new entity (g); 318 entity *e = new entity (g);
302 e->move (vec3 (i*5, -3, -i*10)); 319 e->move (vec3 (i*5, -3, -i*10));
303 e->show (); 320 e->show ();
304 } 321 }
305 322
323 {
324 fisch (vec3 (0, 0, -2e9), 1e9, 8);
325 //entity *planet = new entity (new geometry_sphere (1e9));
326 //planet->move (vec3 (0, 0, -1.5e9));
327 //planet->show ();
328 }
329
330 {
331 entity *planet = new entity (new geometry_sphere (4e15));
332 planet->move (vec3 (0, 0, 1e17));
333 planet->show ();
334 }
335
306 draw_floor (10, -500, -10, -1000); 336 draw_floor (10, -500, -10, -1000);
307 draw_level (); 337 draw_level ();
308 draw_test_nurb (); 338 //draw_test_nurb ();
339#endif
309 340
310 //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; 341 //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368;
311 camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; 342 camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0;
312 camera.p = point (0, 0, 10); 343 camera.p = point (0, 0, 10);
313 camera.d = vec3 (0, 0, -1); 344 camera.d = vec3 (0, 0, -1);
314 camera.u = vec3 (0, 1, 0); 345 camera.u = vec3 (0, 1, 0);
315 camera.w = w; camera.h = h; 346 camera.w = w; camera.h = h;
316 camera.fov = 35; 347 camera.fov = 40.;
317 camera.z_near = 1.;
318
319 glMatrixMode (GL_MODELVIEW);
320 glLoadIdentity ();
321 348
322 glEnable (GL_CULL_FACE); 349 glEnable (GL_CULL_FACE);
323 glEnable (GL_DEPTH_TEST); 350 glDisable (GL_ALPHA_TEST);
324 351 glDisable (GL_BLEND);
325 glShadeModel (GL_SMOOTH);
326
327 glEnable (GL_LIGHTING);
328 glEnable (GL_LIGHT0);
329 352
330 init_shaders (); 353 init_shaders ();
331 354
332 osama_material osa_mat; 355 osama_material osa_mat;
333 356
334 /* Loop until done. */ 357 /* Loop until done. */
335 start_time = SDL_GetTicks ();
336 frames = 0; 358 frames = 0;
337 359
338 while (!done) 360 while (!done)
339 { 361 {
340 char *sdl_error; 362 char *sdl_error;
350 camera.u = cross (camera.d, right); 372 camera.u = cross (camera.d, right);
351 373
352 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; 374 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z;
353 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; 375 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y;
354 376
355
356#if 0
357 static GLfloat ry;
358 ry += 0.001;
359 camera.d.x = cos (ry);
360 camera.d.z = sin (ry);
361 //camera.d.y = sin (ry * 0.1);
362#endif
363 osa_mat.begin (); 377 osa_mat.begin ();
364 378
365 camera.begin (); 379 camera.begin ();
366 camera.pass (view::DEPTH); 380 camera.render (view::DEPTH);
381 camera.render (view::POSTDEPTH);
367 camera.pass (view::LIGHTED); 382 camera.render (view::LIGHTED);
368 camera.end (); 383 camera.end ();
369 384
370 SDL_GL_SwapBuffers (); 385 SDL_GL_SwapBuffers ();
371 timer.frame (); 386 timer.frame ();
372 387
373 osa_mat.end (); 388 osa_mat.end ();
389
390#if 0
374 /* Check for error conditions. */ 391 /* Check for error conditions. */
375 gl_error = glGetError (); 392 gl_error = glGetError ();
376 393
377 if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); 394 if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error);
378 395
384 SDL_ClearError (); 401 SDL_ClearError ();
385 } 402 }
386 403
387 /* Allow the user to see what's happening */ 404 /* Allow the user to see what's happening */
388 //SDL_Delay (40); 405 //SDL_Delay (40);
406#endif
389 407
390 /* Check if there's a pending event. */ 408 /* Check if there's a pending event. */
391 while (SDL_PollEvent (&event)) 409 while (SDL_PollEvent (&event))
392 done = HandleEvent (&event); 410 done = HandleEvent (&event);
393 411
394 412
395 ++frames; 413 ++frames;
396 }
397
398 /* Print out the frames per second */
399 this_time = SDL_GetTicks ();
400 if (this_time != start_time)
401 {
402 printf ("%2.2f FPS\n",
403 ((float) frames / (this_time - start_time)) * 1000.0);
404 } 414 }
405 415
406 if (global_image) 416 if (global_image)
407 { 417 {
408 SDL_FreeSurface (global_image); 418 SDL_FreeSurface (global_image);
427 int slowly; 437 int slowly;
428 float gamma = 0.0; 438 float gamma = 0.0;
429 int noframe = 0; 439 int noframe = 0;
430 int fsaa = 0; 440 int fsaa = 0;
431 441
442 shader::debdebdebdebug ();//D
443
432 logo = 0; 444 logo = 0;
433 slowly = 0; 445 slowly = 0;
434 numtests = 1; 446 numtests = 1;
435 for (i = 1; argv[i]; ++i) 447 for (i = 1; argv[i]; ++i)
436 { 448 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines