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

Comparing libgender/test.C (file contents):
Revision 1.39 by root, Wed Oct 6 09:41:48 2004 UTC vs.
Revision 1.105 by root, Mon Jul 18 01:40:01 2005 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#include <list>
6
7#include "opengl.h"
5 8
6#include "SDL.h" 9#include "SDL.h"
7#include "SDL_opengl.h" 10#include "SDL_opengl.h"
8 11
9static SDL_Surface *global_image = NULL; 12static SDL_Surface *global_image = NULL;
10static GLuint global_texture = 0; 13static GLuint global_texture = 0;
11 14
12#include "util.h" 15#include "util.h"
13#include "entity.h" 16#include "entity.h"
14#include "txtprt_import.h" 17#include "txtprt_import.h"
18#include "randlvl.h"
15 19
16CGcontext cgc; 20bool doom3parse (const char *f);
17CGprogram vsh, fsh;
18CGparameter mv, mvp, lightpos;
19CGprofile vsh_profile, fsh_profile;
20 21
21static void CheckCgError(void) 22#include "shader.h"
22{
23 CGerror err = cgGetError();
24
25 if (err != CG_NO_ERROR)
26 {
27 printf("CG error: %s\n", cgGetErrorString(err));
28 exit(1);
29 }
30}
31 23
32/**********************************************************************/ 24/**********************************************************************/
33 25
34view camera; 26view camera;
35vec3 camera_velocity; 27vec3 camera_velocity;
36float camera_angle = 0, camera_velocity_angle; 28float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2;
37float camera_velocity_factor = 20; 29float camera_velocity_factor = 80;
38 30
39void 31void
40HotKey_ToggleFullScreen (void) 32HotKey_ToggleFullScreen (void)
41{ 33{
42 SDL_Surface *screen; 34 SDL_Surface *screen;
43 35
44 screen = SDL_GetVideoSurface (); 36 screen = SDL_GetVideoSurface ();
37
45 if (SDL_WM_ToggleFullScreen (screen)) 38 if (SDL_WM_ToggleFullScreen (screen))
46 printf ("Toggled fullscreen mode - now %s\n", 39 printf ("Toggled fullscreen mode - now %s\n",
47 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); 40 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
48 else 41 else
49 printf ("Unable to toggle fullscreen mode\n"); 42 printf ("Unable to toggle fullscreen mode\n");
54{ 47{
55 SDL_GrabMode mode; 48 SDL_GrabMode mode;
56 49
57 printf ("Ctrl-G: toggling input grab!\n"); 50 printf ("Ctrl-G: toggling input grab!\n");
58 mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); 51 mode = SDL_WM_GrabInput (SDL_GRAB_QUERY);
52
59 if (mode == SDL_GRAB_ON) 53 if (mode == SDL_GRAB_ON)
60 printf ("Grab was on\n"); 54 printf ("Grab was on\n");
61 else 55 else
62 printf ("Grab was off\n"); 56 printf ("Grab was off\n");
63 57
64 mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); 58 mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
59
65 if (mode == SDL_GRAB_ON) 60 if (mode == SDL_GRAB_ON)
66 printf ("Grab is now on\n"); 61 printf ("Grab is now on\n");
67 else 62 else
68 printf ("Grab is now off\n"); 63 printf ("Grab is now off\n");
69} 64}
79HandleEvent (SDL_Event * event) 74HandleEvent (SDL_Event * event)
80{ 75{
81 int done; 76 int done;
82 77
83 done = 0; 78 done = 0;
79
84 switch (event->type) 80 switch (event->type)
85 { 81 {
86 case SDL_ACTIVEEVENT: 82 case SDL_ACTIVEEVENT:
87 /* See what happened */ 83 /* See what happened */
88 printf ("app %s ", event->active.gain ? "gained" : "lost"); 84 printf ("app %s ", event->active.gain ? "gained" : "lost");
89 if (event->active.state & SDL_APPACTIVE) 85 if (event->active.state & SDL_APPACTIVE)
90 {
91 printf ("active "); 86 printf ("active ");
92 }
93 else if (event->active.state & SDL_APPMOUSEFOCUS) 87 else if (event->active.state & SDL_APPMOUSEFOCUS)
94 {
95 printf ("mouse "); 88 printf ("mouse ");
96 }
97 else if (event->active.state & SDL_APPINPUTFOCUS) 89 else if (event->active.state & SDL_APPINPUTFOCUS)
98 {
99 printf ("input "); 90 printf ("input ");
100 }
101 91
102 printf ("focus\n"); 92 printf ("focus\n");
103 break; 93 break;
104 94
105 case SDL_KEYDOWN: 95 case SDL_KEYDOWN:
106 if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; 96 if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--;
107 if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; 97 if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++;
108 if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x--;
109 if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x++; 98 if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle++;
99 if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle--;
100 if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2++;
101 if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2--;
110 if (event->key.keysym.sym == SDLK_a) camera_velocity.y--; 102 if (event->key.keysym.sym == SDLK_e) camera_velocity.y--;
111 if (event->key.keysym.sym == SDLK_s) camera_velocity.y++; 103 if (event->key.keysym.sym == SDLK_q) camera_velocity.y++;
112 if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; 104 if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5;
113 if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; 105 if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5;
114 if (event->key.keysym.sym == SDLK_e) camera_velocity_angle++;
115 if (event->key.keysym.sym == SDLK_q) camera_velocity_angle--;
116 106
117 if (event->key.keysym.sym == SDLK_ESCAPE) 107 if (event->key.keysym.sym == SDLK_ESCAPE)
118 done = 1; 108 done = 1;
119 109
120 if ((event->key.keysym.sym == SDLK_g) && 110 if ((event->key.keysym.sym == SDLK_g) &&
132 break; 122 break;
133 123
134 case SDL_KEYUP: 124 case SDL_KEYUP:
135 if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; 125 if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++;
136 if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; 126 if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--;
137 if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x++; 127 if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle++;
138 if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x--; 128 if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle--;
129 if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2--;
130 if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2++;
139 if (event->key.keysym.sym == SDLK_a) camera_velocity.y++; 131 if (event->key.keysym.sym == SDLK_e) camera_velocity.y++;
140 if (event->key.keysym.sym == SDLK_s) camera_velocity.y--; 132 if (event->key.keysym.sym == SDLK_q) camera_velocity.y--;
141 if (event->key.keysym.sym == SDLK_e) camera_velocity_angle--;
142 if (event->key.keysym.sym == SDLK_q) camera_velocity_angle++;
143 break; 133 break;
144 134
145 case SDL_QUIT: 135 case SDL_QUIT:
146 done = 1; 136 done = 1;
147 break; 137 break;
148 } 138 }
149 139
150 return (done); 140 return (done);
141}
142
143void draw_floor (int size, int dx, int dy, int dz)
144{
145 int x, z, ry;
146
147 for (x = 0; x < 10; x++)
148 {
149 for (z = 0; z < 10; z++)
150 {
151 vector<vertex_t2f_n3f_v3f> pts;
152 pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, 0), vec3 (0, 1, 0), tex2 (0, 0)));
153 pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1)));
154 pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1)));
155 pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0)));
156
157 geometry_quads *q = new geometry_quads;
158 //q->m = new simple_material;
159 q->set (pts);
160 entity *e = new entity (q);
161 e->move (vec3 (dx + x * size, dy, dz + z * size));
162 e->show ();
163 }
164 }
165}
166
167void draw_test_nurb ()
168{
169 geometry_nurbs *q = new geometry_nurbs;
170 q->set ();
171 entity *e = new entity (q);
172 e->move (vec3 (10, 3, -4));
173 e->show ();
174}
175
176void fisch (vec3 center, GLfloat radius, int depth)
177{
178 entity *planet = new entity (new geometry_sphere (testmat, radius));
179 planet->move (center);
180 planet->show ();
181
182 if (--depth)
183 {
184 GLfloat r2 = radius * .1F;
185 GLfloat r3 = radius + r2;
186
187 fisch (center + vec3 (r3, 0, 0), r2, depth);
188 fisch (center + vec3 (0, 0, r3), r2, depth);
189 fisch (center + vec3 (-r3, 0, 0), r2, depth);
190 }
191}
192
193extern void draw_level ();
194
195std::list<entity_moveable *> moveables;
196
197void perfom_moves ()
198{
199 for (std::list<entity_moveable *>::iterator i = moveables.begin (); i != moveables.end (); ++i)
200 {
201 (*i)->perform_step (timer.diff);
202 }
151} 203}
152 204
153int 205int
154RunGLTest (int argc, char *argv[], 206RunGLTest (int argc, char *argv[],
155 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) 207 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa)
158 int rgb_size[3]; 210 int rgb_size[3];
159 int w = 640; 211 int w = 640;
160 int h = 480; 212 int h = 480;
161 int done = 0; 213 int done = 0;
162 int frames; 214 int frames;
163 Uint32 start_time, this_time;
164 Uint32 video_flags; 215 Uint32 video_flags;
165 int value; 216 int value;
217 GLenum gl_error;
166 218
167 if (SDL_Init (SDL_INIT_VIDEO) < 0) 219 if (SDL_Init (SDL_INIT_VIDEO) < 0)
168 { 220 {
169 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 221 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
170 exit (1); 222 exit (1);
212 } 264 }
213 265
214 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); 266 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]);
215 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); 267 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]);
216 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); 268 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]);
269 SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 0);
217 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); 270 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
218 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 271 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
219 272
220 if (fsaa) 273 if (fsaa)
221 { 274 {
222 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); 275 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
228 fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); 281 fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ());
229 SDL_Quit (); 282 SDL_Quit ();
230 exit (1); 283 exit (1);
231 } 284 }
232 285
233 printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); 286 //printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel);
234 printf ("\n"); 287 //printf ("\n");
235 printf ("Vendor : %s\n", glGetString (GL_VENDOR)); 288 //printf ("Vendor : %s\n", glGetString (GL_VENDOR));
236 printf ("Renderer : %s\n", glGetString (GL_RENDERER)); 289 //printf ("Renderer : %s\n", glGetString (GL_RENDERER));
237 printf ("Version : %s\n", glGetString (GL_VERSION)); 290 //printf ("Version : %s\n", glGetString (GL_VERSION));
238 printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); 291 //printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS));
239 printf ("\n"); 292 printf ("\n");
240 293
241 SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); 294 SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value);
242 printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); 295 printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value);
243 SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); 296 SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value);
244 printf ("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value); 297 printf ("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value);
245 SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value); 298 SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value);
246 printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value); 299 printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value);
300 SDL_GL_GetAttribute (SDL_GL_ALPHA_SIZE, &value);
301 printf ("SDL_GL_ALPHA_SIZE: requested ?, got %d\n", value);
247 SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); 302 SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value);
248 printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value); 303 printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value);
249 SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); 304 SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value);
250 printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); 305 printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
251 306
263 318
264 /* Set the gamma for the window */ 319 /* Set the gamma for the window */
265 if (gamma != 0.0) 320 if (gamma != 0.0)
266 SDL_SetGamma (gamma, gamma, gamma); 321 SDL_SetGamma (gamma, gamma, gamma);
267 322
268 // load a entity 323 testmat = new test_material;
324 testmat2 = new mat_gouraud_shaded (colour (1, 1, 0));
325 testmat3 = new mat_timed ();
326 debugmat = new mat_debug ();
327
328 entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat2, 10));
329 planet->move (vec3 (0, 0, -20));
330 planet->show ();
331
332 planet->v = vec3 (10, 0, 0);
333 moveables.push_back (planet);
334
335 doom3parse ("test.proc");
336
269 for (int i = 0; i < 7; i++) 337 for (int i = 0; i < 20; i++)
270 { 338 {
339 // load a entity
271 txtprt_parser p; 340 txtprt_parser p;
272 entity_transform *f = new entity_transform; 341 geometry *g;
273 entity *e;
274 try 342 try
275 { 343 {
276 e = p.read ("test.blasc"); 344 g = p.read ("test.blasc");
345 }
277 } catch (txtprt_i_exception & e) 346 catch (txtprt_i_exception & e)
278 { 347 {
279 cout << "ERR: " << e.msg << endl; 348 cout << "ERR: " << e.msg << endl;
280 } 349 }
281 f->set (e); 350
282 f->update (matrix::translation (vec3 (0, -1, -i*5))); 351 entity *e = new entity (g);
352 e->move (vec3 (i*5, -3, -i*10));
283 f->show (); 353 e->show ();
354 }
355
356 {
357 fisch (vec3 (0, 0, -2e9), 1e9, 8);
358 //entity *planet = new entity (new geometry_sphere (1e9));
359 //planet->move (vec3 (0, 0, -1.5e9));
360 //planet->show ();
284 } 361 }
285 362
363 {
364 entity *planet = new entity (new geometry_sphere (testmat3, 4e15));
365 planet->move (vec3 (0, 0, 1e17));
366 planet->show ();
367 }
368
369 {
370 RandomBuilding r;
371 entity *randlvl = r.draw (1000, 1000, 200);
372 randlvl->move (vec3 (0, 0, 0));
373 randlvl->show ();
374
375 entity *randlvl2 = r.draw (1000, 10000, 1000);
376 randlvl2->move (vec3 (-20000, 0, 0));
377 randlvl2->show ();
378
379 entity *randlvl3 = r.draw (100, 30, 3);
380 randlvl3->move (vec3 (-1000, 0, 0));
381 randlvl3->show ();
382
383
384 entity *randlvl4 = r.draw (100, 1000000, 100000);
385 randlvl4->move (vec3 (0, -1001000, 0));
386 randlvl4->show ();
387 }
388
389 //draw_floor (10, -500, -10, -1000);
390 draw_level ();
391
392#if 0
393 {
394 geometry_heightfield *hf = new geometry_heightfield (100000., 100000.);
395 entity *e = new entity (hf);
396 e->move (vec3 (-100000, -100000 * 0.01, -100000));
397 e->show ();
398 }
399#endif
400
401 //draw_test_nurb ();
402
403 //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368;
286 camera.orig.x = camera.orig.y = camera.orig.z = 0; 404 camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0;
287 camera.p = point (0, 0, 10); 405 camera.p = point (0, 0, 10);
288 camera.d = vec3 (0, 0, -1); 406 camera.d = vec3 (0, 0, -1);
289 camera.u = vec3 (0, 1, 0); 407 camera.u = vec3 (0, 1, 0);
290 camera.w = w; camera.h = h; 408 camera.w = w; camera.h = h;
291 camera.fov = 80; 409 camera.fov = 40.;
292 410
293 glMatrixMode (GL_MODELVIEW);
294 glLoadIdentity ();
295
296 //glEnable (GL_CULL_FACE);
297 glEnable (GL_DEPTH_TEST); 411 glDisable (GL_ALPHA_TEST);
298 glEnable (GL_TEXTURE_2D); //texturing
299
300 glShadeModel (GL_SMOOTH);
301
302 glEnable (GL_LIGHTING);
303 //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 };
304 //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION);
305 //glLightfv (GL_LIGHT0, GL_DIFFUSE, lightc);
306 glEnable (GL_LIGHT0);
307
308 cgc = cgCreateContext ();
309
310 vsh_profile = CG_PROFILE_ARBVP1;
311 //if (cgGLIsProfileSupported (CG_PROFILE_VP30)) vsh_profile = CG_PROFILE_VP30;
312 //if (cgGLIsProfileSupported (CG_PROFILE_VP40)) vsh_profile = CG_PROFILE_VP40;
313 fsh_profile = CG_PROFILE_ARBFP1;
314 //if (cgGLIsProfileSupported (CG_PROFILE_FP30)) fsh_profile = CG_PROFILE_FP30;
315 //if (cgGLIsProfileSupported (CG_PROFILE_FP40)) fsh_profile = CG_PROFILE_FP40;
316
317 vsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "vsh.cg", vsh_profile, 0, 0);
318 CheckCgError ();
319 cgGLLoadProgram (vsh);
320 CheckCgError ();
321 mv = cgGetNamedParameter (vsh, "WorldProj");
322 mvp = cgGetNamedParameter (vsh, "WorldViewProj");
323 lightpos = cgGetNamedParameter (vsh, "LightPos");
324 CheckCgError ();
325
326 CGparameter g_Texture; // the texture parameter
327
328
329 fsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "fsh.cg", fsh_profile, 0, 0);
330 Texture t("o.jpg");
331 g_Texture = cgGetNamedParameter(fsh, "Texture"); // the texture cg-warper ;)
332 cgGLSetTextureParameter(g_Texture, t.texture); // Bind the texture number 999 to g_Texture
333 CheckCgError ();
334 cgGLLoadProgram (fsh);
335 CheckCgError ();
336
337 cgGLBindProgram (vsh);
338 CheckCgError ();
339 cgGLBindProgram (fsh);
340 CheckCgError ();
341 412
342 /* Loop until done. */ 413 /* Loop until done. */
343 start_time = SDL_GetTicks ();
344 frames = 0; 414 frames = 0;
345 415
416 linear_light mylight2;//mylight, mylight2;
417
418 // mylight.radius = 100000;
419 // mylight.c = colour (1., 1, 1, 1.);
420 // mylight.intensity = 1.F;
421
422 mylight2.radius = 100000;
423 mylight2.c = colour (0., 1., 1., 1.);
424 mylight2.intensity = 1.F;
425 mylight2.orig.x = 0; mylight2.orig.y = 0; mylight2.orig.z = 0;
426 mylight2.p.x = 0; mylight2.p.y = 0; mylight2.p.z = 0;
427
428 //pass_data pass_light (&mylight);
429 pass_data pass_light2 (&mylight2);
346 430
347 while (!done) 431 while (!done)
348 { 432 {
349 GLenum gl_error;
350 char *sdl_error; 433 char *sdl_error;
351 SDL_Event event; 434 SDL_Event event;
352 435
353 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
354
355 camera.p.x += camera_velocity_factor * camera_velocity.x * timer.diff;
356 camera.p.y += camera_velocity_factor * camera_velocity.y * timer.diff;
357 camera.p.z += camera_velocity_factor * camera_velocity.z * timer.diff;
358
359 camera_angle += camera_velocity_factor * camera_velocity_angle * timer.diff; 436 camera_angle += 90 * camera_velocity_angle * timer.diff;
360 camera.d.z = -cos (camera_angle * 12 / 180.); 437 camera_angle2 += 90 * camera_velocity_angle2 * timer.diff;
361 camera.d.x = sin (camera_angle * 12 / 180.);
362 438
363 cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); 439 vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1);
440 vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus;
364 441
365 glBindTexture (GL_TEXTURE_2D, t.texture); 442 camera.d = matrix::rotation (camera_angle2, right) * geradeaus;
366 cgGLEnableTextureParameter(g_Texture); // Enable the texture parameter 443 camera.u = cross (camera.d, right);
367 444
368#if 0 445 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z;
369 static GLfloat ry; 446 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y;
370 ry += 0.001;
371 camera.d.x = cos (ry);
372 camera.d.z = sin (ry);
373 //camera.d.y = sin (ry * 0.1);
374#endif
375 447
448 //mylight.orig = camera.orig;
449 //mylight.p = camera.p;
450
451 mylight2.orig = camera.orig;
452 //mylight2.p = vec3 (sin (timer.now / 2) * 100000, 1, cos (timer.now / 2) * 100000);
453
454 //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F);
455
376 camera.begin (); 456 camera.begin ();
377 camera.pass (view::DEPTH); 457 camera.render (pass_depth);
378 camera.pass (view::LIGHTED); 458 camera.render (pass_postdepth);
459 camera.render (pass_light2);
460 //camera.render (view::LIGHTED, pass_light2);
379 camera.end (); 461 camera.end ();
462
463 perfom_moves ();
380 464
381 SDL_GL_SwapBuffers (); 465 SDL_GL_SwapBuffers ();
382 timer.frame (); 466 timer.frame ();
383 467
468#if 0
384 /* Check for error conditions. */ 469 /* Check for error conditions. */
385 gl_error = glGetError (); 470 gl_error = glGetError ();
386 471
387 if (gl_error != GL_NO_ERROR)
388 fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); 472 if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error);
389 473
390 sdl_error = SDL_GetError (); 474 sdl_error = SDL_GetError ();
391 475
392 if (sdl_error[0] != '\0') 476 if (sdl_error[0] != '\0')
393 { 477 {
394 fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); 478 fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error);
395 SDL_ClearError (); 479 SDL_ClearError ();
396 } 480 }
397 481
398 /* Allow the user to see what's happening */ 482 /* Allow the user to see what's happening */
399 //SDL_Delay (20); 483 //SDL_Delay (40);
484#endif
400 485
401 /* Check if there's a pending event. */ 486 /* Check if there's a pending event. */
402 while (SDL_PollEvent (&event)) 487 while (SDL_PollEvent (&event))
403 done = HandleEvent (&event); 488 done = HandleEvent (&event);
404 489
405
406 ++frames; 490 ++frames;
407 }
408
409 /* Print out the frames per second */
410 this_time = SDL_GetTicks ();
411 if (this_time != start_time)
412 {
413 printf ("%2.2f FPS\n",
414 ((float) frames / (this_time - start_time)) * 1000.0);
415 } 491 }
416 492
417 if (global_image) 493 if (global_image)
418 { 494 {
419 SDL_FreeSurface (global_image); 495 SDL_FreeSurface (global_image);
420 global_image = NULL; 496 global_image = NULL;
421 } 497 }
498
422 if (global_texture) 499 if (global_texture)
423 { 500 {
424 glDeleteTextures (1, &global_texture); 501 glDeleteTextures (1, &global_texture);
425 global_texture = 0; 502 global_texture = 0;
426 } 503 }
427 504
428 /* Destroy our GL context, etc. */ 505 /* Destroy our GL context, etc. */
429 SDL_Quit (); 506 SDL_Quit ();
430 return (0); 507 return (0);
431} 508}
432
433int 509int
434main (int argc, char *argv[]) 510main (int argc, char *argv[])
435{ 511{
436 int i, logo; 512 int i, logo;
437 int numtests; 513 int numtests;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines