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> |
|
|
6 | |
|
|
7 | #include "opengl.h" |
5 | |
8 | |
6 | #include "SDL.h" |
9 | #include "SDL.h" |
7 | #include "SDL_opengl.h" |
10 | #include "SDL_opengl.h" |
8 | |
11 | |
9 | static SDL_Surface *global_image = NULL; |
12 | static SDL_Surface *global_image = NULL; |
10 | static GLuint global_texture = 0; |
13 | static GLuint global_texture = 0; |
11 | |
14 | |
12 | #include "util.h" |
15 | #include "util.h" |
13 | #include "entity.h" |
16 | #include "entity.h" |
14 | #include "txtprt_import.h" |
17 | #include "txtprt_import.h" |
|
|
18 | #include "randlvl.h" |
15 | |
19 | |
16 | CGcontext cgc; |
20 | bool doom3parse (const char *f); |
17 | CGprogram vsh, fsh; |
|
|
18 | CGparameter mv, mvp, lightpos; |
|
|
19 | CGprofile vsh_profile, fsh_profile; |
|
|
20 | |
21 | |
21 | static void CheckCgError(void) |
22 | #include "shader.h" |
22 | { |
|
|
23 | CGerror err = cgGetError(); |
|
|
24 | |
|
|
25 | if (err != CG_NO_ERROR) |
|
|
26 | { |
|
|
27 | printf("CG error: %s\n", cgGetErrorString(err)); |
|
|
28 | exit(1); |
|
|
29 | } |
|
|
30 | } |
|
|
31 | |
23 | |
32 | /**********************************************************************/ |
24 | /**********************************************************************/ |
33 | |
25 | |
34 | view camera; |
26 | view camera; |
35 | vec3 camera_velocity; |
27 | vec3 camera_velocity; |
36 | float camera_angle = 0, camera_velocity_angle; |
28 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
37 | float camera_velocity_factor = 20; |
29 | float camera_velocity_factor = 80; |
38 | |
30 | |
39 | void |
31 | void |
40 | HotKey_ToggleFullScreen (void) |
32 | HotKey_ToggleFullScreen (void) |
41 | { |
33 | { |
42 | SDL_Surface *screen; |
34 | SDL_Surface *screen; |
43 | |
35 | |
44 | screen = SDL_GetVideoSurface (); |
36 | screen = SDL_GetVideoSurface (); |
|
|
37 | |
45 | if (SDL_WM_ToggleFullScreen (screen)) |
38 | if (SDL_WM_ToggleFullScreen (screen)) |
46 | printf ("Toggled fullscreen mode - now %s\n", |
39 | printf ("Toggled fullscreen mode - now %s\n", |
47 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
40 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
48 | else |
41 | else |
49 | printf ("Unable to toggle fullscreen mode\n"); |
42 | printf ("Unable to toggle fullscreen mode\n"); |
… | |
… | |
54 | { |
47 | { |
55 | SDL_GrabMode mode; |
48 | SDL_GrabMode mode; |
56 | |
49 | |
57 | printf ("Ctrl-G: toggling input grab!\n"); |
50 | printf ("Ctrl-G: toggling input grab!\n"); |
58 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
51 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
|
|
52 | |
59 | if (mode == SDL_GRAB_ON) |
53 | if (mode == SDL_GRAB_ON) |
60 | printf ("Grab was on\n"); |
54 | printf ("Grab was on\n"); |
61 | else |
55 | else |
62 | printf ("Grab was off\n"); |
56 | printf ("Grab was off\n"); |
63 | |
57 | |
64 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
58 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
|
|
59 | |
65 | if (mode == SDL_GRAB_ON) |
60 | if (mode == SDL_GRAB_ON) |
66 | printf ("Grab is now on\n"); |
61 | printf ("Grab is now on\n"); |
67 | else |
62 | else |
68 | printf ("Grab is now off\n"); |
63 | printf ("Grab is now off\n"); |
69 | } |
64 | } |
… | |
… | |
79 | HandleEvent (SDL_Event * event) |
74 | HandleEvent (SDL_Event * event) |
80 | { |
75 | { |
81 | int done; |
76 | int done; |
82 | |
77 | |
83 | done = 0; |
78 | done = 0; |
|
|
79 | |
84 | switch (event->type) |
80 | switch (event->type) |
85 | { |
81 | { |
86 | case SDL_ACTIVEEVENT: |
82 | case SDL_ACTIVEEVENT: |
87 | /* See what happened */ |
83 | /* See what happened */ |
88 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
84 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
89 | if (event->active.state & SDL_APPACTIVE) |
85 | if (event->active.state & SDL_APPACTIVE) |
90 | { |
|
|
91 | printf ("active "); |
86 | printf ("active "); |
92 | } |
|
|
93 | else if (event->active.state & SDL_APPMOUSEFOCUS) |
87 | else if (event->active.state & SDL_APPMOUSEFOCUS) |
94 | { |
|
|
95 | printf ("mouse "); |
88 | printf ("mouse "); |
96 | } |
|
|
97 | else if (event->active.state & SDL_APPINPUTFOCUS) |
89 | else if (event->active.state & SDL_APPINPUTFOCUS) |
98 | { |
|
|
99 | printf ("input "); |
90 | printf ("input "); |
100 | } |
|
|
101 | |
91 | |
102 | printf ("focus\n"); |
92 | printf ("focus\n"); |
103 | break; |
93 | break; |
104 | |
94 | |
105 | case SDL_KEYDOWN: |
95 | case SDL_KEYDOWN: |
106 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
96 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
107 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
97 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
108 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x--; |
|
|
109 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x++; |
98 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle++; |
|
|
99 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle--; |
|
|
100 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2++; |
|
|
101 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2--; |
110 | if (event->key.keysym.sym == SDLK_a) camera_velocity.y--; |
102 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y--; |
111 | if (event->key.keysym.sym == SDLK_s) camera_velocity.y++; |
103 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y++; |
112 | if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
104 | if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
113 | if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; |
105 | if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; |
114 | if (event->key.keysym.sym == SDLK_e) camera_velocity_angle++; |
|
|
115 | if (event->key.keysym.sym == SDLK_q) camera_velocity_angle--; |
|
|
116 | |
106 | |
117 | if (event->key.keysym.sym == SDLK_ESCAPE) |
107 | if (event->key.keysym.sym == SDLK_ESCAPE) |
118 | done = 1; |
108 | done = 1; |
119 | |
109 | |
120 | if ((event->key.keysym.sym == SDLK_g) && |
110 | if ((event->key.keysym.sym == SDLK_g) && |
… | |
… | |
132 | break; |
122 | break; |
133 | |
123 | |
134 | case SDL_KEYUP: |
124 | case SDL_KEYUP: |
135 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
125 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
136 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
126 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
137 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x++; |
127 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle++; |
138 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x--; |
128 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle--; |
|
|
129 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2--; |
|
|
130 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2++; |
139 | if (event->key.keysym.sym == SDLK_a) camera_velocity.y++; |
131 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y++; |
140 | if (event->key.keysym.sym == SDLK_s) camera_velocity.y--; |
132 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y--; |
141 | if (event->key.keysym.sym == SDLK_e) camera_velocity_angle--; |
|
|
142 | if (event->key.keysym.sym == SDLK_q) camera_velocity_angle++; |
|
|
143 | break; |
133 | break; |
144 | |
134 | |
145 | case SDL_QUIT: |
135 | case SDL_QUIT: |
146 | done = 1; |
136 | done = 1; |
147 | break; |
137 | break; |
148 | } |
138 | } |
149 | |
139 | |
150 | return (done); |
140 | return (done); |
|
|
141 | } |
|
|
142 | |
|
|
143 | void draw_floor (int size, int dx, int dy, int dz) |
|
|
144 | { |
|
|
145 | int x, z, ry; |
|
|
146 | |
|
|
147 | for (x = 0; x < 10; x++) |
|
|
148 | { |
|
|
149 | for (z = 0; z < 10; z++) |
|
|
150 | { |
|
|
151 | vector<vertex_t2f_n3f_v3f> pts; |
|
|
152 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, 0), vec3 (0, 1, 0), tex2 (0, 0))); |
|
|
153 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, size), vec3 (0, 1, 0), tex2 (0, 1))); |
|
|
154 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, size), vec3 (0, 1, 0), tex2 (1, 1))); |
|
|
155 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
|
|
156 | |
|
|
157 | geometry_quads *q = new geometry_quads; |
|
|
158 | //q->m = new simple_material; |
|
|
159 | q->set (pts); |
|
|
160 | entity *e = new entity (q); |
|
|
161 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
|
|
162 | e->show (); |
|
|
163 | } |
|
|
164 | } |
|
|
165 | } |
|
|
166 | |
|
|
167 | void draw_test_nurb () |
|
|
168 | { |
|
|
169 | geometry_nurbs *q = new geometry_nurbs; |
|
|
170 | q->set (); |
|
|
171 | entity *e = new entity (q); |
|
|
172 | e->move (vec3 (10, 3, -4)); |
|
|
173 | e->show (); |
|
|
174 | } |
|
|
175 | |
|
|
176 | void fisch (vec3 center, GLfloat radius, int depth) |
|
|
177 | { |
|
|
178 | entity *planet = new entity (new geometry_sphere (testmat, radius)); |
|
|
179 | planet->move (center); |
|
|
180 | planet->show (); |
|
|
181 | |
|
|
182 | if (--depth) |
|
|
183 | { |
|
|
184 | GLfloat r2 = radius * .1F; |
|
|
185 | GLfloat r3 = radius + r2; |
|
|
186 | |
|
|
187 | fisch (center + vec3 (r3, 0, 0), r2, depth); |
|
|
188 | fisch (center + vec3 (0, 0, r3), r2, depth); |
|
|
189 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
|
|
190 | } |
|
|
191 | } |
|
|
192 | |
|
|
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 | } |
151 | } |
203 | } |
152 | |
204 | |
153 | int |
205 | int |
154 | RunGLTest (int argc, char *argv[], |
206 | RunGLTest (int argc, char *argv[], |
155 | 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) |
156 | { |
208 | { |
157 | int i; |
209 | int i; |
158 | int rgb_size[3]; |
210 | int rgb_size[3]; |
159 | int w = 640; |
211 | int w = 1600; |
160 | int h = 480; |
212 | int h = 1200; |
161 | int done = 0; |
213 | int done = 0; |
162 | int frames; |
214 | int frames; |
163 | Uint32 start_time, this_time; |
|
|
164 | Uint32 video_flags; |
215 | Uint32 video_flags; |
165 | int value; |
216 | int value; |
166 | GLenum gl_error; |
217 | GLenum gl_error; |
167 | |
218 | |
168 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
219 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
169 | { |
220 | { |
170 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
221 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
171 | exit (1); |
222 | exit (1); |
… | |
… | |
213 | } |
264 | } |
214 | |
265 | |
215 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
266 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
216 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
267 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
217 | 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); |
218 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
270 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
219 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
271 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
220 | |
272 | |
221 | if (fsaa) |
273 | if (fsaa) |
222 | { |
274 | { |
223 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
275 | SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
… | |
… | |
229 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
281 | fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); |
230 | SDL_Quit (); |
282 | SDL_Quit (); |
231 | exit (1); |
283 | exit (1); |
232 | } |
284 | } |
233 | |
285 | |
234 | printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
286 | //printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel); |
235 | printf ("\n"); |
287 | //printf ("\n"); |
236 | printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
288 | //printf ("Vendor : %s\n", glGetString (GL_VENDOR)); |
237 | printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
289 | //printf ("Renderer : %s\n", glGetString (GL_RENDERER)); |
238 | printf ("Version : %s\n", glGetString (GL_VERSION)); |
290 | //printf ("Version : %s\n", glGetString (GL_VERSION)); |
239 | printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
291 | //printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS)); |
240 | printf ("\n"); |
292 | printf ("\n"); |
241 | |
293 | |
242 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
294 | SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value); |
243 | 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); |
244 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
296 | SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value); |
245 | 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); |
246 | SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value); |
298 | SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value); |
247 | 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); |
248 | SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); |
302 | SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); |
249 | 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); |
250 | SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); |
304 | SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); |
251 | printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); |
305 | printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); |
252 | |
306 | |
… | |
… | |
264 | |
318 | |
265 | /* Set the gamma for the window */ |
319 | /* Set the gamma for the window */ |
266 | if (gamma != 0.0) |
320 | if (gamma != 0.0) |
267 | SDL_SetGamma (gamma, gamma, gamma); |
321 | SDL_SetGamma (gamma, gamma, gamma); |
268 | |
322 | |
|
|
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 (); |
|
|
327 | |
|
|
328 | entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat2, 10)); |
|
|
329 | planet->move (vec3 (0, 0, -20)); |
|
|
330 | planet->show (); |
|
|
331 | |
|
|
332 | planet->v = vec3 (10, 0, 0); |
|
|
333 | moveables.push_back (planet); |
|
|
334 | |
|
|
335 | doom3parse ("test.proc"); |
|
|
336 | |
|
|
337 | skybox sb ( |
|
|
338 | "textures/skybox_mystery/1.jpg", |
|
|
339 | "textures/skybox_mystery/2.jpg", |
|
|
340 | "textures/skybox_mystery/3.jpg", |
|
|
341 | "textures/skybox_mystery/4.jpg", |
|
|
342 | "textures/skybox_mystery/5.jpg", |
|
|
343 | "textures/skybox_mystery/6.jpg" |
|
|
344 | ); |
|
|
345 | world_skybox = &sb; |
|
|
346 | |
269 | for (int i = 0; i < 70; i++) |
347 | for (int i = 0; i < 20; i++) |
270 | { |
348 | { |
271 | // load a entity |
349 | // load a entity |
272 | txtprt_parser p; |
350 | txtprt_parser p; |
273 | entity *e; |
351 | geometry *g; |
274 | try |
352 | try |
275 | { |
353 | { |
276 | e = p.read ("test.blasc"); |
354 | g = p.read ("test.blasc"); |
277 | } |
355 | } |
278 | catch (txtprt_i_exception & e) |
356 | catch (txtprt_i_exception & e) |
279 | { |
357 | { |
280 | cout << "ERR: " << e.msg << endl; |
358 | cout << "ERR: " << e.msg << endl; |
281 | } |
359 | } |
282 | |
360 | |
283 | entity_transform *f = new entity_transform; |
361 | entity *e = new entity (g); |
284 | f->set (e); |
362 | e->move (vec3 (i*5, -3, -i*10)); |
285 | f->update (matrix::translation (vec3 (i*5, -3, -i*10))); |
|
|
286 | f->show (); |
363 | e->show (); |
|
|
364 | } |
|
|
365 | |
|
|
366 | { |
|
|
367 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
|
|
368 | //entity *planet = new entity (new geometry_sphere (1e9)); |
|
|
369 | //planet->move (vec3 (0, 0, -1.5e9)); |
|
|
370 | //planet->show (); |
287 | } |
371 | } |
288 | draw_some_random_funky_floor_dance_music (10, -500, -10, -1000); |
372 | |
|
|
373 | { |
|
|
374 | entity *planet = new entity (new geometry_sphere (testmat3, 4e15)); |
|
|
375 | planet->move (vec3 (0, 0, 1e17)); |
|
|
376 | planet->show (); |
|
|
377 | } |
|
|
378 | |
|
|
379 | { |
|
|
380 | RandomBuilding r; |
|
|
381 | entity *randlvl = r.draw (1000, 1000, 200); |
|
|
382 | randlvl->move (vec3 (0, 0, 0)); |
|
|
383 | randlvl->show (); |
|
|
384 | |
|
|
385 | entity *randlvl2 = r.draw (1000, 10000, 1000); |
|
|
386 | randlvl2->move (vec3 (-20000, 0, 0)); |
|
|
387 | randlvl2->show (); |
|
|
388 | |
|
|
389 | entity *randlvl3 = r.draw (100, 30, 3); |
|
|
390 | randlvl3->move (vec3 (-1000, 0, 0)); |
|
|
391 | randlvl3->show (); |
|
|
392 | |
|
|
393 | |
|
|
394 | entity *randlvl4 = r.draw (100, 1000000, 100000); |
|
|
395 | randlvl4->move (vec3 (0, -1001000, 0)); |
|
|
396 | randlvl4->show (); |
|
|
397 | } |
|
|
398 | |
|
|
399 | //draw_floor (10, -500, -10, -1000); |
|
|
400 | draw_level (); |
|
|
401 | |
|
|
402 | #if 0 |
|
|
403 | { |
|
|
404 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
|
|
405 | entity *e = new entity (hf); |
|
|
406 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
|
|
407 | e->show (); |
|
|
408 | } |
|
|
409 | #endif |
|
|
410 | |
|
|
411 | //draw_test_nurb (); |
|
|
412 | |
|
|
413 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
289 | camera.orig.x = camera.orig.y = camera.orig.z = 0; |
414 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
290 | camera.p = point (0, 0, 10); |
415 | camera.p = point (0, 0, 10); |
291 | camera.d = vec3 (0, 0, -1); |
416 | camera.d = vec3 (0, 0, -1); |
292 | camera.u = vec3 (0, 1, 0); |
417 | camera.u = vec3 (0, 1, 0); |
293 | camera.w = w; camera.h = h; |
418 | camera.w = w; camera.h = h; |
294 | camera.fov = 80; |
419 | camera.fov = 40.; |
295 | |
420 | |
296 | glMatrixMode (GL_MODELVIEW); |
|
|
297 | glLoadIdentity (); |
|
|
298 | |
|
|
299 | glEnable (GL_CULL_FACE); |
|
|
300 | glEnable (GL_DEPTH_TEST); |
421 | glDisable (GL_ALPHA_TEST); |
301 | |
|
|
302 | glShadeModel (GL_SMOOTH); |
|
|
303 | |
|
|
304 | glEnable (GL_LIGHTING); |
|
|
305 | glEnable (GL_LIGHT0); |
|
|
306 | |
|
|
307 | cgc = cgCreateContext (); |
|
|
308 | |
|
|
309 | vsh_profile = CG_PROFILE_ARBVP1; |
|
|
310 | //if (cgGLIsProfileSupported (CG_PROFILE_VP30)) vsh_profile = CG_PROFILE_VP30; |
|
|
311 | //if (cgGLIsProfileSupported (CG_PROFILE_VP40)) vsh_profile = CG_PROFILE_VP40; |
|
|
312 | fsh_profile = CG_PROFILE_ARBFP1; |
|
|
313 | //if (cgGLIsProfileSupported (CG_PROFILE_FP30)) fsh_profile = CG_PROFILE_FP30; |
|
|
314 | //if (cgGLIsProfileSupported (CG_PROFILE_FP40)) fsh_profile = CG_PROFILE_FP40; |
|
|
315 | |
|
|
316 | vsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "vsh.cg", vsh_profile, 0, 0); |
|
|
317 | CheckCgError (); |
|
|
318 | cgGLLoadProgram (vsh); |
|
|
319 | CheckCgError (); |
|
|
320 | mv = cgGetNamedParameter (vsh, "WorldProj"); |
|
|
321 | mvp = cgGetNamedParameter (vsh, "WorldViewProj"); |
|
|
322 | lightpos = cgGetNamedParameter (vsh, "LightPos"); |
|
|
323 | CheckCgError (); |
|
|
324 | |
|
|
325 | CGparameter g_Texture; // the texture parameter |
|
|
326 | |
|
|
327 | |
|
|
328 | fsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "fsh.cg", fsh_profile, 0, 0); |
|
|
329 | Texture t("o.jpg"); |
|
|
330 | g_Texture = cgGetNamedParameter(fsh, "Texture"); // the texture cg-warper ;) |
|
|
331 | cgGLSetTextureParameter(g_Texture, t.texture); // Bind the texture number 999 to g_Texture |
|
|
332 | CheckCgError (); |
|
|
333 | cgGLLoadProgram (fsh); |
|
|
334 | CheckCgError (); |
|
|
335 | |
|
|
336 | cgGLBindProgram (vsh); |
|
|
337 | CheckCgError (); |
|
|
338 | cgGLBindProgram (fsh); |
|
|
339 | CheckCgError (); |
|
|
340 | |
422 | |
341 | /* Loop until done. */ |
423 | /* Loop until done. */ |
342 | start_time = SDL_GetTicks (); |
|
|
343 | frames = 0; |
424 | frames = 0; |
|
|
425 | |
|
|
426 | linear_light mylight2;//mylight, mylight2; |
|
|
427 | |
|
|
428 | // mylight.radius = 100000; |
|
|
429 | // mylight.c = colour (1., 1, 1, 1.); |
|
|
430 | // mylight.intensity = 1.F; |
|
|
431 | |
|
|
432 | mylight2.radius = 100000; |
|
|
433 | mylight2.c = colour (0., 1., 1., 1.); |
|
|
434 | mylight2.intensity = 1.F; |
|
|
435 | mylight2.orig.x = 0; mylight2.orig.y = 0; mylight2.orig.z = 0; |
|
|
436 | mylight2.p.x = 0; mylight2.p.y = 0; mylight2.p.z = 0; |
|
|
437 | |
|
|
438 | //pass_data pass_light (&mylight); |
|
|
439 | pass_data pass_light2 (&mylight2); |
344 | |
440 | |
345 | while (!done) |
441 | while (!done) |
346 | { |
442 | { |
347 | char *sdl_error; |
443 | char *sdl_error; |
348 | SDL_Event event; |
444 | SDL_Event event; |
349 | |
445 | |
350 | camera.p.x += camera_velocity_factor * camera_velocity.x * timer.diff; |
|
|
351 | camera.p.y += camera_velocity_factor * camera_velocity.y * timer.diff; |
|
|
352 | camera.p.z += camera_velocity_factor * camera_velocity.z * timer.diff; |
|
|
353 | |
|
|
354 | camera_angle += camera_velocity_factor * camera_velocity_angle * timer.diff; |
446 | camera_angle += 90 * camera_velocity_angle * timer.diff; |
355 | camera.d.z = -cos (camera_angle * 12 / 180.); |
447 | camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
356 | camera.d.x = sin (camera_angle * 12 / 180.); |
|
|
357 | |
448 | |
358 | cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); |
449 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
|
|
450 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
359 | |
451 | |
360 | glBindTexture (GL_TEXTURE_2D, t.texture); |
452 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
361 | cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter |
453 | camera.u = cross (camera.d, right); |
362 | |
454 | |
363 | #if 0 |
455 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
364 | static GLfloat ry; |
456 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
365 | ry += 0.001; |
|
|
366 | camera.d.x = cos (ry); |
|
|
367 | camera.d.z = sin (ry); |
|
|
368 | //camera.d.y = sin (ry * 0.1); |
|
|
369 | #endif |
|
|
370 | |
457 | |
|
|
458 | //mylight.orig = camera.orig; |
|
|
459 | //mylight.p = camera.p; |
|
|
460 | |
|
|
461 | mylight2.orig = camera.orig; |
|
|
462 | //mylight2.p = vec3 (sin (timer.now / 2) * 100000, 1, cos (timer.now / 2) * 100000); |
|
|
463 | |
|
|
464 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
|
|
465 | |
371 | camera.begin (); |
466 | camera.begin (); |
372 | camera.pass (view::DEPTH); |
467 | camera.render (pass_depth); |
373 | camera.pass (view::LIGHTED); |
468 | camera.render (pass_postdepth); |
|
|
469 | camera.render (pass_light2); |
|
|
470 | //camera.render (view::LIGHTED, pass_light2); |
374 | camera.end (); |
471 | camera.end (); |
|
|
472 | |
|
|
473 | perfom_moves (); |
375 | |
474 | |
376 | SDL_GL_SwapBuffers (); |
475 | SDL_GL_SwapBuffers (); |
377 | timer.frame (); |
476 | timer.frame (); |
378 | |
477 | |
|
|
478 | #if 0 |
379 | /* Check for error conditions. */ |
479 | /* Check for error conditions. */ |
380 | gl_error = glGetError (); |
480 | gl_error = glGetError (); |
381 | |
481 | |
382 | if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
482 | if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
383 | |
483 | |
… | |
… | |
388 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
488 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
389 | SDL_ClearError (); |
489 | SDL_ClearError (); |
390 | } |
490 | } |
391 | |
491 | |
392 | /* Allow the user to see what's happening */ |
492 | /* Allow the user to see what's happening */ |
393 | //SDL_Delay (20); |
493 | //SDL_Delay (40); |
|
|
494 | #endif |
394 | |
495 | |
395 | /* Check if there's a pending event. */ |
496 | /* Check if there's a pending event. */ |
396 | while (SDL_PollEvent (&event)) |
497 | while (SDL_PollEvent (&event)) |
397 | done = HandleEvent (&event); |
498 | done = HandleEvent (&event); |
398 | |
499 | |
399 | |
|
|
400 | ++frames; |
500 | ++frames; |
401 | } |
|
|
402 | |
|
|
403 | /* Print out the frames per second */ |
|
|
404 | this_time = SDL_GetTicks (); |
|
|
405 | if (this_time != start_time) |
|
|
406 | { |
|
|
407 | printf ("%2.2f FPS\n", |
|
|
408 | ((float) frames / (this_time - start_time)) * 1000.0); |
|
|
409 | } |
501 | } |
410 | |
502 | |
411 | if (global_image) |
503 | if (global_image) |
412 | { |
504 | { |
413 | SDL_FreeSurface (global_image); |
505 | SDL_FreeSurface (global_image); |
414 | global_image = NULL; |
506 | global_image = NULL; |
415 | } |
507 | } |
|
|
508 | |
416 | if (global_texture) |
509 | if (global_texture) |
417 | { |
510 | { |
418 | glDeleteTextures (1, &global_texture); |
511 | glDeleteTextures (1, &global_texture); |
419 | global_texture = 0; |
512 | global_texture = 0; |
420 | } |
513 | } |
421 | |
514 | |
422 | /* Destroy our GL context, etc. */ |
515 | /* Destroy our GL context, etc. */ |
423 | SDL_Quit (); |
516 | SDL_Quit (); |
424 | return (0); |
517 | return (0); |
425 | } |
518 | } |
426 | |
|
|
427 | int |
519 | int |
428 | main (int argc, char *argv[]) |
520 | main (int argc, char *argv[]) |
429 | { |
521 | { |
430 | int i, logo; |
522 | int i, logo; |
431 | int numtests; |
523 | int numtests; |