… | |
… | |
13 | |
13 | |
14 | #include "util.h" |
14 | #include "util.h" |
15 | #include "entity.h" |
15 | #include "entity.h" |
16 | #include "txtprt_import.h" |
16 | #include "txtprt_import.h" |
17 | |
17 | |
|
|
18 | bool doom3parse (const char *f); |
|
|
19 | |
|
|
20 | #include "shader.h" |
|
|
21 | |
18 | /**********************************************************************/ |
22 | /**********************************************************************/ |
19 | |
23 | |
20 | view camera; |
24 | view camera; |
21 | vec3 camera_velocity; |
25 | vec3 camera_velocity; |
22 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
26 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
… | |
… | |
26 | HotKey_ToggleFullScreen (void) |
30 | HotKey_ToggleFullScreen (void) |
27 | { |
31 | { |
28 | SDL_Surface *screen; |
32 | SDL_Surface *screen; |
29 | |
33 | |
30 | screen = SDL_GetVideoSurface (); |
34 | screen = SDL_GetVideoSurface (); |
|
|
35 | |
31 | if (SDL_WM_ToggleFullScreen (screen)) |
36 | if (SDL_WM_ToggleFullScreen (screen)) |
32 | printf ("Toggled fullscreen mode - now %s\n", |
37 | printf ("Toggled fullscreen mode - now %s\n", |
33 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
38 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
34 | else |
39 | else |
35 | printf ("Unable to toggle fullscreen mode\n"); |
40 | printf ("Unable to toggle fullscreen mode\n"); |
… | |
… | |
40 | { |
45 | { |
41 | SDL_GrabMode mode; |
46 | SDL_GrabMode mode; |
42 | |
47 | |
43 | printf ("Ctrl-G: toggling input grab!\n"); |
48 | printf ("Ctrl-G: toggling input grab!\n"); |
44 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
49 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
|
|
50 | |
45 | if (mode == SDL_GRAB_ON) |
51 | if (mode == SDL_GRAB_ON) |
46 | printf ("Grab was on\n"); |
52 | printf ("Grab was on\n"); |
47 | else |
53 | else |
48 | printf ("Grab was off\n"); |
54 | printf ("Grab was off\n"); |
49 | |
55 | |
50 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
56 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
|
|
57 | |
51 | if (mode == SDL_GRAB_ON) |
58 | if (mode == SDL_GRAB_ON) |
52 | printf ("Grab is now on\n"); |
59 | printf ("Grab is now on\n"); |
53 | else |
60 | else |
54 | printf ("Grab is now off\n"); |
61 | printf ("Grab is now off\n"); |
55 | } |
62 | } |
… | |
… | |
65 | HandleEvent (SDL_Event * event) |
72 | HandleEvent (SDL_Event * event) |
66 | { |
73 | { |
67 | int done; |
74 | int done; |
68 | |
75 | |
69 | done = 0; |
76 | done = 0; |
|
|
77 | |
70 | switch (event->type) |
78 | switch (event->type) |
71 | { |
79 | { |
72 | case SDL_ACTIVEEVENT: |
80 | case SDL_ACTIVEEVENT: |
73 | /* See what happened */ |
81 | /* See what happened */ |
74 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
82 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
… | |
… | |
143 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
151 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
144 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
152 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
145 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
153 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
146 | |
154 | |
147 | geometry_quads *q = new geometry_quads; |
155 | geometry_quads *q = new geometry_quads; |
148 | q->m = new simple_material; |
156 | //q->m = new simple_material; |
149 | q->set (pts); |
157 | q->set (pts); |
150 | entity *e = new entity (q); |
158 | entity *e = new entity (q); |
151 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
159 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
152 | e->show (); |
160 | e->show (); |
153 | } |
161 | } |
… | |
… | |
159 | geometry_nurbs *q = new geometry_nurbs; |
167 | geometry_nurbs *q = new geometry_nurbs; |
160 | q->set (); |
168 | q->set (); |
161 | entity *e = new entity (q); |
169 | entity *e = new entity (q); |
162 | e->move (vec3 (10, 3, -4)); |
170 | e->move (vec3 (10, 3, -4)); |
163 | e->show (); |
171 | e->show (); |
|
|
172 | } |
|
|
173 | |
|
|
174 | void fisch (vec3 center, GLfloat radius, int depth) |
|
|
175 | { |
|
|
176 | entity *planet = new entity (new geometry_sphere (testmat, radius)); |
|
|
177 | planet->move (center); |
|
|
178 | planet->show (); |
|
|
179 | |
|
|
180 | if (--depth) |
|
|
181 | { |
|
|
182 | GLfloat r2 = radius * .1F; |
|
|
183 | GLfloat r3 = radius + r2; |
|
|
184 | |
|
|
185 | fisch (center + vec3 (r3, 0, 0), r2, depth); |
|
|
186 | fisch (center + vec3 (0, 0, r3), r2, depth); |
|
|
187 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
|
|
188 | } |
164 | } |
189 | } |
165 | |
190 | |
166 | extern void draw_level (); |
191 | extern void draw_level (); |
167 | int |
192 | int |
168 | RunGLTest (int argc, char *argv[], |
193 | RunGLTest (int argc, char *argv[], |
… | |
… | |
172 | int rgb_size[3]; |
197 | int rgb_size[3]; |
173 | int w = 640; |
198 | int w = 640; |
174 | int h = 480; |
199 | int h = 480; |
175 | int done = 0; |
200 | int done = 0; |
176 | int frames; |
201 | int frames; |
177 | Uint32 start_time, this_time; |
|
|
178 | Uint32 video_flags; |
202 | Uint32 video_flags; |
179 | int value; |
203 | int value; |
180 | GLenum gl_error; |
204 | GLenum gl_error; |
181 | |
205 | |
182 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
206 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
… | |
… | |
227 | } |
251 | } |
228 | |
252 | |
229 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
253 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
230 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
254 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
231 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
255 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
232 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
256 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
233 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
257 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
234 | |
258 | |
235 | if (fsaa) |
259 | if (fsaa) |
236 | { |
260 | { |
237 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
261 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
… | |
… | |
243 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
267 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
244 | SDL_Quit (); |
268 | SDL_Quit (); |
245 | exit (1); |
269 | exit (1); |
246 | } |
270 | } |
247 | |
271 | |
248 | printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
272 | //printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
249 | printf ("\n"); |
273 | //printf ("\n"); |
250 | printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
274 | //printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
251 | printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
275 | //printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
252 | printf ("Version : %s\n", glGetString (GL_VERSION)); |
276 | //printf ("Version : %s\n", glGetString (GL_VERSION)); |
253 | printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
277 | //printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
254 | printf ("\n"); |
278 | printf ("\n"); |
255 | |
279 | |
256 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
280 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
257 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
281 | printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
258 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
282 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
… | |
… | |
278 | |
302 | |
279 | /* Set the gamma for the window */ |
303 | /* Set the gamma for the window */ |
280 | if (gamma != 0.0) |
304 | if (gamma != 0.0) |
281 | SDL_SetGamma (gamma, gamma, gamma); |
305 | SDL_SetGamma (gamma, gamma, gamma); |
282 | |
306 | |
|
|
307 | testmat = new test_material; |
|
|
308 | |
283 | entity *planet = new entity (new geometry_sphere (10)); |
309 | entity *planet = new entity (new geometry_sphere (testmat, 10)); |
284 | planet->move (vec3 (0, 0, -20)); |
310 | planet->move (vec3 (0, 0, -20)); |
285 | planet->show (); |
311 | planet->show (); |
286 | |
312 | |
287 | #if 1 |
313 | doom3parse ("test.proc"); |
|
|
314 | |
288 | for (int i = 0; i < 20; i++) |
315 | for (int i = 0; i < 20; i++) |
289 | { |
316 | { |
290 | // load a entity |
317 | // load a entity |
291 | txtprt_parser p; |
318 | txtprt_parser p; |
292 | geometry *g; |
319 | geometry *g; |
… | |
… | |
302 | entity *e = new entity (g); |
329 | entity *e = new entity (g); |
303 | e->move (vec3 (i*5, -3, -i*10)); |
330 | e->move (vec3 (i*5, -3, -i*10)); |
304 | e->show (); |
331 | e->show (); |
305 | } |
332 | } |
306 | |
333 | |
307 | { |
334 | { |
|
|
335 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
308 | entity *planet = new entity (new geometry_sphere (1e9)); |
336 | //entity *planet = new entity (new geometry_sphere (1e9)); |
309 | planet->move (vec3 (0, 0, -1.5e9)); |
337 | //planet->move (vec3 (0, 0, -1.5e9)); |
310 | planet->show (); |
338 | //planet->show (); |
311 | } |
339 | } |
312 | |
340 | |
313 | { |
341 | { |
314 | entity *planet = new entity (new geometry_sphere (4e15)); |
342 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
315 | planet->move (vec3 (0, 0, 1e17)); |
343 | planet->move (vec3 (0, 0, 1e17)); |
316 | planet->show (); |
344 | planet->show (); |
317 | } |
345 | } |
318 | |
346 | |
319 | draw_floor (10, -500, -10, -1000); |
347 | //draw_floor (10, -500, -10, -1000); |
320 | draw_level (); |
348 | draw_level (); |
|
|
349 | |
|
|
350 | #if 0 |
|
|
351 | { |
|
|
352 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
|
|
353 | entity *e = new entity (hf); |
|
|
354 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
|
|
355 | e->show (); |
|
|
356 | } |
|
|
357 | #endif |
|
|
358 | |
321 | //draw_test_nurb (); |
359 | //draw_test_nurb (); |
322 | #endif |
|
|
323 | |
360 | |
324 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
361 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
325 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
362 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
326 | camera.p = point (0, 0, 10); |
363 | camera.p = point (0, 0, 10); |
327 | camera.d = vec3 (0, 0, -1); |
364 | camera.d = vec3 (0, 0, -1); |
328 | camera.u = vec3 (0, 1, 0); |
365 | camera.u = vec3 (0, 1, 0); |
329 | camera.w = w; camera.h = h; |
366 | camera.w = w; camera.h = h; |
330 | camera.fov = 35; |
367 | camera.fov = 40.; |
331 | camera.z_near = 1.; |
|
|
332 | |
368 | |
333 | glEnable (GL_CULL_FACE); |
369 | glEnable (GL_CULL_FACE); |
334 | |
370 | glDisable (GL_ALPHA_TEST); |
335 | init_shaders (); |
371 | glDisable (GL_BLEND); |
336 | |
|
|
337 | osama_material osa_mat; |
|
|
338 | |
372 | |
339 | /* Loop until done. */ |
373 | /* Loop until done. */ |
340 | start_time = SDL_GetTicks (); |
|
|
341 | frames = 0; |
374 | frames = 0; |
|
|
375 | |
|
|
376 | linear_light mylight; |
|
|
377 | mylight.radius = 100000; |
|
|
378 | mylight.c = colour (1., 1, 1, 1.); |
|
|
379 | mylight.intensity = 1.F; |
|
|
380 | |
|
|
381 | pass pass_light (&mylight); |
342 | |
382 | |
343 | while (!done) |
383 | while (!done) |
344 | { |
384 | { |
345 | char *sdl_error; |
385 | char *sdl_error; |
346 | SDL_Event event; |
386 | SDL_Event event; |
347 | |
387 | |
348 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
388 | camera_angle += 90 * camera_velocity_angle * timer.diff; |
349 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
389 | camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
350 | |
390 | |
351 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
391 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
352 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
392 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
353 | |
393 | |
354 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
394 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
355 | camera.u = cross (camera.d, right); |
395 | camera.u = cross (camera.d, right); |
356 | |
396 | |
357 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
397 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
358 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
398 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
359 | |
399 | |
360 | osa_mat.begin (); |
400 | mylight.orig = camera.orig; |
|
|
401 | mylight.p = camera.p; |
361 | |
402 | |
|
|
403 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
|
|
404 | |
362 | camera.begin (); |
405 | camera.begin (); |
363 | camera.pass (view::DEPTH); |
406 | camera.render (view::DEPTH, pass_depth); |
364 | camera.pass (view::POSTDEPTH); |
407 | camera.render (view::POSTDEPTH, pass_depth); |
365 | camera.pass (view::LIGHTED); |
408 | camera.render (view::LIGHTED, pass_light); |
366 | camera.end (); |
409 | camera.end (); |
367 | |
410 | |
368 | SDL_GL_SwapBuffers (); |
411 | SDL_GL_SwapBuffers (); |
369 | timer.frame (); |
412 | timer.frame (); |
370 | |
|
|
371 | osa_mat.end (); |
|
|
372 | |
413 | |
373 | #if 0 |
414 | #if 0 |
374 | /* Check for error conditions. */ |
415 | /* Check for error conditions. */ |
375 | gl_error = glGetError (); |
416 | gl_error = glGetError (); |
376 | |
417 | |
… | |
… | |
390 | |
431 | |
391 | /* Check if there's a pending event. */ |
432 | /* Check if there's a pending event. */ |
392 | while (SDL_PollEvent (&event)) |
433 | while (SDL_PollEvent (&event)) |
393 | done = HandleEvent (&event); |
434 | done = HandleEvent (&event); |
394 | |
435 | |
395 | |
|
|
396 | ++frames; |
436 | ++frames; |
397 | } |
|
|
398 | |
|
|
399 | /* Print out the frames per second */ |
|
|
400 | this_time = SDL_GetTicks (); |
|
|
401 | if (this_time != start_time) |
|
|
402 | { |
|
|
403 | printf ("%2.2f FPS\n", |
|
|
404 | ((float) frames / (this_time - start_time)) * 1000.0); |
|
|
405 | } |
437 | } |
406 | |
438 | |
407 | if (global_image) |
439 | if (global_image) |
408 | { |
440 | { |
409 | SDL_FreeSurface (global_image); |
441 | SDL_FreeSurface (global_image); |
410 | global_image = NULL; |
442 | global_image = NULL; |
411 | } |
443 | } |
|
|
444 | |
412 | if (global_texture) |
445 | if (global_texture) |
413 | { |
446 | { |
414 | glDeleteTextures (1, &global_texture); |
447 | glDeleteTextures (1, &global_texture); |
415 | global_texture = 0; |
448 | global_texture = 0; |
416 | } |
449 | } |