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 | |
… | |
… | |
149 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
153 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
150 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
154 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
151 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
155 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
152 | |
156 | |
153 | geometry_quads *q = new geometry_quads; |
157 | geometry_quads *q = new geometry_quads; |
154 | q->m = new simple_material; |
158 | //q->m = new simple_material; |
155 | q->set (pts); |
159 | q->set (pts); |
156 | entity *e = new entity (q); |
160 | entity *e = new entity (q); |
157 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
161 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
158 | e->show (); |
162 | e->show (); |
159 | } |
163 | } |
… | |
… | |
169 | e->show (); |
173 | e->show (); |
170 | } |
174 | } |
171 | |
175 | |
172 | void fisch (vec3 center, GLfloat radius, int depth) |
176 | void fisch (vec3 center, GLfloat radius, int depth) |
173 | { |
177 | { |
174 | entity *planet = new entity (new geometry_sphere (radius)); |
178 | entity *planet = new entity (new geometry_sphere (testmat, radius)); |
175 | planet->move (center); |
179 | planet->move (center); |
176 | planet->show (); |
180 | planet->show (); |
177 | |
181 | |
178 | if (--depth) |
182 | if (--depth) |
179 | { |
183 | { |
… | |
… | |
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; |
… | |
… | |
300 | |
315 | |
301 | /* Set the gamma for the window */ |
316 | /* Set the gamma for the window */ |
302 | if (gamma != 0.0) |
317 | if (gamma != 0.0) |
303 | SDL_SetGamma (gamma, gamma, gamma); |
318 | SDL_SetGamma (gamma, gamma, gamma); |
304 | |
319 | |
|
|
320 | testmat = new test_material; |
|
|
321 | testmat2 = new test_material2; |
|
|
322 | |
305 | entity *planet = new entity (new geometry_sphere (10)); |
323 | entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat, 10)); |
306 | planet->move (vec3 (0, 0, -20)); |
324 | planet->move (vec3 (0, 0, -20)); |
307 | planet->show (); |
325 | planet->show (); |
308 | |
326 | |
309 | shader::debdebdebdebug ();//D |
327 | planet->v = vec3 (10, 0, 0); |
|
|
328 | moveables.push_back (planet); |
310 | |
329 | |
311 | #if 1 |
330 | doom3parse ("test.proc"); |
|
|
331 | |
312 | for (int i = 0; i < 20; i++) |
332 | for (int i = 0; i < 20; i++) |
313 | { |
333 | { |
314 | // load a entity |
334 | // load a entity |
315 | txtprt_parser p; |
335 | txtprt_parser p; |
316 | geometry *g; |
336 | geometry *g; |
… | |
… | |
326 | entity *e = new entity (g); |
346 | entity *e = new entity (g); |
327 | e->move (vec3 (i*5, -3, -i*10)); |
347 | e->move (vec3 (i*5, -3, -i*10)); |
328 | e->show (); |
348 | e->show (); |
329 | } |
349 | } |
330 | |
350 | |
331 | { |
351 | { |
332 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
352 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
333 | //entity *planet = new entity (new geometry_sphere (1e9)); |
353 | //entity *planet = new entity (new geometry_sphere (1e9)); |
334 | //planet->move (vec3 (0, 0, -1.5e9)); |
354 | //planet->move (vec3 (0, 0, -1.5e9)); |
335 | //planet->show (); |
355 | //planet->show (); |
336 | } |
356 | } |
337 | |
357 | |
338 | { |
358 | { |
339 | entity *planet = new entity (new geometry_sphere (4e15)); |
359 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
340 | planet->move (vec3 (0, 0, 1e17)); |
360 | planet->move (vec3 (0, 0, 1e17)); |
341 | planet->show (); |
361 | planet->show (); |
342 | } |
362 | } |
343 | |
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 (); |
|
|
382 | } |
|
|
383 | |
344 | draw_floor (10, -500, -10, -1000); |
384 | //draw_floor (10, -500, -10, -1000); |
345 | draw_level (); |
385 | draw_level (); |
346 | |
386 | |
347 | |
387 | #if 0 |
348 | { |
388 | { |
349 | geometry_heightfield *hf = new geometry_heightfield; |
389 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
350 | geometry_transform *tr = new geometry_transform (hf); |
|
|
351 | tr->update (gl::matrix::scaling (10000., 10000., 10000.)); |
|
|
352 | entity *e = new entity (tr); |
390 | entity *e = new entity (hf); |
353 | e->move (vec3 (-10000, -20, -10000)); |
391 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
354 | e->show (); |
392 | e->show (); |
355 | } |
393 | } |
|
|
394 | #endif |
356 | |
395 | |
357 | //draw_test_nurb (); |
396 | //draw_test_nurb (); |
358 | #endif |
|
|
359 | |
397 | |
360 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
398 | //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; |
399 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
362 | camera.p = point (0, 0, 10); |
400 | camera.p = point (0, 0, 10); |
363 | camera.d = vec3 (0, 0, -1); |
401 | camera.d = vec3 (0, 0, -1); |
364 | camera.u = vec3 (0, 1, 0); |
402 | camera.u = vec3 (0, 1, 0); |
365 | camera.w = w; camera.h = h; |
403 | camera.w = w; camera.h = h; |
366 | camera.fov = 40.; |
404 | camera.fov = 40.; |
367 | |
405 | |
368 | glEnable (GL_CULL_FACE); |
|
|
369 | glDisable (GL_ALPHA_TEST); |
406 | glDisable (GL_ALPHA_TEST); |
370 | glDisable (GL_BLEND); |
|
|
371 | |
|
|
372 | test_material test_mat; |
|
|
373 | |
407 | |
374 | /* Loop until done. */ |
408 | /* Loop until done. */ |
375 | frames = 0; |
409 | frames = 0; |
376 | |
410 | |
|
|
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 | |
|
|
417 | mylight2.radius = 100000; |
|
|
418 | mylight2.c = colour (1., 1., 1., 1.); |
|
|
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; |
|
|
422 | |
|
|
423 | //pass_data pass_light (&mylight); |
|
|
424 | pass_data pass_light2 (&mylight2); |
|
|
425 | |
377 | while (!done) |
426 | while (!done) |
378 | { |
427 | { |
379 | char *sdl_error; |
428 | char *sdl_error; |
380 | SDL_Event event; |
429 | SDL_Event event; |
381 | |
430 | |
382 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
431 | camera_angle += 90 * camera_velocity_angle * timer.diff; |
383 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
432 | camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
384 | |
433 | |
385 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
434 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
386 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
435 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
387 | |
436 | |
388 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
437 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
389 | camera.u = cross (camera.d, right); |
438 | camera.u = cross (camera.d, right); |
390 | |
439 | |
391 | 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; |
392 | 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; |
393 | |
442 | |
|
|
443 | //mylight.orig = camera.orig; |
|
|
444 | //mylight.p = camera.p; |
394 | |
445 | |
|
|
446 | mylight2.orig = camera.orig; |
|
|
447 | mylight2.p = vec3 (sin (timer.now / 2) * 100000, 1, cos (timer.now / 2) * 100000); |
|
|
448 | |
|
|
449 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
|
|
450 | |
395 | camera.begin (); |
451 | camera.begin (); |
396 | camera.render (view::DEPTH); |
452 | camera.render (pass_depth); |
397 | camera.render (view::POSTDEPTH); |
453 | camera.render (pass_postdepth); |
398 | test_mat.enable (camera); |
454 | camera.render (pass_light2); |
399 | camera.render (view::LIGHTED); |
455 | //camera.render (view::LIGHTED, pass_light2); |
400 | test_mat.disable (camera); |
|
|
401 | camera.end (); |
456 | camera.end (); |
|
|
457 | |
|
|
458 | perfom_moves (); |
402 | |
459 | |
403 | SDL_GL_SwapBuffers (); |
460 | SDL_GL_SwapBuffers (); |
404 | timer.frame (); |
461 | timer.frame (); |
405 | |
462 | |
406 | #if 0 |
463 | #if 0 |