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