Mercurial > sdl-ios-xcode
comparison test/testgl.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 9d940db55a91 |
children | 8d384b647307 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
17 #define SHADED_CUBE | 17 #define SHADED_CUBE |
18 | 18 |
19 /* Define this to be the name of the logo image to use with -logo */ | 19 /* Define this to be the name of the logo image to use with -logo */ |
20 #define LOGO_FILE "icon.bmp" | 20 #define LOGO_FILE "icon.bmp" |
21 | 21 |
22 /* The SDL_OPENGLBLIT interface is deprecated. | |
23 The code is still available for benchmark purposes though. | |
24 */ | |
25 | |
26 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE; | |
27 | |
28 static SDL_Surface *global_image = NULL; | 22 static SDL_Surface *global_image = NULL; |
29 static GLuint global_texture = 0; | 23 static GLuint global_texture = 0; |
30 static GLuint cursor_texture = 0; | 24 static GLuint cursor_texture = 0; |
31 | 25 |
32 /**********************************************************************/ | 26 /**********************************************************************/ |
33 | 27 |
34 void HotKey_ToggleFullScreen(void) | 28 void |
35 { | 29 HotKey_ToggleFullScreen(void) |
36 SDL_Surface *screen; | 30 { |
37 | 31 SDL_Surface *screen; |
38 screen = SDL_GetVideoSurface(); | 32 |
39 if ( SDL_WM_ToggleFullScreen(screen) ) { | 33 screen = SDL_GetVideoSurface(); |
40 printf("Toggled fullscreen mode - now %s\n", | 34 if (SDL_WM_ToggleFullScreen(screen)) { |
41 (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed"); | 35 printf("Toggled fullscreen mode - now %s\n", |
42 } else { | 36 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
43 printf("Unable to toggle fullscreen mode\n"); | 37 } else { |
44 } | 38 printf("Unable to toggle fullscreen mode\n"); |
45 } | 39 } |
46 | 40 } |
47 void HotKey_ToggleGrab(void) | 41 |
48 { | 42 void |
49 SDL_GrabMode mode; | 43 HotKey_ToggleGrab(void) |
50 | 44 { |
51 printf("Ctrl-G: toggling input grab!\n"); | 45 SDL_GrabMode mode; |
52 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); | 46 |
53 if ( mode == SDL_GRAB_ON ) { | 47 printf("Ctrl-G: toggling input grab!\n"); |
54 printf("Grab was on\n"); | 48 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); |
55 } else { | 49 if (mode == SDL_GRAB_ON) { |
56 printf("Grab was off\n"); | 50 printf("Grab was on\n"); |
57 } | 51 } else { |
58 mode = SDL_WM_GrabInput(!mode); | 52 printf("Grab was off\n"); |
59 if ( mode == SDL_GRAB_ON ) { | 53 } |
60 printf("Grab is now on\n"); | 54 mode = SDL_WM_GrabInput(!mode); |
61 } else { | 55 if (mode == SDL_GRAB_ON) { |
62 printf("Grab is now off\n"); | 56 printf("Grab is now on\n"); |
63 } | 57 } else { |
64 } | 58 printf("Grab is now off\n"); |
65 | 59 } |
66 void HotKey_Iconify(void) | 60 } |
67 { | 61 |
68 printf("Ctrl-Z: iconifying window!\n"); | 62 void |
69 SDL_WM_IconifyWindow(); | 63 HotKey_Iconify(void) |
70 } | 64 { |
71 | 65 printf("Ctrl-Z: iconifying window!\n"); |
72 int HandleEvent(SDL_Event *event) | 66 SDL_WM_IconifyWindow(); |
73 { | 67 } |
74 int done; | 68 |
75 | 69 int |
76 done = 0; | 70 HandleEvent(SDL_Event * event) |
77 switch( event->type ) { | 71 { |
78 case SDL_ACTIVEEVENT: | 72 int done; |
79 /* See what happened */ | 73 |
80 printf( "app %s ", event->active.gain ? "gained" : "lost" ); | 74 done = 0; |
81 if ( event->active.state & SDL_APPACTIVE ) { | 75 switch (event->type) { |
82 printf( "active " ); | 76 case SDL_ACTIVEEVENT: |
83 } else if ( event->active.state & SDL_APPMOUSEFOCUS ) { | 77 /* See what happened */ |
84 printf( "mouse " ); | 78 printf("app %s ", event->active.gain ? "gained" : "lost"); |
85 } else if ( event->active.state & SDL_APPINPUTFOCUS ) { | 79 if (event->active.state & SDL_APPACTIVE) { |
86 printf( "input " ); | 80 printf("active "); |
87 } | 81 } else if (event->active.state & SDL_APPMOUSEFOCUS) { |
88 printf( "focus\n" ); | 82 printf("mouse "); |
89 break; | 83 } else if (event->active.state & SDL_APPINPUTFOCUS) { |
90 | 84 printf("input "); |
91 | 85 } |
92 case SDL_KEYDOWN: | 86 printf("focus\n"); |
93 if ( event->key.keysym.sym == SDLK_ESCAPE ) { | 87 break; |
94 done = 1; | 88 |
95 } | 89 |
96 if ( (event->key.keysym.sym == SDLK_g) && | 90 case SDL_KEYDOWN: |
97 (event->key.keysym.mod & KMOD_CTRL) ) { | 91 if (event->key.keysym.sym == SDLK_ESCAPE) { |
98 HotKey_ToggleGrab(); | 92 done = 1; |
99 } | 93 } |
100 if ( (event->key.keysym.sym == SDLK_z) && | 94 if ((event->key.keysym.sym == SDLK_g) && |
101 (event->key.keysym.mod & KMOD_CTRL) ) { | 95 (event->key.keysym.mod & KMOD_CTRL)) { |
102 HotKey_Iconify(); | 96 HotKey_ToggleGrab(); |
103 } | 97 } |
104 if ( (event->key.keysym.sym == SDLK_RETURN) && | 98 if ((event->key.keysym.sym == SDLK_z) && |
105 (event->key.keysym.mod & KMOD_ALT) ) { | 99 (event->key.keysym.mod & KMOD_CTRL)) { |
106 HotKey_ToggleFullScreen(); | 100 HotKey_Iconify(); |
107 } | 101 } |
108 printf("key '%s' pressed\n", | 102 if ((event->key.keysym.sym == SDLK_RETURN) && |
109 SDL_GetKeyName(event->key.keysym.sym)); | 103 (event->key.keysym.mod & KMOD_ALT)) { |
110 break; | 104 HotKey_ToggleFullScreen(); |
111 case SDL_QUIT: | 105 } |
112 done = 1; | 106 printf("key '%s' pressed\n", SDL_GetKeyName(event->key.keysym.sym)); |
113 break; | 107 break; |
114 } | 108 case SDL_QUIT: |
115 return(done); | 109 done = 1; |
116 } | 110 break; |
117 | 111 } |
118 void SDL_GL_Enter2DMode() | 112 return (done); |
119 { | 113 } |
120 SDL_Surface *screen = SDL_GetVideoSurface(); | 114 |
121 | 115 void |
122 /* Note, there may be other things you need to change, | 116 SDL_GL_Enter2DMode() |
123 depending on how you have your OpenGL state set up. | 117 { |
124 */ | 118 SDL_Surface *screen = SDL_GetVideoSurface(); |
125 glPushAttrib(GL_ENABLE_BIT); | 119 |
126 glDisable(GL_DEPTH_TEST); | 120 /* Note, there may be other things you need to change, |
127 glDisable(GL_CULL_FACE); | 121 depending on how you have your OpenGL state set up. |
128 glEnable(GL_TEXTURE_2D); | 122 */ |
129 | 123 glPushAttrib(GL_ENABLE_BIT); |
130 /* This allows alpha blending of 2D textures with the scene */ | 124 glDisable(GL_DEPTH_TEST); |
131 glEnable(GL_BLEND); | 125 glDisable(GL_CULL_FACE); |
132 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 126 glEnable(GL_TEXTURE_2D); |
133 | 127 |
134 glViewport(0, 0, screen->w, screen->h); | 128 /* This allows alpha blending of 2D textures with the scene */ |
135 | 129 glEnable(GL_BLEND); |
136 glMatrixMode(GL_PROJECTION); | 130 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
137 glPushMatrix(); | 131 |
138 glLoadIdentity(); | 132 glViewport(0, 0, screen->w, screen->h); |
139 | 133 |
140 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0); | 134 glMatrixMode(GL_PROJECTION); |
141 | 135 glPushMatrix(); |
142 glMatrixMode(GL_MODELVIEW); | 136 glLoadIdentity(); |
143 glPushMatrix(); | 137 |
144 glLoadIdentity(); | 138 glOrtho(0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0); |
145 | 139 |
146 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | 140 glMatrixMode(GL_MODELVIEW); |
147 } | 141 glPushMatrix(); |
148 | 142 glLoadIdentity(); |
149 void SDL_GL_Leave2DMode() | 143 |
150 { | 144 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
151 glMatrixMode(GL_MODELVIEW); | 145 } |
152 glPopMatrix(); | 146 |
153 | 147 void |
154 glMatrixMode(GL_PROJECTION); | 148 SDL_GL_Leave2DMode() |
155 glPopMatrix(); | 149 { |
156 | 150 glMatrixMode(GL_MODELVIEW); |
157 glPopAttrib(); | 151 glPopMatrix(); |
152 | |
153 glMatrixMode(GL_PROJECTION); | |
154 glPopMatrix(); | |
155 | |
156 glPopAttrib(); | |
158 } | 157 } |
159 | 158 |
160 /* Quick utility function for texture creation */ | 159 /* Quick utility function for texture creation */ |
161 static int power_of_two(int input) | 160 static int |
162 { | 161 power_of_two(int input) |
163 int value = 1; | 162 { |
164 | 163 int value = 1; |
165 while ( value < input ) { | 164 |
166 value <<= 1; | 165 while (value < input) { |
167 } | 166 value <<= 1; |
168 return value; | 167 } |
169 } | 168 return value; |
170 | 169 } |
171 GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) | 170 |
172 { | 171 GLuint |
173 GLuint texture; | 172 SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord) |
174 int w, h; | 173 { |
175 SDL_Surface *image; | 174 GLuint texture; |
176 SDL_Rect area; | 175 int w, h; |
177 Uint32 saved_flags; | 176 SDL_Surface *image; |
178 Uint8 saved_alpha; | 177 SDL_Rect area; |
179 | 178 Uint32 saved_flags; |
180 /* Use the surface width and height expanded to powers of 2 */ | 179 Uint8 saved_alpha; |
181 w = power_of_two(surface->w); | 180 |
182 h = power_of_two(surface->h); | 181 /* Use the surface width and height expanded to powers of 2 */ |
183 texcoord[0] = 0.0f; /* Min X */ | 182 w = power_of_two(surface->w); |
184 texcoord[1] = 0.0f; /* Min Y */ | 183 h = power_of_two(surface->h); |
185 texcoord[2] = (GLfloat)surface->w / w; /* Max X */ | 184 texcoord[0] = 0.0f; /* Min X */ |
186 texcoord[3] = (GLfloat)surface->h / h; /* Max Y */ | 185 texcoord[1] = 0.0f; /* Min Y */ |
187 | 186 texcoord[2] = (GLfloat) surface->w / w; /* Max X */ |
188 image = SDL_CreateRGBSurface( | 187 texcoord[3] = (GLfloat) surface->h / h; /* Max Y */ |
189 SDL_SWSURFACE, | 188 |
190 w, h, | 189 image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, |
191 32, | 190 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ |
192 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ | 191 0x000000FF, |
193 0x000000FF, | 192 0x0000FF00, 0x00FF0000, 0xFF000000 |
194 0x0000FF00, | |
195 0x00FF0000, | |
196 0xFF000000 | |
197 #else | 193 #else |
198 0xFF000000, | 194 0xFF000000, |
199 0x00FF0000, | 195 0x00FF0000, 0x0000FF00, 0x000000FF |
200 0x0000FF00, | |
201 0x000000FF | |
202 #endif | 196 #endif |
203 ); | 197 ); |
204 if ( image == NULL ) { | 198 if (image == NULL) { |
205 return 0; | 199 return 0; |
206 } | 200 } |
207 | 201 |
208 /* Save the alpha blending attributes */ | 202 /* Save the alpha blending attributes */ |
209 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); | 203 saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
210 saved_alpha = surface->format->alpha; | 204 saved_alpha = surface->format->alpha; |
211 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | 205 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { |
212 SDL_SetAlpha(surface, 0, 0); | 206 SDL_SetAlpha(surface, 0, 0); |
213 } | 207 } |
214 | 208 |
215 /* Copy the surface into the GL texture image */ | 209 /* Copy the surface into the GL texture image */ |
216 area.x = 0; | 210 area.x = 0; |
217 area.y = 0; | 211 area.y = 0; |
218 area.w = surface->w; | 212 area.w = surface->w; |
219 area.h = surface->h; | 213 area.h = surface->h; |
220 SDL_BlitSurface(surface, &area, image, &area); | 214 SDL_BlitSurface(surface, &area, image, &area); |
221 | 215 |
222 /* Restore the alpha blending attributes */ | 216 /* Restore the alpha blending attributes */ |
223 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | 217 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { |
224 SDL_SetAlpha(surface, saved_flags, saved_alpha); | 218 SDL_SetAlpha(surface, saved_flags, saved_alpha); |
225 } | 219 } |
226 | 220 |
227 /* Create an OpenGL texture for the image */ | 221 /* Create an OpenGL texture for the image */ |
228 glGenTextures(1, &texture); | 222 glGenTextures(1, &texture); |
229 glBindTexture(GL_TEXTURE_2D, texture); | 223 glBindTexture(GL_TEXTURE_2D, texture); |
230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
232 glTexImage2D(GL_TEXTURE_2D, | 226 glTexImage2D(GL_TEXTURE_2D, |
233 0, | 227 0, |
234 GL_RGBA, | 228 GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
235 w, h, | 229 SDL_FreeSurface(image); /* No longer needed */ |
236 0, | 230 |
237 GL_RGBA, | 231 return texture; |
238 GL_UNSIGNED_BYTE, | 232 } |
239 image->pixels); | 233 |
240 SDL_FreeSurface(image); /* No longer needed */ | 234 void |
241 | 235 DrawLogoCursor(void) |
242 return texture; | 236 { |
243 } | 237 static GLfloat texMinX, texMinY; |
244 | 238 static GLfloat texMaxX, texMaxY; |
245 void DrawLogoCursor(void) | 239 static int w, h; |
246 { | 240 int x, y; |
247 static GLfloat texMinX, texMinY; | 241 |
248 static GLfloat texMaxX, texMaxY; | 242 if (!cursor_texture) { |
249 static int w, h; | 243 SDL_Surface *image; |
250 int x, y; | 244 GLfloat texcoord[4]; |
251 | 245 |
252 if ( ! cursor_texture ) { | 246 /* Load the image (could use SDL_image library here) */ |
253 SDL_Surface *image; | 247 image = SDL_LoadBMP(LOGO_FILE); |
254 GLfloat texcoord[4]; | 248 if (image == NULL) { |
255 | 249 return; |
256 /* Load the image (could use SDL_image library here) */ | 250 } |
257 image = SDL_LoadBMP(LOGO_FILE); | 251 w = image->w; |
258 if ( image == NULL ) { | 252 h = image->h; |
259 return; | 253 |
260 } | 254 /* Convert the image into an OpenGL texture */ |
261 w = image->w; | 255 cursor_texture = SDL_GL_LoadTexture(image, texcoord); |
262 h = image->h; | 256 |
263 | 257 /* Make texture coordinates easy to understand */ |
264 /* Convert the image into an OpenGL texture */ | 258 texMinX = texcoord[0]; |
265 cursor_texture = SDL_GL_LoadTexture(image, texcoord); | 259 texMinY = texcoord[1]; |
266 | 260 texMaxX = texcoord[2]; |
267 /* Make texture coordinates easy to understand */ | 261 texMaxY = texcoord[3]; |
268 texMinX = texcoord[0]; | 262 |
269 texMinY = texcoord[1]; | 263 /* We don't need the original image anymore */ |
270 texMaxX = texcoord[2]; | 264 SDL_FreeSurface(image); |
271 texMaxY = texcoord[3]; | 265 |
272 | 266 /* Make sure that the texture conversion is okay */ |
273 /* We don't need the original image anymore */ | 267 if (!cursor_texture) { |
274 SDL_FreeSurface(image); | 268 return; |
275 | 269 } |
276 /* Make sure that the texture conversion is okay */ | 270 } |
277 if ( ! cursor_texture ) { | 271 |
278 return; | 272 /* Move the image around */ |
279 } | 273 SDL_GetMouseState(&x, &y); |
280 } | 274 x -= w / 2; |
281 | 275 y -= h / 2; |
282 /* Move the image around */ | 276 |
283 SDL_GetMouseState(&x, &y); | 277 /* Show the image on the screen */ |
284 x -= w/2; | 278 SDL_GL_Enter2DMode(); |
285 y -= h/2; | 279 glBindTexture(GL_TEXTURE_2D, cursor_texture); |
286 | 280 glBegin(GL_TRIANGLE_STRIP); |
287 /* Show the image on the screen */ | 281 glTexCoord2f(texMinX, texMinY); |
288 SDL_GL_Enter2DMode(); | 282 glVertex2i(x, y); |
289 glBindTexture(GL_TEXTURE_2D, cursor_texture); | 283 glTexCoord2f(texMaxX, texMinY); |
290 glBegin(GL_TRIANGLE_STRIP); | 284 glVertex2i(x + w, y); |
291 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y ); | 285 glTexCoord2f(texMinX, texMaxY); |
292 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y ); | 286 glVertex2i(x, y + h); |
293 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h); | 287 glTexCoord2f(texMaxX, texMaxY); |
294 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h); | 288 glVertex2i(x + w, y + h); |
295 glEnd(); | 289 glEnd(); |
296 SDL_GL_Leave2DMode(); | 290 SDL_GL_Leave2DMode(); |
297 } | 291 } |
298 | 292 |
299 void DrawLogoTexture(void) | 293 void |
300 { | 294 DrawLogoTexture(void) |
301 static GLfloat texMinX, texMinY; | 295 { |
302 static GLfloat texMaxX, texMaxY; | 296 static GLfloat texMinX, texMinY; |
303 static int x = 0; | 297 static GLfloat texMaxX, texMaxY; |
304 static int y = 0; | 298 static int x = 0; |
305 static int w, h; | 299 static int y = 0; |
306 static int delta_x = 1; | 300 static int w, h; |
307 static int delta_y = 1; | 301 static int delta_x = 1; |
308 | 302 static int delta_y = 1; |
309 SDL_Surface *screen = SDL_GetVideoSurface(); | 303 |
310 | 304 SDL_Surface *screen = SDL_GetVideoSurface(); |
311 if ( ! global_texture ) { | 305 |
312 SDL_Surface *image; | 306 if (!global_texture) { |
313 GLfloat texcoord[4]; | 307 SDL_Surface *image; |
314 | 308 GLfloat texcoord[4]; |
315 /* Load the image (could use SDL_image library here) */ | 309 |
316 image = SDL_LoadBMP(LOGO_FILE); | 310 /* Load the image (could use SDL_image library here) */ |
317 if ( image == NULL ) { | 311 image = SDL_LoadBMP(LOGO_FILE); |
318 return; | 312 if (image == NULL) { |
319 } | 313 return; |
320 w = image->w; | 314 } |
321 h = image->h; | 315 w = image->w; |
322 | 316 h = image->h; |
323 /* Convert the image into an OpenGL texture */ | 317 |
324 global_texture = SDL_GL_LoadTexture(image, texcoord); | 318 /* Convert the image into an OpenGL texture */ |
325 | 319 global_texture = SDL_GL_LoadTexture(image, texcoord); |
326 /* Make texture coordinates easy to understand */ | 320 |
327 texMinX = texcoord[0]; | 321 /* Make texture coordinates easy to understand */ |
328 texMinY = texcoord[1]; | 322 texMinX = texcoord[0]; |
329 texMaxX = texcoord[2]; | 323 texMinY = texcoord[1]; |
330 texMaxY = texcoord[3]; | 324 texMaxX = texcoord[2]; |
331 | 325 texMaxY = texcoord[3]; |
332 /* We don't need the original image anymore */ | 326 |
333 SDL_FreeSurface(image); | 327 /* We don't need the original image anymore */ |
334 | 328 SDL_FreeSurface(image); |
335 /* Make sure that the texture conversion is okay */ | 329 |
336 if ( ! global_texture ) { | 330 /* Make sure that the texture conversion is okay */ |
337 return; | 331 if (!global_texture) { |
338 } | 332 return; |
339 } | 333 } |
340 | 334 } |
341 /* Move the image around */ | 335 |
342 x += delta_x; | 336 /* Move the image around */ |
343 if ( x < 0 ) { | 337 x += delta_x; |
344 x = 0; | 338 if (x < 0) { |
345 delta_x = -delta_x; | 339 x = 0; |
346 } else | 340 delta_x = -delta_x; |
347 if ( (x+w) > screen->w ) { | 341 } else if ((x + w) > screen->w) { |
348 x = screen->w-w; | 342 x = screen->w - w; |
349 delta_x = -delta_x; | 343 delta_x = -delta_x; |
350 } | 344 } |
351 y += delta_y; | 345 y += delta_y; |
352 if ( y < 0 ) { | 346 if (y < 0) { |
353 y = 0; | 347 y = 0; |
354 delta_y = -delta_y; | 348 delta_y = -delta_y; |
355 } else | 349 } else if ((y + h) > screen->h) { |
356 if ( (y+h) > screen->h ) { | 350 y = screen->h - h; |
357 y = screen->h-h; | 351 delta_y = -delta_y; |
358 delta_y = -delta_y; | 352 } |
359 } | 353 |
360 | 354 /* Show the image on the screen */ |
361 /* Show the image on the screen */ | 355 SDL_GL_Enter2DMode(); |
362 SDL_GL_Enter2DMode(); | 356 glBindTexture(GL_TEXTURE_2D, global_texture); |
363 glBindTexture(GL_TEXTURE_2D, global_texture); | 357 glBegin(GL_TRIANGLE_STRIP); |
364 glBegin(GL_TRIANGLE_STRIP); | 358 glTexCoord2f(texMinX, texMinY); |
365 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y ); | 359 glVertex2i(x, y); |
366 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y ); | 360 glTexCoord2f(texMaxX, texMinY); |
367 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h); | 361 glVertex2i(x + w, y); |
368 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h); | 362 glTexCoord2f(texMinX, texMaxY); |
369 glEnd(); | 363 glVertex2i(x, y + h); |
370 SDL_GL_Leave2DMode(); | 364 glTexCoord2f(texMaxX, texMaxY); |
371 } | 365 glVertex2i(x + w, y + h); |
372 | 366 glEnd(); |
373 /* This code is deprecated, but available for speed comparisons */ | 367 SDL_GL_Leave2DMode(); |
374 void DrawLogoBlit(void) | 368 } |
375 { | 369 |
376 static int x = 0; | 370 int |
377 static int y = 0; | 371 RunGLTest(int argc, char *argv[], |
378 static int w, h; | 372 int logo, int logocursor, int slowly, int bpp, float gamma, |
379 static int delta_x = 1; | 373 int noframe, int fsaa, int sync, int accel) |
380 static int delta_y = 1; | 374 { |
381 | 375 int i; |
382 SDL_Rect dst; | 376 int rgb_size[3]; |
383 SDL_Surface *screen = SDL_GetVideoSurface(); | 377 int w = 640; |
384 | 378 int h = 480; |
385 if ( global_image == NULL ) { | 379 int done = 0; |
386 SDL_Surface *temp; | 380 int frames; |
387 | 381 Uint32 start_time, this_time; |
388 /* Load the image (could use SDL_image library here) */ | 382 float color[8][3] = { {1.0, 1.0, 0.0}, |
389 temp = SDL_LoadBMP(LOGO_FILE); | 383 {1.0, 0.0, 0.0}, |
390 if ( temp == NULL ) { | 384 {0.0, 0.0, 0.0}, |
391 return; | 385 {0.0, 1.0, 0.0}, |
392 } | 386 {0.0, 1.0, 1.0}, |
393 w = temp->w; | 387 {1.0, 1.0, 1.0}, |
394 h = temp->h; | 388 {1.0, 0.0, 1.0}, |
395 | 389 {0.0, 0.0, 1.0} |
396 /* Convert the image into the screen format */ | 390 }; |
397 global_image = SDL_CreateRGBSurface( | 391 float cube[8][3] = { {0.5, 0.5, -0.5}, |
398 SDL_SWSURFACE, | 392 {0.5, -0.5, -0.5}, |
399 w, h, | 393 {-0.5, -0.5, -0.5}, |
400 screen->format->BitsPerPixel, | 394 {-0.5, 0.5, -0.5}, |
401 screen->format->Rmask, | 395 {-0.5, 0.5, 0.5}, |
402 screen->format->Gmask, | 396 {0.5, 0.5, 0.5}, |
403 screen->format->Bmask, | 397 {0.5, -0.5, 0.5}, |
404 screen->format->Amask); | 398 {-0.5, -0.5, 0.5} |
405 if ( global_image ) { | 399 }; |
406 SDL_BlitSurface(temp, NULL, global_image, NULL); | 400 Uint32 video_flags; |
407 } | 401 int value; |
408 SDL_FreeSurface(temp); | 402 |
409 | 403 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
410 /* Make sure that the texture conversion is okay */ | 404 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
411 if ( ! global_image ) { | 405 exit(1); |
412 return; | 406 } |
413 } | 407 |
414 } | 408 /* See if we should detect the display depth */ |
415 | 409 if (bpp == 0) { |
416 /* Move the image around | 410 if (SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8) { |
417 Note that we do not clear the old position. This is because we | 411 bpp = 8; |
418 perform a glClear() which clears the framebuffer and then only | 412 } else { |
419 update the new area. | 413 bpp = 16; /* More doesn't seem to work */ |
420 Note that you can also achieve interesting effects by modifying | 414 } |
421 the screen surface alpha channel. It's set to 255 by default.. | 415 } |
422 */ | 416 |
423 x += delta_x; | 417 /* Set the flags we want to use for setting the video mode */ |
424 if ( x < 0 ) { | 418 video_flags = SDL_OPENGL; |
425 x = 0; | 419 for (i = 1; argv[i]; ++i) { |
426 delta_x = -delta_x; | 420 if (strcmp(argv[i], "-fullscreen") == 0) { |
427 } else | 421 video_flags |= SDL_FULLSCREEN; |
428 if ( (x+w) > screen->w ) { | 422 } |
429 x = screen->w-w; | 423 } |
430 delta_x = -delta_x; | 424 |
431 } | 425 if (noframe) { |
432 y += delta_y; | 426 video_flags |= SDL_NOFRAME; |
433 if ( y < 0 ) { | 427 } |
434 y = 0; | 428 |
435 delta_y = -delta_y; | 429 /* Initialize the display */ |
436 } else | 430 switch (bpp) { |
437 if ( (y+h) > screen->h ) { | 431 case 8: |
438 y = screen->h-h; | 432 rgb_size[0] = 3; |
439 delta_y = -delta_y; | 433 rgb_size[1] = 3; |
440 } | 434 rgb_size[2] = 2; |
441 dst.x = x; | 435 break; |
442 dst.y = y; | 436 case 15: |
443 dst.w = w; | 437 case 16: |
444 dst.h = h; | 438 rgb_size[0] = 5; |
445 SDL_BlitSurface(global_image, NULL, screen, &dst); | 439 rgb_size[1] = 5; |
446 | 440 rgb_size[2] = 5; |
447 /* Show the image on the screen */ | 441 break; |
448 SDL_UpdateRects(screen, 1, &dst); | 442 default: |
449 } | 443 rgb_size[0] = 8; |
450 | 444 rgb_size[1] = 8; |
451 int RunGLTest( int argc, char* argv[], | 445 rgb_size[2] = 8; |
452 int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa, int sync, int accel ) | 446 break; |
453 { | 447 } |
454 int i; | 448 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]); |
455 int rgb_size[3]; | 449 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]); |
456 int w = 640; | 450 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]); |
457 int h = 480; | 451 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
458 int done = 0; | 452 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
459 int frames; | 453 if (fsaa) { |
460 Uint32 start_time, this_time; | 454 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); |
461 float color[8][3]= {{ 1.0, 1.0, 0.0}, | 455 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); |
462 { 1.0, 0.0, 0.0}, | 456 } |
463 { 0.0, 0.0, 0.0}, | 457 if (accel) { |
464 { 0.0, 1.0, 0.0}, | 458 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); |
465 { 0.0, 1.0, 1.0}, | 459 } |
466 { 1.0, 1.0, 1.0}, | 460 if (sync) { |
467 { 1.0, 0.0, 1.0}, | 461 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
468 { 0.0, 0.0, 1.0}}; | 462 } else { |
469 float cube[8][3]= {{ 0.5, 0.5, -0.5}, | 463 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0); |
470 { 0.5, -0.5, -0.5}, | 464 } |
471 {-0.5, -0.5, -0.5}, | 465 if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) { |
472 {-0.5, 0.5, -0.5}, | 466 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); |
473 {-0.5, 0.5, 0.5}, | 467 SDL_Quit(); |
474 { 0.5, 0.5, 0.5}, | 468 exit(1); |
475 { 0.5, -0.5, 0.5}, | 469 } |
476 {-0.5, -0.5, 0.5}}; | 470 |
477 Uint32 video_flags; | 471 printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); |
478 int value; | 472 printf("\n"); |
479 | 473 printf("Vendor : %s\n", glGetString(GL_VENDOR)); |
480 if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { | 474 printf("Renderer : %s\n", glGetString(GL_RENDERER)); |
481 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); | 475 printf("Version : %s\n", glGetString(GL_VERSION)); |
482 exit( 1 ); | 476 printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); |
483 } | 477 printf("\n"); |
484 | 478 |
485 /* See if we should detect the display depth */ | 479 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); |
486 if ( bpp == 0 ) { | 480 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value); |
487 if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) { | 481 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); |
488 bpp = 8; | 482 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value); |
489 } else { | 483 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); |
490 bpp = 16; /* More doesn't seem to work */ | 484 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value); |
491 } | 485 SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); |
492 } | 486 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value); |
493 | 487 SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value); |
494 /* Set the flags we want to use for setting the video mode */ | 488 printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); |
495 if ( logo && USE_DEPRECATED_OPENGLBLIT ) { | 489 if (fsaa) { |
496 video_flags = SDL_OPENGLBLIT; | 490 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); |
497 } else { | 491 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); |
498 video_flags = SDL_OPENGL; | 492 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); |
499 } | 493 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, |
500 for ( i=1; argv[i]; ++i ) { | 494 value); |
501 if ( strcmp(argv[i], "-fullscreen") == 0 ) { | 495 } |
502 video_flags |= SDL_FULLSCREEN; | 496 if (accel) { |
503 } | 497 SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); |
504 } | 498 printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); |
505 | 499 } |
506 if (noframe) { | 500 if (sync) { |
507 video_flags |= SDL_NOFRAME; | 501 SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &value); |
508 } | 502 printf("SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value); |
509 | 503 } |
510 /* Initialize the display */ | 504 |
511 switch (bpp) { | 505 /* Set the window manager title bar */ |
512 case 8: | 506 SDL_WM_SetCaption("SDL GL test", "testgl"); |
513 rgb_size[0] = 3; | 507 |
514 rgb_size[1] = 3; | 508 /* Set the gamma for the window */ |
515 rgb_size[2] = 2; | 509 if (gamma != 0.0) { |
516 break; | 510 SDL_SetGamma(gamma, gamma, gamma); |
517 case 15: | 511 } |
518 case 16: | 512 |
519 rgb_size[0] = 5; | 513 glViewport(0, 0, w, h); |
520 rgb_size[1] = 5; | 514 glMatrixMode(GL_PROJECTION); |
521 rgb_size[2] = 5; | 515 glLoadIdentity(); |
522 break; | 516 |
523 default: | 517 glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); |
524 rgb_size[0] = 8; | 518 |
525 rgb_size[1] = 8; | 519 glMatrixMode(GL_MODELVIEW); |
526 rgb_size[2] = 8; | 520 glLoadIdentity(); |
527 break; | 521 |
528 } | 522 glEnable(GL_DEPTH_TEST); |
529 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] ); | 523 |
530 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] ); | 524 glDepthFunc(GL_LESS); |
531 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] ); | 525 |
532 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); | 526 glShadeModel(GL_SMOOTH); |
533 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); | 527 |
534 if ( fsaa ) { | 528 /* Loop until done. */ |
535 SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); | 529 start_time = SDL_GetTicks(); |
536 SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, fsaa ); | 530 frames = 0; |
537 } | 531 while (!done) { |
538 if ( accel ) { | 532 GLenum gl_error; |
539 SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ); | 533 char *sdl_error; |
540 } | 534 SDL_Event event; |
541 if ( sync ) { | 535 |
542 SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 ); | 536 /* Do our drawing, too. */ |
543 } else { | 537 glClearColor(0.0, 0.0, 0.0, 1.0); |
544 SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); | 538 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
545 } | 539 |
546 if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) { | 540 glBegin(GL_QUADS); |
547 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); | |
548 SDL_Quit(); | |
549 exit(1); | |
550 } | |
551 | |
552 printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel); | |
553 printf("\n"); | |
554 printf( "Vendor : %s\n", glGetString( GL_VENDOR ) ); | |
555 printf( "Renderer : %s\n", glGetString( GL_RENDERER ) ); | |
556 printf( "Version : %s\n", glGetString( GL_VERSION ) ); | |
557 printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) ); | |
558 printf("\n"); | |
559 | |
560 SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ); | |
561 printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value); | |
562 SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ); | |
563 printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value); | |
564 SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ); | |
565 printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value); | |
566 SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value ); | |
567 printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value ); | |
568 SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ); | |
569 printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value ); | |
570 if ( fsaa ) { | |
571 SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value ); | |
572 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value ); | |
573 SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value ); | |
574 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value ); | |
575 } | |
576 if ( accel ) { | |
577 SDL_GL_GetAttribute( SDL_GL_ACCELERATED_VISUAL, &value ); | |
578 printf( "SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value ); | |
579 } | |
580 if ( sync ) { | |
581 SDL_GL_GetAttribute( SDL_GL_SWAP_CONTROL, &value ); | |
582 printf( "SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value ); | |
583 } | |
584 | |
585 /* Set the window manager title bar */ | |
586 SDL_WM_SetCaption( "SDL GL test", "testgl" ); | |
587 | |
588 /* Set the gamma for the window */ | |
589 if ( gamma != 0.0 ) { | |
590 SDL_SetGamma(gamma, gamma, gamma); | |
591 } | |
592 | |
593 glViewport( 0, 0, w, h ); | |
594 glMatrixMode( GL_PROJECTION ); | |
595 glLoadIdentity( ); | |
596 | |
597 glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 ); | |
598 | |
599 glMatrixMode( GL_MODELVIEW ); | |
600 glLoadIdentity( ); | |
601 | |
602 glEnable(GL_DEPTH_TEST); | |
603 | |
604 glDepthFunc(GL_LESS); | |
605 | |
606 glShadeModel(GL_SMOOTH); | |
607 | |
608 /* Loop until done. */ | |
609 start_time = SDL_GetTicks(); | |
610 frames = 0; | |
611 while( !done ) { | |
612 GLenum gl_error; | |
613 char* sdl_error; | |
614 SDL_Event event; | |
615 | |
616 /* Do our drawing, too. */ | |
617 glClearColor( 0.0, 0.0, 0.0, 1.0 ); | |
618 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
619 | |
620 glBegin( GL_QUADS ); | |
621 | 541 |
622 #ifdef SHADED_CUBE | 542 #ifdef SHADED_CUBE |
623 glColor3fv(color[0]); | 543 glColor3fv(color[0]); |
624 glVertex3fv(cube[0]); | 544 glVertex3fv(cube[0]); |
625 glColor3fv(color[1]); | 545 glColor3fv(color[1]); |
626 glVertex3fv(cube[1]); | 546 glVertex3fv(cube[1]); |
627 glColor3fv(color[2]); | 547 glColor3fv(color[2]); |
628 glVertex3fv(cube[2]); | 548 glVertex3fv(cube[2]); |
629 glColor3fv(color[3]); | 549 glColor3fv(color[3]); |
630 glVertex3fv(cube[3]); | 550 glVertex3fv(cube[3]); |
631 | 551 |
632 glColor3fv(color[3]); | 552 glColor3fv(color[3]); |
633 glVertex3fv(cube[3]); | 553 glVertex3fv(cube[3]); |
634 glColor3fv(color[4]); | 554 glColor3fv(color[4]); |
635 glVertex3fv(cube[4]); | 555 glVertex3fv(cube[4]); |
636 glColor3fv(color[7]); | 556 glColor3fv(color[7]); |
637 glVertex3fv(cube[7]); | 557 glVertex3fv(cube[7]); |
638 glColor3fv(color[2]); | 558 glColor3fv(color[2]); |
639 glVertex3fv(cube[2]); | 559 glVertex3fv(cube[2]); |
640 | 560 |
641 glColor3fv(color[0]); | 561 glColor3fv(color[0]); |
642 glVertex3fv(cube[0]); | 562 glVertex3fv(cube[0]); |
643 glColor3fv(color[5]); | 563 glColor3fv(color[5]); |
644 glVertex3fv(cube[5]); | 564 glVertex3fv(cube[5]); |
645 glColor3fv(color[6]); | 565 glColor3fv(color[6]); |
646 glVertex3fv(cube[6]); | 566 glVertex3fv(cube[6]); |
647 glColor3fv(color[1]); | 567 glColor3fv(color[1]); |
648 glVertex3fv(cube[1]); | 568 glVertex3fv(cube[1]); |
649 | 569 |
650 glColor3fv(color[5]); | 570 glColor3fv(color[5]); |
651 glVertex3fv(cube[5]); | 571 glVertex3fv(cube[5]); |
652 glColor3fv(color[4]); | 572 glColor3fv(color[4]); |
653 glVertex3fv(cube[4]); | 573 glVertex3fv(cube[4]); |
654 glColor3fv(color[7]); | 574 glColor3fv(color[7]); |
655 glVertex3fv(cube[7]); | 575 glVertex3fv(cube[7]); |
656 glColor3fv(color[6]); | 576 glColor3fv(color[6]); |
657 glVertex3fv(cube[6]); | 577 glVertex3fv(cube[6]); |
658 | 578 |
659 glColor3fv(color[5]); | 579 glColor3fv(color[5]); |
660 glVertex3fv(cube[5]); | 580 glVertex3fv(cube[5]); |
661 glColor3fv(color[0]); | 581 glColor3fv(color[0]); |
662 glVertex3fv(cube[0]); | 582 glVertex3fv(cube[0]); |
663 glColor3fv(color[3]); | 583 glColor3fv(color[3]); |
664 glVertex3fv(cube[3]); | 584 glVertex3fv(cube[3]); |
665 glColor3fv(color[4]); | 585 glColor3fv(color[4]); |
666 glVertex3fv(cube[4]); | 586 glVertex3fv(cube[4]); |
667 | 587 |
668 glColor3fv(color[6]); | 588 glColor3fv(color[6]); |
669 glVertex3fv(cube[6]); | 589 glVertex3fv(cube[6]); |
670 glColor3fv(color[1]); | 590 glColor3fv(color[1]); |
671 glVertex3fv(cube[1]); | 591 glVertex3fv(cube[1]); |
672 glColor3fv(color[2]); | 592 glColor3fv(color[2]); |
673 glVertex3fv(cube[2]); | 593 glVertex3fv(cube[2]); |
674 glColor3fv(color[7]); | 594 glColor3fv(color[7]); |
675 glVertex3fv(cube[7]); | 595 glVertex3fv(cube[7]); |
676 #else /* flat cube */ | 596 #else /* flat cube */ |
677 glColor3f(1.0, 0.0, 0.0); | 597 glColor3f(1.0, 0.0, 0.0); |
678 glVertex3fv(cube[0]); | 598 glVertex3fv(cube[0]); |
679 glVertex3fv(cube[1]); | 599 glVertex3fv(cube[1]); |
680 glVertex3fv(cube[2]); | 600 glVertex3fv(cube[2]); |
681 glVertex3fv(cube[3]); | 601 glVertex3fv(cube[3]); |
682 | 602 |
683 glColor3f(0.0, 1.0, 0.0); | 603 glColor3f(0.0, 1.0, 0.0); |
684 glVertex3fv(cube[3]); | 604 glVertex3fv(cube[3]); |
685 glVertex3fv(cube[4]); | 605 glVertex3fv(cube[4]); |
686 glVertex3fv(cube[7]); | 606 glVertex3fv(cube[7]); |
687 glVertex3fv(cube[2]); | 607 glVertex3fv(cube[2]); |
688 | 608 |
689 glColor3f(0.0, 0.0, 1.0); | 609 glColor3f(0.0, 0.0, 1.0); |
690 glVertex3fv(cube[0]); | 610 glVertex3fv(cube[0]); |
691 glVertex3fv(cube[5]); | 611 glVertex3fv(cube[5]); |
692 glVertex3fv(cube[6]); | 612 glVertex3fv(cube[6]); |
693 glVertex3fv(cube[1]); | 613 glVertex3fv(cube[1]); |
694 | 614 |
695 glColor3f(0.0, 1.0, 1.0); | 615 glColor3f(0.0, 1.0, 1.0); |
696 glVertex3fv(cube[5]); | 616 glVertex3fv(cube[5]); |
697 glVertex3fv(cube[4]); | 617 glVertex3fv(cube[4]); |
698 glVertex3fv(cube[7]); | 618 glVertex3fv(cube[7]); |
699 glVertex3fv(cube[6]); | 619 glVertex3fv(cube[6]); |
700 | 620 |
701 glColor3f(1.0, 1.0, 0.0); | 621 glColor3f(1.0, 1.0, 0.0); |
702 glVertex3fv(cube[5]); | 622 glVertex3fv(cube[5]); |
703 glVertex3fv(cube[0]); | 623 glVertex3fv(cube[0]); |
704 glVertex3fv(cube[3]); | 624 glVertex3fv(cube[3]); |
705 glVertex3fv(cube[4]); | 625 glVertex3fv(cube[4]); |
706 | 626 |
707 glColor3f(1.0, 0.0, 1.0); | 627 glColor3f(1.0, 0.0, 1.0); |
708 glVertex3fv(cube[6]); | 628 glVertex3fv(cube[6]); |
709 glVertex3fv(cube[1]); | 629 glVertex3fv(cube[1]); |
710 glVertex3fv(cube[2]); | 630 glVertex3fv(cube[2]); |
711 glVertex3fv(cube[7]); | 631 glVertex3fv(cube[7]); |
712 #endif /* SHADED_CUBE */ | 632 #endif /* SHADED_CUBE */ |
713 | 633 |
714 glEnd( ); | 634 glEnd(); |
715 | 635 |
716 glMatrixMode(GL_MODELVIEW); | 636 glMatrixMode(GL_MODELVIEW); |
717 glRotatef(5.0, 1.0, 1.0, 1.0); | 637 glRotatef(5.0, 1.0, 1.0, 1.0); |
718 | 638 |
719 /* Draw 2D logo onto the 3D display */ | 639 /* Draw 2D logo onto the 3D display */ |
720 if ( logo ) { | 640 if (logo) { |
721 if ( USE_DEPRECATED_OPENGLBLIT ) { | 641 DrawLogoTexture(); |
722 DrawLogoBlit(); | 642 } |
723 } else { | 643 if (logocursor) { |
724 DrawLogoTexture(); | 644 DrawLogoCursor(); |
725 } | 645 } |
726 } | 646 |
727 if ( logocursor ) { | 647 SDL_GL_SwapBuffers(); |
728 DrawLogoCursor(); | 648 |
729 } | 649 /* Check for error conditions. */ |
730 | 650 gl_error = glGetError(); |
731 SDL_GL_SwapBuffers( ); | 651 |
732 | 652 if (gl_error != GL_NO_ERROR) { |
733 /* Check for error conditions. */ | 653 fprintf(stderr, "testgl: OpenGL error: %d\n", gl_error); |
734 gl_error = glGetError( ); | 654 } |
735 | 655 |
736 if( gl_error != GL_NO_ERROR ) { | 656 sdl_error = SDL_GetError(); |
737 fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error ); | 657 |
738 } | 658 if (sdl_error[0] != '\0') { |
739 | 659 fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error); |
740 sdl_error = SDL_GetError( ); | 660 SDL_ClearError(); |
741 | 661 } |
742 if( sdl_error[0] != '\0' ) { | 662 |
743 fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error); | 663 /* Allow the user to see what's happening */ |
744 SDL_ClearError(); | 664 if (slowly) { |
745 } | 665 SDL_Delay(20); |
746 | 666 } |
747 /* Allow the user to see what's happening */ | 667 |
748 if ( slowly ) { | 668 /* Check if there's a pending event. */ |
749 SDL_Delay( 20 ); | 669 while (SDL_PollEvent(&event)) { |
750 } | 670 done = HandleEvent(&event); |
751 | 671 } |
752 /* Check if there's a pending event. */ | 672 ++frames; |
753 while( SDL_PollEvent( &event ) ) { | 673 } |
754 done = HandleEvent(&event); | 674 |
755 } | 675 /* Print out the frames per second */ |
756 ++frames; | 676 this_time = SDL_GetTicks(); |
757 } | 677 if (this_time != start_time) { |
758 | 678 printf("%2.2f FPS\n", |
759 /* Print out the frames per second */ | 679 ((float) frames / (this_time - start_time)) * 1000.0); |
760 this_time = SDL_GetTicks(); | 680 } |
761 if ( this_time != start_time ) { | 681 |
762 printf("%2.2f FPS\n", | 682 if (global_image) { |
763 ((float)frames/(this_time-start_time))*1000.0); | 683 SDL_FreeSurface(global_image); |
764 } | 684 global_image = NULL; |
765 | 685 } |
766 if ( global_image ) { | 686 if (global_texture) { |
767 SDL_FreeSurface(global_image); | 687 glDeleteTextures(1, &global_texture); |
768 global_image = NULL; | 688 global_texture = 0; |
769 } | 689 } |
770 if ( global_texture ) { | 690 if (cursor_texture) { |
771 glDeleteTextures( 1, &global_texture ); | 691 glDeleteTextures(1, &cursor_texture); |
772 global_texture = 0; | 692 cursor_texture = 0; |
773 } | 693 } |
774 if ( cursor_texture ) { | 694 |
775 glDeleteTextures( 1, &cursor_texture ); | 695 /* Destroy our GL context, etc. */ |
776 cursor_texture = 0; | 696 SDL_Quit(); |
777 } | 697 return (0); |
778 | 698 } |
779 /* Destroy our GL context, etc. */ | 699 |
780 SDL_Quit( ); | 700 int |
781 return(0); | 701 main(int argc, char *argv[]) |
782 } | 702 { |
783 | 703 int i, logo, logocursor = 0; |
784 int main(int argc, char *argv[]) | 704 int numtests; |
785 { | 705 int bpp = 0; |
786 int i, logo, logocursor = 0; | 706 int slowly; |
787 int numtests; | 707 float gamma = 0.0; |
788 int bpp = 0; | 708 int noframe = 0; |
789 int slowly; | 709 int fsaa = 0; |
790 float gamma = 0.0; | 710 int accel = 0; |
791 int noframe = 0; | 711 int sync = 0; |
792 int fsaa = 0; | 712 |
793 int accel = 0; | 713 logo = 0; |
794 int sync = 0; | 714 slowly = 0; |
795 | 715 numtests = 1; |
796 logo = 0; | 716 for (i = 1; argv[i]; ++i) { |
797 slowly = 0; | 717 if (strcmp(argv[i], "-twice") == 0) { |
798 numtests = 1; | 718 ++numtests; |
799 for ( i=1; argv[i]; ++i ) { | 719 } |
800 if ( strcmp(argv[i], "-twice") == 0 ) { | 720 if (strcmp(argv[i], "-logo") == 0) { |
801 ++numtests; | 721 logo = 1; |
802 } | 722 } |
803 if ( strcmp(argv[i], "-logo") == 0 ) { | 723 if (strcmp(argv[i], "-logocursor") == 0) { |
804 logo = 1; | 724 logocursor = 1; |
805 USE_DEPRECATED_OPENGLBLIT = SDL_FALSE; | 725 } |
806 } | 726 if (strcmp(argv[i], "-slow") == 0) { |
807 if ( strcmp(argv[i], "-logoblit") == 0 ) { | 727 slowly = 1; |
808 logo = 1; | 728 } |
809 USE_DEPRECATED_OPENGLBLIT = SDL_TRUE; | 729 if (strcmp(argv[i], "-bpp") == 0) { |
810 } | 730 bpp = atoi(argv[++i]); |
811 if ( strcmp(argv[i], "-logocursor") == 0 ) { | 731 } |
812 logocursor = 1; | 732 if (strcmp(argv[i], "-gamma") == 0) { |
813 } | 733 gamma = (float) atof(argv[++i]); |
814 if ( strcmp(argv[i], "-slow") == 0 ) { | 734 } |
815 slowly = 1; | 735 if (strcmp(argv[i], "-noframe") == 0) { |
816 } | 736 noframe = 1; |
817 if ( strcmp(argv[i], "-bpp") == 0 ) { | 737 } |
818 bpp = atoi(argv[++i]); | 738 if (strcmp(argv[i], "-fsaa") == 0) { |
819 } | 739 ++fsaa; |
820 if ( strcmp(argv[i], "-gamma") == 0 ) { | 740 } |
821 gamma = (float)atof(argv[++i]); | 741 if (strcmp(argv[i], "-accel") == 0) { |
822 } | 742 ++accel; |
823 if ( strcmp(argv[i], "-noframe") == 0 ) { | 743 } |
824 noframe = 1; | 744 if (strcmp(argv[i], "-sync") == 0) { |
825 } | 745 ++sync; |
826 if ( strcmp(argv[i], "-fsaa") == 0 ) { | 746 } |
827 ++fsaa; | 747 if (strncmp(argv[i], "-h", 2) == 0) { |
828 } | 748 printf |
829 if ( strcmp(argv[i], "-accel") == 0 ) { | 749 ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-accel] [-sync] [-fullscreen]\n", |
830 ++accel; | 750 argv[0]); |
831 } | 751 exit(0); |
832 if ( strcmp(argv[i], "-sync") == 0 ) { | 752 } |
833 ++sync; | 753 } |
834 } | 754 for (i = 0; i < numtests; ++i) { |
835 if ( strncmp(argv[i], "-h", 2) == 0 ) { | 755 RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, |
836 printf( | 756 noframe, fsaa, sync, accel); |
837 "Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-accel] [-sync] [-fullscreen]\n", | 757 } |
838 argv[0]); | 758 return 0; |
839 exit(0); | |
840 } | |
841 } | |
842 for ( i=0; i<numtests; ++i ) { | |
843 RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa, sync, accel); | |
844 } | |
845 return 0; | |
846 } | 759 } |
847 | 760 |
848 #else /* HAVE_OPENGL */ | 761 #else /* HAVE_OPENGL */ |
849 | 762 |
850 int main(int argc, char *argv[]) | 763 int |
851 { | 764 main(int argc, char *argv[]) |
852 printf("No OpenGL support on this system\n"); | 765 { |
853 return 1; | 766 printf("No OpenGL support on this system\n"); |
767 return 1; | |
854 } | 768 } |
855 | 769 |
856 #endif /* HAVE_OPENGL */ | 770 #endif /* HAVE_OPENGL */ |