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 | |
5 | |
|
|
6 | #include "opengl.h" |
|
|
7 | |
6 | #include "SDL.h" |
8 | #include "SDL.h" |
7 | |
|
|
8 | #include "SDL_opengl.h" |
9 | #include "SDL_opengl.h" |
9 | |
|
|
10 | /* Undefine this if you want a flat cube instead of a rainbow cube */ |
|
|
11 | #define SHADED_CUBE |
|
|
12 | |
|
|
13 | /* Define this to be the name of the logo image to use with -logo */ |
|
|
14 | #define LOGO_FILE "icon.bmp" |
|
|
15 | |
10 | |
16 | static SDL_Surface *global_image = NULL; |
11 | static SDL_Surface *global_image = NULL; |
17 | static GLuint global_texture = 0; |
12 | static GLuint global_texture = 0; |
18 | |
13 | |
|
|
14 | #include "util.h" |
19 | #include "entity.h" |
15 | #include "entity.h" |
20 | |
|
|
21 | #include "txtprt_import.h" |
16 | #include "txtprt_import.h" |
22 | |
17 | |
23 | /**********************************************************************/ |
18 | /**********************************************************************/ |
|
|
19 | |
|
|
20 | view camera; |
|
|
21 | vec3 camera_velocity; |
|
|
22 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
|
|
23 | float camera_velocity_factor = 80; |
24 | |
24 | |
25 | void |
25 | void |
26 | HotKey_ToggleFullScreen (void) |
26 | HotKey_ToggleFullScreen (void) |
27 | { |
27 | { |
28 | SDL_Surface *screen; |
28 | SDL_Surface *screen; |
29 | |
29 | |
30 | screen = SDL_GetVideoSurface (); |
30 | screen = SDL_GetVideoSurface (); |
31 | if (SDL_WM_ToggleFullScreen (screen)) |
31 | if (SDL_WM_ToggleFullScreen (screen)) |
32 | { |
|
|
33 | printf ("Toggled fullscreen mode - now %s\n", |
32 | printf ("Toggled fullscreen mode - now %s\n", |
34 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
33 | (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
35 | } |
|
|
36 | else |
34 | else |
37 | { |
|
|
38 | printf ("Unable to toggle fullscreen mode\n"); |
35 | printf ("Unable to toggle fullscreen mode\n"); |
39 | } |
|
|
40 | } |
36 | } |
41 | |
37 | |
42 | void |
38 | void |
43 | HotKey_ToggleGrab (void) |
39 | HotKey_ToggleGrab (void) |
44 | { |
40 | { |
45 | SDL_GrabMode mode; |
41 | SDL_GrabMode mode; |
46 | |
42 | |
47 | printf ("Ctrl-G: toggling input grab!\n"); |
43 | printf ("Ctrl-G: toggling input grab!\n"); |
48 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
44 | mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
49 | if (mode == SDL_GRAB_ON) |
45 | if (mode == SDL_GRAB_ON) |
50 | { |
|
|
51 | printf ("Grab was on\n"); |
46 | printf ("Grab was on\n"); |
52 | } |
|
|
53 | else |
47 | else |
54 | { |
|
|
55 | printf ("Grab was off\n"); |
48 | printf ("Grab was off\n"); |
56 | } |
|
|
57 | |
49 | |
58 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
50 | mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); |
59 | if (mode == SDL_GRAB_ON) |
51 | if (mode == SDL_GRAB_ON) |
60 | { |
|
|
61 | printf ("Grab is now on\n"); |
52 | printf ("Grab is now on\n"); |
62 | } |
|
|
63 | else |
53 | else |
64 | { |
|
|
65 | printf ("Grab is now off\n"); |
54 | printf ("Grab is now off\n"); |
66 | } |
|
|
67 | } |
55 | } |
68 | |
56 | |
69 | void |
57 | void |
70 | HotKey_Iconify (void) |
58 | HotKey_Iconify (void) |
71 | { |
59 | { |
… | |
… | |
83 | { |
71 | { |
84 | case SDL_ACTIVEEVENT: |
72 | case SDL_ACTIVEEVENT: |
85 | /* See what happened */ |
73 | /* See what happened */ |
86 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
74 | printf ("app %s ", event->active.gain ? "gained" : "lost"); |
87 | if (event->active.state & SDL_APPACTIVE) |
75 | if (event->active.state & SDL_APPACTIVE) |
88 | { |
|
|
89 | printf ("active "); |
76 | printf ("active "); |
90 | } |
|
|
91 | else if (event->active.state & SDL_APPMOUSEFOCUS) |
77 | else if (event->active.state & SDL_APPMOUSEFOCUS) |
92 | { |
|
|
93 | printf ("mouse "); |
78 | printf ("mouse "); |
94 | } |
|
|
95 | else if (event->active.state & SDL_APPINPUTFOCUS) |
79 | else if (event->active.state & SDL_APPINPUTFOCUS) |
96 | { |
|
|
97 | printf ("input "); |
80 | printf ("input "); |
98 | } |
|
|
99 | |
81 | |
100 | printf ("focus\n"); |
82 | printf ("focus\n"); |
101 | break; |
83 | break; |
102 | |
84 | |
103 | case SDL_KEYDOWN: |
85 | case SDL_KEYDOWN: |
|
|
86 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
|
|
87 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
|
|
88 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle++; |
|
|
89 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle--; |
|
|
90 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2++; |
|
|
91 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2--; |
|
|
92 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y--; |
|
|
93 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y++; |
|
|
94 | if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
|
|
95 | if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; |
|
|
96 | |
104 | if (event->key.keysym.sym == SDLK_ESCAPE) |
97 | if (event->key.keysym.sym == SDLK_ESCAPE) |
105 | { |
|
|
106 | done = 1; |
98 | done = 1; |
107 | } |
|
|
108 | |
99 | |
109 | if ((event->key.keysym.sym == SDLK_g) && |
100 | if ((event->key.keysym.sym == SDLK_g) && |
110 | (event->key.keysym.mod & KMOD_CTRL)) |
101 | (event->key.keysym.mod & KMOD_CTRL)) |
111 | { |
|
|
112 | HotKey_ToggleGrab (); |
102 | HotKey_ToggleGrab (); |
113 | } |
|
|
114 | |
103 | |
115 | if ((event->key.keysym.sym == SDLK_z) && |
104 | if ((event->key.keysym.sym == SDLK_z) && |
116 | (event->key.keysym.mod & KMOD_CTRL)) |
105 | (event->key.keysym.mod & KMOD_CTRL)) |
117 | { |
|
|
118 | HotKey_Iconify (); |
106 | HotKey_Iconify (); |
119 | } |
|
|
120 | |
107 | |
121 | if ((event->key.keysym.sym == SDLK_RETURN) && |
108 | if ((event->key.keysym.sym == SDLK_RETURN) && |
122 | (event->key.keysym.mod & KMOD_ALT)) |
109 | (event->key.keysym.mod & KMOD_ALT)) |
123 | { |
|
|
124 | HotKey_ToggleFullScreen (); |
110 | HotKey_ToggleFullScreen (); |
125 | } |
|
|
126 | |
111 | |
127 | printf ("key '%s' pressed\n", SDL_GetKeyName (event->key.keysym.sym)); |
112 | break; |
|
|
113 | |
|
|
114 | case SDL_KEYUP: |
|
|
115 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
|
|
116 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
|
|
117 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle++; |
|
|
118 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle--; |
|
|
119 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2--; |
|
|
120 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2++; |
|
|
121 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y++; |
|
|
122 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y--; |
128 | break; |
123 | break; |
129 | |
124 | |
130 | case SDL_QUIT: |
125 | case SDL_QUIT: |
131 | done = 1; |
126 | done = 1; |
132 | break; |
127 | break; |
133 | } |
128 | } |
134 | |
129 | |
135 | return (done); |
130 | return (done); |
136 | } |
131 | } |
137 | |
132 | |
138 | void |
133 | void draw_floor (int size, int dx, int dy, int dz) |
139 | SDL_GL_Enter2DMode () |
|
|
140 | { |
134 | { |
141 | SDL_Surface *screen = SDL_GetVideoSurface (); |
135 | int x, z, ry; |
142 | |
136 | |
143 | /* Note, there may be other things you need to change, |
137 | for (x = 0; x < 10; x++) |
144 | depending on how you have your OpenGL state set up. |
|
|
145 | */ |
|
|
146 | glPushAttrib (GL_ENABLE_BIT); |
|
|
147 | glDisable (GL_DEPTH_TEST); |
|
|
148 | glDisable (GL_CULL_FACE); |
|
|
149 | glEnable (GL_TEXTURE_2D); |
|
|
150 | |
|
|
151 | /* This allows alpha blending of 2D textures with the scene */ |
|
|
152 | glEnable (GL_BLEND); |
|
|
153 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
154 | |
|
|
155 | glViewport (0, 0, screen->w, screen->h); |
|
|
156 | |
|
|
157 | glMatrixMode (GL_PROJECTION); |
|
|
158 | glPushMatrix (); |
|
|
159 | glLoadIdentity (); |
|
|
160 | |
|
|
161 | glOrtho (0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0); |
|
|
162 | |
|
|
163 | glMatrixMode (GL_MODELVIEW); |
|
|
164 | glPushMatrix (); |
|
|
165 | glLoadIdentity (); |
|
|
166 | |
|
|
167 | glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
|
|
168 | } |
|
|
169 | |
|
|
170 | void |
|
|
171 | SDL_GL_Leave2DMode () |
|
|
172 | { |
|
|
173 | glMatrixMode (GL_MODELVIEW); |
|
|
174 | glPopMatrix (); |
|
|
175 | |
|
|
176 | glMatrixMode (GL_PROJECTION); |
|
|
177 | glPopMatrix (); |
|
|
178 | |
|
|
179 | glPopAttrib (); |
|
|
180 | } |
|
|
181 | |
|
|
182 | /* Quick utility function for texture creation */ |
|
|
183 | static int |
|
|
184 | power_of_two (int input) |
|
|
185 | { |
|
|
186 | int value = 1; |
|
|
187 | |
|
|
188 | while (value < input) |
|
|
189 | { |
|
|
190 | value <<= 1; |
|
|
191 | } |
138 | { |
192 | return value; |
139 | for (z = 0; z < 10; z++) |
193 | } |
140 | { |
|
|
141 | vector<vertex_t2f_n3f_v3f> pts; |
|
|
142 | pts.push_back (vertex_t2f_n3f_v3f (point ( 0, 0, 0), vec3 (0, 1, 0), tex2 (0, 0))); |
|
|
143 | 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))); |
|
|
145 | pts.push_back (vertex_t2f_n3f_v3f (point (size, 0, 0), vec3 (0, 1, 0), tex2 (1, 0))); |
194 | |
146 | |
195 | GLuint |
147 | geometry_quads *q = new geometry_quads; |
196 | SDL_GL_LoadTexture (SDL_Surface * surface, GLfloat * texcoord) |
148 | q->m = new simple_material; |
197 | { |
149 | q->set (pts); |
198 | GLuint texture; |
150 | entity *e = new entity (q); |
199 | int w, h; |
151 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
200 | SDL_Surface *image; |
152 | e->show (); |
201 | SDL_Rect area; |
153 | } |
202 | Uint32 saved_flags; |
|
|
203 | Uint8 saved_alpha; |
|
|
204 | |
|
|
205 | /* Use the surface width and height expanded to powers of 2 */ |
|
|
206 | w = power_of_two (surface->w); |
|
|
207 | h = power_of_two (surface->h); |
|
|
208 | texcoord[0] = 0.0f; /* Min X */ |
|
|
209 | texcoord[1] = 0.0f; /* Min Y */ |
|
|
210 | texcoord[2] = (GLfloat) surface->w / w; /* Max X */ |
|
|
211 | texcoord[3] = (GLfloat) surface->h / h; /* Max Y */ |
|
|
212 | |
|
|
213 | image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32, |
|
|
214 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ |
|
|
215 | 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 |
|
|
216 | #else |
|
|
217 | 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF |
|
|
218 | #endif |
|
|
219 | ); |
|
|
220 | if (image == NULL) |
|
|
221 | { |
154 | } |
222 | return 0; |
155 | } |
|
|
156 | |
|
|
157 | void draw_test_nurb () |
|
|
158 | { |
|
|
159 | geometry_nurbs *q = new geometry_nurbs; |
|
|
160 | q->set (); |
|
|
161 | entity *e = new entity (q); |
|
|
162 | e->move (vec3 (10, 3, -4)); |
|
|
163 | e->show (); |
|
|
164 | } |
|
|
165 | |
|
|
166 | void fisch (vec3 center, GLfloat radius, int depth) |
|
|
167 | { |
|
|
168 | entity *planet = new entity (new geometry_sphere (radius)); |
|
|
169 | planet->move (center); |
|
|
170 | planet->show (); |
|
|
171 | |
|
|
172 | if (--depth) |
223 | } |
173 | { |
|
|
174 | GLfloat r2 = radius * .1F; |
|
|
175 | GLfloat r3 = radius + r2; |
224 | |
176 | |
225 | /* Save the alpha blending attributes */ |
177 | fisch (center + vec3 (r3, 0, 0), r2, depth); |
226 | saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
178 | fisch (center + vec3 (0, 0, r3), r2, depth); |
227 | saved_alpha = surface->format->alpha; |
179 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
228 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
|
|
229 | { |
180 | } |
230 | SDL_SetAlpha (surface, 0, 0); |
|
|
231 | } |
|
|
232 | |
|
|
233 | /* Copy the surface into the GL texture image */ |
|
|
234 | area.x = 0; |
|
|
235 | area.y = 0; |
|
|
236 | area.w = surface->w; |
|
|
237 | area.h = surface->h; |
|
|
238 | SDL_BlitSurface (surface, &area, image, &area); |
|
|
239 | |
|
|
240 | /* Restore the alpha blending attributes */ |
|
|
241 | if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
|
|
242 | { |
|
|
243 | SDL_SetAlpha (surface, saved_flags, saved_alpha); |
|
|
244 | } |
|
|
245 | |
|
|
246 | /* Create an OpenGL texture for the image */ |
|
|
247 | glGenTextures (1, &texture); |
|
|
248 | glBindTexture (GL_TEXTURE_2D, texture); |
|
|
249 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
|
250 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
|
251 | glTexImage2D (GL_TEXTURE_2D, |
|
|
252 | 0, |
|
|
253 | GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
|
|
254 | SDL_FreeSurface (image); /* No longer needed */ |
|
|
255 | |
|
|
256 | return texture; |
|
|
257 | } |
181 | } |
258 | |
182 | |
|
|
183 | extern void draw_level (); |
259 | int |
184 | int |
260 | RunGLTest (int argc, char *argv[], |
185 | RunGLTest (int argc, char *argv[], |
261 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
186 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
262 | { |
187 | { |
263 | int i; |
188 | int i; |
264 | int rgb_size[3]; |
189 | int rgb_size[3]; |
265 | int w = 640; |
190 | int w = 640; |
266 | int h = 480; |
191 | int h = 480; |
267 | int done = 0; |
192 | int done = 0; |
268 | int frames; |
193 | int frames; |
269 | Uint32 start_time, this_time; |
|
|
270 | Uint32 video_flags; |
194 | Uint32 video_flags; |
271 | int value; |
195 | int value; |
|
|
196 | GLenum gl_error; |
272 | |
197 | |
273 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
198 | if (SDL_Init (SDL_INIT_VIDEO) < 0) |
274 | { |
199 | { |
275 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
200 | fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
276 | exit (1); |
201 | exit (1); |
… | |
… | |
314 | rgb_size[0] = 8; |
239 | rgb_size[0] = 8; |
315 | rgb_size[1] = 8; |
240 | rgb_size[1] = 8; |
316 | rgb_size[2] = 8; |
241 | rgb_size[2] = 8; |
317 | break; |
242 | break; |
318 | } |
243 | } |
|
|
244 | |
319 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
245 | SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); |
320 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
246 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); |
321 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
247 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); |
322 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
248 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
323 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
249 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
… | |
… | |
362 | printf ("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, |
288 | printf ("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, |
363 | value); |
289 | value); |
364 | } |
290 | } |
365 | |
291 | |
366 | /* Set the window manager title bar */ |
292 | /* Set the window manager title bar */ |
367 | SDL_WM_SetCaption ("SDL GL test", "testgl"); |
293 | SDL_WM_SetCaption ("libgender rendering test", "gendertest"); |
368 | |
294 | |
369 | /* Set the gamma for the window */ |
295 | /* Set the gamma for the window */ |
370 | if (gamma != 0.0) |
296 | if (gamma != 0.0) |
371 | SDL_SetGamma (gamma, gamma, gamma); |
297 | SDL_SetGamma (gamma, gamma, gamma); |
372 | |
298 | |
373 | view v; |
299 | entity *planet = new entity (new geometry_sphere (10)); |
|
|
300 | planet->move (vec3 (0, 0, -20)); |
|
|
301 | planet->show (); |
|
|
302 | |
|
|
303 | #if 1 |
|
|
304 | for (int i = 0; i < 20; i++) |
|
|
305 | { |
|
|
306 | // load a entity |
|
|
307 | txtprt_parser p; |
|
|
308 | geometry *g; |
|
|
309 | try |
|
|
310 | { |
|
|
311 | g = p.read ("test.blasc"); |
|
|
312 | } |
|
|
313 | catch (txtprt_i_exception & e) |
|
|
314 | { |
|
|
315 | cout << "ERR: " << e.msg << endl; |
|
|
316 | } |
|
|
317 | |
|
|
318 | entity *e = new entity (g); |
|
|
319 | e->move (vec3 (i*5, -3, -i*10)); |
|
|
320 | e->show (); |
|
|
321 | } |
|
|
322 | |
|
|
323 | { |
|
|
324 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
|
|
325 | //entity *planet = new entity (new geometry_sphere (1e9)); |
|
|
326 | //planet->move (vec3 (0, 0, -1.5e9)); |
|
|
327 | //planet->show (); |
|
|
328 | } |
|
|
329 | |
|
|
330 | { |
|
|
331 | entity *planet = new entity (new geometry_sphere (4e15)); |
|
|
332 | planet->move (vec3 (0, 0, 1e17)); |
|
|
333 | planet->show (); |
|
|
334 | } |
|
|
335 | |
|
|
336 | draw_floor (10, -500, -10, -1000); |
|
|
337 | draw_level (); |
|
|
338 | //draw_test_nurb (); |
|
|
339 | #endif |
|
|
340 | |
|
|
341 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
|
|
342 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
374 | v.p = point (0, 0, 0); |
343 | camera.p = point (0, 0, 10); |
375 | v.d = vec3 (0, 0, -1); |
344 | camera.d = vec3 (0, 0, -1); |
376 | v.u = vec3 (0, 1, 0); |
345 | camera.u = vec3 (0, 1, 0); |
377 | v.w = w; v.h = h; |
346 | camera.w = w; camera.h = h; |
378 | v.fov = 90; |
347 | camera.fov = 40.; |
379 | |
348 | |
380 | glMatrixMode (GL_MODELVIEW); |
349 | glEnable (GL_CULL_FACE); |
381 | glLoadIdentity (); |
|
|
382 | |
|
|
383 | glEnable (GL_DEPTH_TEST); |
350 | glDisable (GL_ALPHA_TEST); |
|
|
351 | glDisable (GL_BLEND); |
384 | |
352 | |
385 | glDepthFunc (GL_LESS); |
353 | init_shaders (); |
386 | |
354 | |
387 | glShadeModel (GL_SMOOTH); |
355 | osama_material osa_mat; |
388 | GLfloat ambient[4] = { 1, 1, 1, 1 }; |
|
|
389 | glEnable (GL_LIGHTING); |
|
|
390 | glEnable (GL_COLOR_MATERIAL); |
|
|
391 | glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient); |
|
|
392 | |
356 | |
393 | /* Loop until done. */ |
357 | /* Loop until done. */ |
394 | start_time = SDL_GetTicks (); |
|
|
395 | frames = 0; |
358 | frames = 0; |
|
|
359 | |
396 | while (!done) |
360 | while (!done) |
397 | { |
361 | { |
398 | GLenum gl_error; |
|
|
399 | char *sdl_error; |
362 | char *sdl_error; |
400 | SDL_Event event; |
363 | SDL_Event event; |
401 | |
364 | |
402 | /* Do our drawing, too. */ |
365 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
403 | glClearColor (0.0, 0.0, 0.0, 1.0); |
366 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
404 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
405 | |
367 | |
406 | static GLfloat ry; |
368 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
407 | ry += 0.1; |
369 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
408 | v.d.x = cos (ry); |
|
|
409 | v.d.z = sin (ry); |
|
|
410 | |
370 | |
411 | draw_context c; |
371 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
412 | v.draw (c); |
372 | camera.u = cross (camera.d, right); |
|
|
373 | |
|
|
374 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
|
|
375 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
|
|
376 | |
|
|
377 | osa_mat.begin (); |
|
|
378 | |
|
|
379 | camera.begin (); |
|
|
380 | camera.render (view::DEPTH); |
|
|
381 | camera.render (view::POSTDEPTH); |
|
|
382 | camera.render (view::LIGHTED); |
|
|
383 | camera.end (); |
413 | |
384 | |
414 | SDL_GL_SwapBuffers (); |
385 | SDL_GL_SwapBuffers (); |
|
|
386 | timer.frame (); |
415 | |
387 | |
|
|
388 | osa_mat.end (); |
|
|
389 | |
|
|
390 | #if 0 |
416 | /* Check for error conditions. */ |
391 | /* Check for error conditions. */ |
417 | gl_error = glGetError (); |
392 | gl_error = glGetError (); |
418 | |
393 | |
419 | if (gl_error != GL_NO_ERROR) |
|
|
420 | fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
394 | if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
421 | |
395 | |
422 | sdl_error = SDL_GetError (); |
396 | sdl_error = SDL_GetError (); |
423 | |
397 | |
424 | if (sdl_error[0] != '\0') |
398 | if (sdl_error[0] != '\0') |
425 | { |
399 | { |
426 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
400 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
427 | SDL_ClearError (); |
401 | SDL_ClearError (); |
428 | } |
402 | } |
429 | |
403 | |
430 | /* Allow the user to see what's happening */ |
404 | /* Allow the user to see what's happening */ |
431 | SDL_Delay (20); |
405 | //SDL_Delay (40); |
|
|
406 | #endif |
432 | |
407 | |
433 | /* Check if there's a pending event. */ |
408 | /* Check if there's a pending event. */ |
434 | while (SDL_PollEvent (&event)) |
409 | while (SDL_PollEvent (&event)) |
435 | { |
|
|
436 | done = HandleEvent (&event); |
410 | done = HandleEvent (&event); |
437 | } |
411 | |
|
|
412 | |
438 | ++frames; |
413 | ++frames; |
439 | } |
|
|
440 | |
|
|
441 | /* Print out the frames per second */ |
|
|
442 | this_time = SDL_GetTicks (); |
|
|
443 | if (this_time != start_time) |
|
|
444 | { |
|
|
445 | printf ("%2.2f FPS\n", |
|
|
446 | ((float) frames / (this_time - start_time)) * 1000.0); |
|
|
447 | } |
414 | } |
448 | |
415 | |
449 | if (global_image) |
416 | if (global_image) |
450 | { |
417 | { |
451 | SDL_FreeSurface (global_image); |
418 | SDL_FreeSurface (global_image); |
… | |
… | |
459 | |
426 | |
460 | /* Destroy our GL context, etc. */ |
427 | /* Destroy our GL context, etc. */ |
461 | SDL_Quit (); |
428 | SDL_Quit (); |
462 | return (0); |
429 | return (0); |
463 | } |
430 | } |
464 | |
|
|
465 | int |
431 | int |
466 | main (int argc, char *argv[]) |
432 | main (int argc, char *argv[]) |
467 | { |
433 | { |
468 | int i, logo; |
434 | int i, logo; |
469 | int numtests; |
435 | int numtests; |
… | |
… | |
471 | int slowly; |
437 | int slowly; |
472 | float gamma = 0.0; |
438 | float gamma = 0.0; |
473 | int noframe = 0; |
439 | int noframe = 0; |
474 | int fsaa = 0; |
440 | int fsaa = 0; |
475 | |
441 | |
476 | // load a entity |
442 | shader::debdebdebdebug ();//D |
477 | txtprt_parser p; |
|
|
478 | try { |
|
|
479 | entity *e = p.read ("test.blasc"); |
|
|
480 | } catch (txtprt_i_exception & e) { |
|
|
481 | cout << "ERR: " << e.msg << endl; |
|
|
482 | } |
|
|
483 | // now please draw my entity ;) |
|
|
484 | |
443 | |
485 | logo = 0; |
444 | logo = 0; |
486 | slowly = 0; |
445 | slowly = 0; |
487 | numtests = 1; |
446 | numtests = 1; |
488 | for (i = 1; argv[i]; ++i) |
447 | for (i = 1; argv[i]; ++i) |
… | |
… | |
517 | ("Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa]\n", |
476 | ("Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa]\n", |
518 | argv[0]); |
477 | argv[0]); |
519 | exit (0); |
478 | exit (0); |
520 | } |
479 | } |
521 | } |
480 | } |
|
|
481 | |
522 | for (i = 0; i < numtests; ++i) |
482 | for (i = 0; i < numtests; ++i) |
523 | { |
|
|
524 | RunGLTest (argc, argv, logo, slowly, bpp, gamma, noframe, fsaa); |
483 | RunGLTest (argc, argv, logo, slowly, bpp, gamma, noframe, fsaa); |
525 | } |
484 | |
526 | return 0; |
485 | return 0; |
527 | } |
486 | } |