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" |
17 | |
19 | |
18 | bool doom3parse (const char *f); |
20 | bool doom3parse (const char *f); |
19 | |
21 | |
20 | #include "shader.h" |
22 | #include "shader.h" |
21 | |
23 | |
… | |
… | |
187 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
189 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
188 | } |
190 | } |
189 | } |
191 | } |
190 | |
192 | |
191 | 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 | |
192 | int |
205 | int |
193 | RunGLTest (int argc, char *argv[], |
206 | RunGLTest (int argc, char *argv[], |
194 | 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) |
195 | { |
208 | { |
196 | int i; |
209 | int i; |
… | |
… | |
303 | /* Set the gamma for the window */ |
316 | /* Set the gamma for the window */ |
304 | if (gamma != 0.0) |
317 | if (gamma != 0.0) |
305 | SDL_SetGamma (gamma, gamma, gamma); |
318 | SDL_SetGamma (gamma, gamma, gamma); |
306 | |
319 | |
307 | testmat = new test_material; |
320 | testmat = new test_material; |
|
|
321 | testmat2 = new mat_gouraud_shaded (colour (1, 0, 0)); |
308 | |
322 | |
309 | entity *planet = new entity (new geometry_sphere (testmat, 10)); |
323 | entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat, 10)); |
310 | planet->move (vec3 (0, 0, -20)); |
324 | planet->move (vec3 (0, 0, -20)); |
311 | planet->show (); |
325 | planet->show (); |
|
|
326 | |
|
|
327 | planet->v = vec3 (10, 0, 0); |
|
|
328 | moveables.push_back (planet); |
312 | |
329 | |
313 | doom3parse ("test.proc"); |
330 | doom3parse ("test.proc"); |
314 | |
331 | |
315 | for (int i = 0; i < 20; i++) |
332 | for (int i = 0; i < 20; i++) |
316 | { |
333 | { |
… | |
… | |
337 | //planet->move (vec3 (0, 0, -1.5e9)); |
354 | //planet->move (vec3 (0, 0, -1.5e9)); |
338 | //planet->show (); |
355 | //planet->show (); |
339 | } |
356 | } |
340 | |
357 | |
341 | { |
358 | { |
342 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
359 | entity *planet = new entity (new geometry_sphere (testmat2, 4e15)); |
343 | planet->move (vec3 (0, 0, 1e17)); |
360 | planet->move (vec3 (0, 0, 1e17)); |
344 | planet->show (); |
361 | planet->show (); |
|
|
362 | } |
|
|
363 | |
|
|
364 | { |
|
|
365 | RandomBuilding r; |
|
|
366 | entity *randlvl = r.draw (1000, 1000, 200); |
|
|
367 | randlvl->move (vec3 (0, 0, 0)); |
|
|
368 | randlvl->show (); |
|
|
369 | |
|
|
370 | entity *randlvl2 = r.draw (1000, 10000, 1000); |
|
|
371 | randlvl2->move (vec3 (-20000, 0, 0)); |
|
|
372 | randlvl2->show (); |
|
|
373 | |
|
|
374 | entity *randlvl3 = r.draw (100, 30, 3); |
|
|
375 | randlvl3->move (vec3 (-1000, 0, 0)); |
|
|
376 | randlvl3->show (); |
|
|
377 | |
|
|
378 | |
|
|
379 | entity *randlvl4 = r.draw (100, 1000000, 100000); |
|
|
380 | randlvl4->move (vec3 (0, -1001000, 0)); |
|
|
381 | randlvl4->show (); |
345 | } |
382 | } |
346 | |
383 | |
347 | //draw_floor (10, -500, -10, -1000); |
384 | //draw_floor (10, -500, -10, -1000); |
348 | draw_level (); |
385 | draw_level (); |
349 | |
386 | |
… | |
… | |
364 | camera.d = vec3 (0, 0, -1); |
401 | camera.d = vec3 (0, 0, -1); |
365 | camera.u = vec3 (0, 1, 0); |
402 | camera.u = vec3 (0, 1, 0); |
366 | camera.w = w; camera.h = h; |
403 | camera.w = w; camera.h = h; |
367 | camera.fov = 40.; |
404 | camera.fov = 40.; |
368 | |
405 | |
369 | glEnable (GL_CULL_FACE); |
|
|
370 | glDisable (GL_ALPHA_TEST); |
406 | glDisable (GL_ALPHA_TEST); |
371 | glDisable (GL_BLEND); |
|
|
372 | |
407 | |
373 | /* Loop until done. */ |
408 | /* Loop until done. */ |
374 | frames = 0; |
409 | frames = 0; |
375 | |
410 | |
376 | linear_light mylight; |
411 | linear_light mylight2;//mylight, mylight2; |
|
|
412 | |
|
|
413 | // mylight.radius = 100000; |
|
|
414 | // mylight.c = colour (1., 1, 1, 1.); |
|
|
415 | // mylight.intensity = 1.F; |
|
|
416 | |
377 | mylight.radius = 100000; |
417 | mylight2.radius = 100000; |
378 | mylight.c = colour (1., 1, 1, 1.); |
418 | mylight2.c = colour (1., 1., 1., 1.); |
379 | mylight.intensity = 1.F; |
419 | mylight2.intensity = 1.F; |
|
|
420 | mylight2.orig.x = 0; mylight2.orig.y = 0; mylight2.orig.z = 0; |
|
|
421 | mylight2.p.x = 0; mylight2.p.y = 0; mylight2.p.z = 0; |
380 | |
422 | |
381 | pass pass_light (&mylight); |
423 | //pass_data pass_light (&mylight); |
|
|
424 | pass_data pass_light2 (&mylight2); |
382 | |
425 | |
383 | while (!done) |
426 | while (!done) |
384 | { |
427 | { |
385 | char *sdl_error; |
428 | char *sdl_error; |
386 | SDL_Event event; |
429 | SDL_Event event; |
… | |
… | |
395 | camera.u = cross (camera.d, right); |
438 | camera.u = cross (camera.d, right); |
396 | |
439 | |
397 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
440 | 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; |
441 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
399 | |
442 | |
|
|
443 | //mylight.orig = camera.orig; |
|
|
444 | //mylight.p = camera.p; |
|
|
445 | |
400 | mylight.orig = camera.orig; |
446 | mylight2.orig = camera.orig; |
401 | mylight.p = camera.p; |
447 | mylight2.p = vec3 (sin (timer.now / 2) * 100000, 1, cos (timer.now / 2) * 100000); |
402 | |
448 | |
403 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
449 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
404 | |
450 | |
405 | camera.begin (); |
451 | camera.begin (); |
406 | camera.render (view::DEPTH, pass_depth); |
452 | camera.render (pass_depth); |
407 | camera.render (view::POSTDEPTH, pass_depth); |
453 | camera.render (pass_postdepth); |
|
|
454 | camera.render (pass_light2); |
408 | camera.render (view::LIGHTED, pass_light); |
455 | //camera.render (view::LIGHTED, pass_light2); |
409 | camera.end (); |
456 | camera.end (); |
|
|
457 | |
|
|
458 | perfom_moves (); |
410 | |
459 | |
411 | SDL_GL_SwapBuffers (); |
460 | SDL_GL_SwapBuffers (); |
412 | timer.frame (); |
461 | timer.frame (); |
413 | |
462 | |
414 | #if 0 |
463 | #if 0 |