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> |
5 | |
6 | |
6 | #include "opengl.h" |
7 | #include "opengl.h" |
7 | |
8 | |
8 | #include "SDL.h" |
9 | #include "SDL.h" |
9 | #include "SDL_opengl.h" |
10 | #include "SDL_opengl.h" |
… | |
… | |
12 | static GLuint global_texture = 0; |
13 | static GLuint global_texture = 0; |
13 | |
14 | |
14 | #include "util.h" |
15 | #include "util.h" |
15 | #include "entity.h" |
16 | #include "entity.h" |
16 | #include "txtprt_import.h" |
17 | #include "txtprt_import.h" |
|
|
18 | #include "randlvl.h" |
|
|
19 | |
|
|
20 | bool doom3parse (const char *f); |
17 | |
21 | |
18 | #include "shader.h" |
22 | #include "shader.h" |
19 | |
23 | |
20 | /**********************************************************************/ |
24 | /**********************************************************************/ |
21 | |
25 | |
… | |
… | |
185 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
189 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
186 | } |
190 | } |
187 | } |
191 | } |
188 | |
192 | |
189 | extern void draw_level (); |
193 | extern void draw_level (); |
|
|
194 | |
|
|
195 | std::list<entity_moveable *> moveables; |
|
|
196 | |
|
|
197 | void 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 | } |
|
|
203 | } |
|
|
204 | |
190 | int |
205 | int |
191 | RunGLTest (int argc, char *argv[], |
206 | RunGLTest (int argc, char *argv[], |
192 | 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) |
193 | { |
208 | { |
194 | int i; |
209 | int i; |
195 | int rgb_size[3]; |
210 | int rgb_size[3]; |
196 | int w = 640; |
211 | int w = 800; |
197 | int h = 480; |
212 | int h = 600; |
198 | int done = 0; |
213 | int done = 0; |
199 | int frames; |
214 | int frames; |
200 | Uint32 video_flags; |
215 | Uint32 video_flags; |
201 | int value; |
216 | int value; |
202 | GLenum gl_error; |
217 | GLenum gl_error; |
203 | |
218 | |
204 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
219 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
205 | { |
220 | { |
206 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
221 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
207 | exit (1); |
222 | exit (1); |
… | |
… | |
249 | } |
264 | } |
250 | |
265 | |
251 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
266 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
252 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
267 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
253 | 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); |
254 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
270 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
255 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
271 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
256 | |
272 | |
257 | if (fsaa) |
273 | if (fsaa) |
258 | { |
274 | { |
… | |
… | |
279 | 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); |
280 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
296 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
281 | 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); |
282 | SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value); |
298 | SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value); |
283 | 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); |
284 | SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); |
302 | SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); |
285 | 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); |
286 | SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); |
304 | SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); |
287 | printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); |
305 | printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); |
288 | |
306 | |
… | |
… | |
301 | /* Set the gamma for the window */ |
319 | /* Set the gamma for the window */ |
302 | if (gamma != 0.0) |
320 | if (gamma != 0.0) |
303 | SDL_SetGamma (gamma, gamma, gamma); |
321 | SDL_SetGamma (gamma, gamma, gamma); |
304 | |
322 | |
305 | testmat = new test_material; |
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 (); |
306 | |
327 | |
307 | #if 0 |
328 | #if 0 |
308 | entity *planet = new entity (new geometry_sphere (10)); |
329 | entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat2, 10)); |
309 | planet->move (vec3 (0, 0, -20)); |
330 | planet->move (vec3 (0, 0, -20)); |
310 | planet->show (); |
331 | planet->show (); |
|
|
332 | |
|
|
333 | planet->v = vec3 (10, 0, 0); |
|
|
334 | moveables.push_back (planet); |
311 | #endif |
335 | #endif |
312 | |
336 | |
|
|
337 | doom3parse ("test.proc"); |
|
|
338 | |
|
|
339 | skybox sb ( |
|
|
340 | "textures/skybox_mystery/1.jpg", |
|
|
341 | "textures/skybox_mystery/2.jpg", |
|
|
342 | "textures/skybox_mystery/3.jpg", |
|
|
343 | "textures/skybox_mystery/4.jpg", |
|
|
344 | "textures/skybox_mystery/5.jpg", |
|
|
345 | "textures/skybox_mystery/6.jpg" |
|
|
346 | ); |
|
|
347 | world_skybox = &sb; |
|
|
348 | |
313 | for (int i = 0; i < 20; i++) |
349 | for (int i = 0; i <= 0; i++) |
314 | { |
350 | { |
315 | // load a entity |
351 | // load a entity |
316 | txtprt_parser p; |
352 | txtprt_parser p; |
317 | geometry *g; |
353 | geometry *g; |
318 | try |
354 | try |
… | |
… | |
327 | entity *e = new entity (g); |
363 | entity *e = new entity (g); |
328 | e->move (vec3 (i*5, -3, -i*10)); |
364 | e->move (vec3 (i*5, -3, -i*10)); |
329 | e->show (); |
365 | e->show (); |
330 | } |
366 | } |
331 | |
367 | |
|
|
368 | #if 0 |
332 | { |
369 | { |
333 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
370 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
334 | //entity *planet = new entity (new geometry_sphere (1e9)); |
371 | //entity *planet = new entity (new geometry_sphere (1e9)); |
335 | //planet->move (vec3 (0, 0, -1.5e9)); |
372 | //planet->move (vec3 (0, 0, -1.5e9)); |
336 | //planet->show (); |
373 | //planet->show (); |
337 | } |
374 | } |
338 | |
375 | |
339 | { |
376 | { |
340 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
377 | entity *planet = new entity (new geometry_sphere (testmat3, 4e15)); |
341 | planet->move (vec3 (0, 0, 1e17)); |
378 | planet->move (vec3 (0, 0, 1e17)); |
342 | planet->show (); |
379 | planet->show (); |
343 | } |
380 | } |
|
|
381 | |
|
|
382 | { |
|
|
383 | RandomBuilding r; |
|
|
384 | entity *randlvl = r.draw (1000, 1000, 200); |
|
|
385 | randlvl->move (vec3 (0, 0, 0)); |
|
|
386 | randlvl->show (); |
|
|
387 | |
|
|
388 | entity *randlvl2 = r.draw (1000, 10000, 1000); |
|
|
389 | randlvl2->move (vec3 (-20000, 0, 0)); |
|
|
390 | randlvl2->show (); |
|
|
391 | |
|
|
392 | entity *randlvl3 = r.draw (100, 30, 3); |
|
|
393 | randlvl3->move (vec3 (-1000, 0, 0)); |
|
|
394 | randlvl3->show (); |
|
|
395 | |
|
|
396 | |
|
|
397 | entity *randlvl4 = r.draw (100, 1000000, 100000); |
|
|
398 | randlvl4->move (vec3 (0, -1001000, 0)); |
|
|
399 | randlvl4->show (); |
|
|
400 | } |
344 | |
401 | |
345 | //draw_floor (10, -500, -10, -1000); |
402 | //draw_floor (10, -500, -10, -1000); |
|
|
403 | #endif |
346 | draw_level (); |
404 | draw_level (); |
347 | |
|
|
348 | |
405 | |
349 | #if 0 |
406 | #if 0 |
350 | { |
407 | { |
351 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
408 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
352 | entity *e = new entity (hf); |
409 | entity *e = new entity (hf); |
353 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
410 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
354 | e->show (); |
411 | e->show (); |
355 | } |
412 | } |
|
|
413 | #endif |
356 | |
414 | |
357 | //draw_test_nurb (); |
415 | //draw_test_nurb (); |
358 | #endif |
|
|
359 | |
416 | |
360 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
417 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
361 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
418 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
362 | camera.p = point (0, 0, 10); |
419 | camera.p = point (0, 0, 10); |
363 | camera.d = vec3 (0, 0, -1); |
420 | camera.d = vec3 (0, 0, -1); |
364 | camera.u = vec3 (0, 1, 0); |
421 | camera.u = vec3 (0, 1, 0); |
365 | camera.w = w; camera.h = h; |
422 | camera.w = w; camera.h = h; |
366 | camera.fov = 40.; |
423 | camera.fov = 40.; |
367 | |
424 | |
368 | glEnable (GL_CULL_FACE); |
|
|
369 | glDisable (GL_ALPHA_TEST); |
425 | glDisable (GL_ALPHA_TEST); |
370 | glDisable (GL_BLEND); |
|
|
371 | |
426 | |
372 | /* Loop until done. */ |
427 | /* Loop until done. */ |
373 | frames = 0; |
428 | frames = 0; |
374 | |
429 | |
375 | linear_light mylight; |
430 | linear_light mylight2;//mylight, mylight2; |
|
|
431 | |
|
|
432 | // mylight.radius = 100000; |
|
|
433 | // mylight.c = colour (1., 1, 1, 1.); |
|
|
434 | // mylight.intensity = 1.F; |
|
|
435 | |
376 | mylight.radius = 100000; |
436 | mylight2.radius = 100000; |
377 | mylight.c = colour (1., 1, 1, 1.); |
437 | mylight2.c = colour (0., 1., 1., 1.); |
378 | mylight.intensity = 1.F; |
438 | mylight2.intensity = 1.F; |
|
|
439 | mylight2.orig.x = 0; mylight2.orig.y = 0; mylight2.orig.z = 0; |
|
|
440 | mylight2.p.x = 0; mylight2.p.y = 0; mylight2.p.z = 0; |
379 | |
441 | |
380 | pass pass_light (&mylight); |
442 | //pass_data pass_light (&mylight); |
|
|
443 | pass_data pass_light2 (&mylight2); |
381 | |
444 | |
382 | while (!done) |
445 | while (!done) |
383 | { |
446 | { |
384 | char *sdl_error; |
447 | char *sdl_error; |
385 | SDL_Event event; |
448 | SDL_Event event; |
386 | |
449 | |
387 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
450 | camera_angle += 90 * camera_velocity_angle * timer.diff; |
388 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
451 | camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
389 | |
452 | |
390 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
453 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
391 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
454 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
392 | |
455 | |
393 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
456 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
394 | camera.u = cross (camera.d, right); |
457 | camera.u = cross (camera.d, right); |
395 | |
458 | |
396 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
459 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
397 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
460 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
398 | |
461 | |
|
|
462 | //mylight.orig = camera.orig; |
|
|
463 | //mylight.p = camera.p; |
|
|
464 | |
399 | mylight.orig = camera.orig; |
465 | mylight2.orig = camera.orig; |
400 | mylight.p = camera.p; |
466 | //mylight2.p = vec3 (sin (timer.now / 2) * 100000, 1, cos (timer.now / 2) * 100000); |
401 | |
467 | |
402 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
468 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
403 | |
469 | |
404 | camera.begin (); |
470 | camera.begin (); |
405 | camera.render (view::DEPTH, pass_depth); |
471 | camera.render (pass_depth); |
406 | camera.render (view::POSTDEPTH, pass_depth); |
472 | camera.render (pass_postdepth); |
|
|
473 | camera.render (pass_light2); |
407 | camera.render (view::LIGHTED, pass_light); |
474 | //camera.render (view::LIGHTED, pass_light2); |
408 | camera.end (); |
475 | camera.end (); |
|
|
476 | |
|
|
477 | perfom_moves (); |
409 | |
478 | |
410 | SDL_GL_SwapBuffers (); |
479 | SDL_GL_SwapBuffers (); |
411 | timer.frame (); |
480 | timer.frame (); |
412 | |
481 | |
413 | #if 0 |
482 | #if 0 |