… | |
… | |
16 | CGcontext cgc; |
16 | CGcontext cgc; |
17 | CGprogram vsh, fsh; |
17 | CGprogram vsh, fsh; |
18 | CGparameter mv, mvp, lightpos; |
18 | CGparameter mv, mvp, lightpos; |
19 | CGprofile vsh_profile, fsh_profile; |
19 | CGprofile vsh_profile, fsh_profile; |
20 | |
20 | |
21 | static void CheckCgError(void) |
21 | static void CheckCgError (void) |
22 | { |
22 | { |
23 | CGerror err = cgGetError(); |
23 | CGerror err = cgGetError (); |
24 | |
24 | |
25 | if (err != CG_NO_ERROR) |
25 | if (err != CG_NO_ERROR) |
26 | { |
26 | { |
27 | printf("CG error: %s\n", cgGetErrorString(err)); |
27 | printf("CG error: %s\n", cgGetErrorString (err)); |
28 | exit(1); |
28 | exit(1); |
29 | } |
29 | } |
30 | } |
30 | } |
31 | |
31 | |
32 | /**********************************************************************/ |
32 | /**********************************************************************/ |
33 | |
33 | |
34 | view camera; |
34 | view camera; |
35 | vec3 camera_velocity; |
35 | vec3 camera_velocity; |
36 | float camera_angle = 0, camera_velocity_angle; |
36 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
37 | float camera_velocity_factor = 20; |
37 | float camera_velocity_factor = 80; |
38 | |
38 | |
39 | void |
39 | void |
40 | HotKey_ToggleFullScreen (void) |
40 | HotKey_ToggleFullScreen (void) |
41 | { |
41 | { |
42 | SDL_Surface *screen; |
42 | SDL_Surface *screen; |
… | |
… | |
101 | |
101 | |
102 | printf ("focus\n"); |
102 | printf ("focus\n"); |
103 | break; |
103 | break; |
104 | |
104 | |
105 | case SDL_KEYDOWN: |
105 | case SDL_KEYDOWN: |
106 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
106 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
107 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
107 | 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++; |
108 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle++; |
|
|
109 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle--; |
|
|
110 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2++; |
|
|
111 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2--; |
110 | if (event->key.keysym.sym == SDLK_a) camera_velocity.y--; |
112 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y--; |
111 | if (event->key.keysym.sym == SDLK_s) camera_velocity.y++; |
113 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y++; |
112 | if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
114 | 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; |
115 | 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 | |
116 | |
117 | if (event->key.keysym.sym == SDLK_ESCAPE) |
117 | if (event->key.keysym.sym == SDLK_ESCAPE) |
118 | done = 1; |
118 | done = 1; |
119 | |
119 | |
120 | if ((event->key.keysym.sym == SDLK_g) && |
120 | if ((event->key.keysym.sym == SDLK_g) && |
… | |
… | |
132 | break; |
132 | break; |
133 | |
133 | |
134 | case SDL_KEYUP: |
134 | case SDL_KEYUP: |
135 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
135 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
136 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
136 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
137 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x++; |
137 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle++; |
138 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x--; |
138 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle--; |
|
|
139 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2--; |
|
|
140 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2++; |
139 | if (event->key.keysym.sym == SDLK_a) camera_velocity.y++; |
141 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y++; |
140 | if (event->key.keysym.sym == SDLK_s) camera_velocity.y--; |
142 | 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; |
143 | break; |
144 | |
144 | |
145 | case SDL_QUIT: |
145 | case SDL_QUIT: |
146 | done = 1; |
146 | done = 1; |
147 | break; |
147 | break; |
148 | } |
148 | } |
149 | |
149 | |
150 | return (done); |
150 | return (done); |
151 | } |
151 | } |
152 | |
152 | |
|
|
153 | void draw_floor (int size, int dx, int dy, int dz) |
|
|
154 | { |
|
|
155 | int x, z, ry; |
|
|
156 | |
|
|
157 | for (x = 0; x < 100; x++) |
|
|
158 | { |
|
|
159 | for (z = 0; z < 100; z++) |
|
|
160 | { |
|
|
161 | vector<vertex2d> pts; |
|
|
162 | pts.push_back (vertex2d (point ( 0, 0, 0), vec3 (0, 1, 0), texc (0, 0))); |
|
|
163 | pts.push_back (vertex2d (point ( 0, 0, size), vec3 (0, 1, 0), texc (0, 1))); |
|
|
164 | pts.push_back (vertex2d (point (size, 0, size), vec3 (0, 1, 0), texc (1, 1))); |
|
|
165 | pts.push_back (vertex2d (point (size, 0, 0), vec3 (0, 1, 0), texc (1, 0))); |
|
|
166 | |
|
|
167 | geometry_quads *q = new geometry_quads; |
|
|
168 | q->set (pts); |
|
|
169 | entity *e = new entity (q); |
|
|
170 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
|
|
171 | e->show (); |
|
|
172 | } |
|
|
173 | } |
|
|
174 | } |
|
|
175 | |
|
|
176 | void draw_test_nurb () |
|
|
177 | { |
|
|
178 | geometry_nurbs *q = new geometry_nurbs; |
|
|
179 | q->set (); |
|
|
180 | entity *e = new entity (q); |
|
|
181 | e->move (vec3 (10, 3, -4)); |
|
|
182 | e->show (); |
|
|
183 | } |
|
|
184 | |
|
|
185 | extern void draw_level (); |
153 | int |
186 | int |
154 | RunGLTest (int argc, char *argv[], |
187 | RunGLTest (int argc, char *argv[], |
155 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
188 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
156 | { |
189 | { |
157 | int i; |
190 | int i; |
… | |
… | |
161 | int done = 0; |
194 | int done = 0; |
162 | int frames; |
195 | int frames; |
163 | Uint32 start_time, this_time; |
196 | Uint32 start_time, this_time; |
164 | Uint32 video_flags; |
197 | Uint32 video_flags; |
165 | int value; |
198 | int value; |
|
|
199 | GLenum gl_error; |
166 | |
200 | |
167 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
201 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
168 | { |
202 | { |
169 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
203 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
170 | exit (1); |
204 | exit (1); |
… | |
… | |
263 | |
297 | |
264 | /* Set the gamma for the window */ |
298 | /* Set the gamma for the window */ |
265 | if (gamma != 0.0) |
299 | if (gamma != 0.0) |
266 | SDL_SetGamma (gamma, gamma, gamma); |
300 | SDL_SetGamma (gamma, gamma, gamma); |
267 | |
301 | |
268 | for (int i = 0; i < 70; i++) |
302 | for (int i = 0; i < 1; i++) |
269 | { |
303 | { |
270 | // load a entity |
304 | // load a entity |
271 | txtprt_parser p; |
305 | txtprt_parser p; |
272 | entity *e; |
306 | geometry *g; |
273 | try |
307 | try |
274 | { |
308 | { |
275 | e = p.read ("test.blasc"); |
309 | g = p.read ("test.blasc"); |
276 | } |
310 | } |
277 | catch (txtprt_i_exception & e) |
311 | catch (txtprt_i_exception & e) |
278 | { |
312 | { |
279 | cout << "ERR: " << e.msg << endl; |
313 | cout << "ERR: " << e.msg << endl; |
280 | } |
314 | } |
281 | |
315 | |
282 | entity_transform *f = new entity_transform; |
316 | entity *e = new entity (g); |
283 | f->set (e); |
317 | e->move (vec3 (i*5, -3, -i*10)); |
284 | f->update (matrix::translation (vec3 (i*5, -1, -i*10))); |
|
|
285 | f->show (); |
318 | e->show (); |
286 | } |
319 | } |
287 | |
320 | |
|
|
321 | //draw_floor (10, -500, -10, -1000); |
|
|
322 | draw_level (); |
|
|
323 | //draw_test_nurb (); |
|
|
324 | |
|
|
325 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
288 | camera.orig.x = camera.orig.y = camera.orig.z = 0; |
326 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
289 | camera.p = point (0, 0, 10); |
327 | camera.p = point (0, 0, 10); |
290 | camera.d = vec3 (0, 0, -1); |
328 | camera.d = vec3 (0, 0, -1); |
291 | camera.u = vec3 (0, 1, 0); |
329 | camera.u = vec3 (0, 1, 0); |
292 | camera.w = w; camera.h = h; |
330 | camera.w = w; camera.h = h; |
293 | camera.fov = 80; |
331 | camera.fov = 35; |
|
|
332 | camera.z_near = 1.; |
294 | |
333 | |
295 | glMatrixMode (GL_MODELVIEW); |
334 | glMatrixMode (GL_MODELVIEW); |
296 | glLoadIdentity (); |
335 | glLoadIdentity (); |
297 | |
336 | |
298 | glEnable (GL_CULL_FACE); |
337 | glEnable (GL_CULL_FACE); |
299 | glEnable (GL_DEPTH_TEST); |
338 | glEnable (GL_DEPTH_TEST); |
300 | |
339 | |
301 | glShadeModel (GL_SMOOTH); |
340 | glShadeModel (GL_SMOOTH); |
302 | |
341 | |
303 | glEnable (GL_LIGHTING); |
342 | glEnable (GL_LIGHTING); |
304 | //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 }; |
|
|
305 | //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION); |
|
|
306 | //glLightfv (GL_LIGHT0, GL_DIFFUSE, lightc); |
|
|
307 | glEnable (GL_LIGHT0); |
343 | glEnable (GL_LIGHT0); |
308 | |
344 | |
309 | cgc = cgCreateContext (); |
345 | cgc = cgCreateContext (); |
310 | |
346 | |
311 | vsh_profile = CG_PROFILE_ARBVP1; |
347 | vsh_profile = CG_PROFILE_ARBVP1; |
… | |
… | |
342 | |
378 | |
343 | /* Loop until done. */ |
379 | /* Loop until done. */ |
344 | start_time = SDL_GetTicks (); |
380 | start_time = SDL_GetTicks (); |
345 | frames = 0; |
381 | frames = 0; |
346 | |
382 | |
347 | |
|
|
348 | while (!done) |
383 | while (!done) |
349 | { |
384 | { |
350 | GLenum gl_error; |
|
|
351 | char *sdl_error; |
385 | char *sdl_error; |
352 | SDL_Event event; |
386 | SDL_Event event; |
353 | |
387 | |
354 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
355 | |
|
|
356 | camera.p.x += camera_velocity_factor * camera_velocity.x * timer.diff; |
|
|
357 | camera.p.y += camera_velocity_factor * camera_velocity.y * timer.diff; |
|
|
358 | camera.p.z += camera_velocity_factor * camera_velocity.z * timer.diff; |
|
|
359 | |
|
|
360 | camera_angle += camera_velocity_factor * camera_velocity_angle * timer.diff; |
388 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
361 | camera.d.z = -cos (camera_angle * 12 / 180.); |
389 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
362 | camera.d.x = sin (camera_angle * 12 / 180.); |
390 | |
|
|
391 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
|
|
392 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
|
|
393 | |
|
|
394 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
|
|
395 | camera.u = cross (camera.d, right); |
|
|
396 | |
|
|
397 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
|
|
398 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
363 | |
399 | |
364 | cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); |
400 | cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); |
365 | |
401 | |
366 | glBindTexture (GL_TEXTURE_2D, t.texture); |
402 | glBindTexture (GL_TEXTURE_2D, t.texture); |
367 | cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter |
403 | cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter |
… | |
… | |
383 | timer.frame (); |
419 | timer.frame (); |
384 | |
420 | |
385 | /* Check for error conditions. */ |
421 | /* Check for error conditions. */ |
386 | gl_error = glGetError (); |
422 | gl_error = glGetError (); |
387 | |
423 | |
388 | if (gl_error != GL_NO_ERROR) |
|
|
389 | fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
424 | if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
390 | |
425 | |
391 | sdl_error = SDL_GetError (); |
426 | sdl_error = SDL_GetError (); |
392 | |
427 | |
393 | if (sdl_error[0] != '\0') |
428 | if (sdl_error[0] != '\0') |
394 | { |
429 | { |
395 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
430 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
396 | SDL_ClearError (); |
431 | SDL_ClearError (); |
397 | } |
432 | } |
398 | |
433 | |
399 | /* Allow the user to see what's happening */ |
434 | /* Allow the user to see what's happening */ |
400 | //SDL_Delay (20); |
435 | //SDL_Delay (40); |
401 | |
436 | |
402 | /* Check if there's a pending event. */ |
437 | /* Check if there's a pending event. */ |
403 | while (SDL_PollEvent (&event)) |
438 | while (SDL_PollEvent (&event)) |
404 | done = HandleEvent (&event); |
439 | done = HandleEvent (&event); |
405 | |
440 | |
… | |
… | |
428 | |
463 | |
429 | /* Destroy our GL context, etc. */ |
464 | /* Destroy our GL context, etc. */ |
430 | SDL_Quit (); |
465 | SDL_Quit (); |
431 | return (0); |
466 | return (0); |
432 | } |
467 | } |
433 | |
|
|
434 | int |
468 | int |
435 | main (int argc, char *argv[]) |
469 | main (int argc, char *argv[]) |
436 | { |
470 | { |
437 | int i, logo; |
471 | int i, logo; |
438 | int numtests; |
472 | int numtests; |