Mercurial > sdl-ios-xcode
comparison test/testgl.c @ 492:c59692dcdce0
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 16 Sep 2002 06:17:34 +0000 |
parents | ca0b4ba5313e |
children | 9c42ee1b7d77 |
comparison
equal
deleted
inserted
replaced
491:da6a7e859616 | 492:c59692dcdce0 |
---|---|
16 #define LOGO_FILE "icon.bmp" | 16 #define LOGO_FILE "icon.bmp" |
17 | 17 |
18 /* The SDL_OPENGLBLIT interface is deprecated. | 18 /* The SDL_OPENGLBLIT interface is deprecated. |
19 The code is still available for benchmark purposes though. | 19 The code is still available for benchmark purposes though. |
20 */ | 20 */ |
21 | |
21 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE; | 22 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE; |
23 | |
24 static SDL_Surface *global_image = NULL; | |
25 static GLuint global_texture = 0; | |
22 | 26 |
23 /**********************************************************************/ | 27 /**********************************************************************/ |
24 | 28 |
25 void HotKey_ToggleFullScreen(void) | 29 void HotKey_ToggleFullScreen(void) |
26 { | 30 { |
231 SDL_FreeSurface(image); /* No longer needed */ | 235 SDL_FreeSurface(image); /* No longer needed */ |
232 | 236 |
233 return texture; | 237 return texture; |
234 } | 238 } |
235 | 239 |
240 | |
236 void DrawLogoTexture(void) | 241 void DrawLogoTexture(void) |
237 { | 242 { |
238 static GLuint texture; | |
239 static GLfloat texMinX, texMinY; | 243 static GLfloat texMinX, texMinY; |
240 static GLfloat texMaxX, texMaxY; | 244 static GLfloat texMaxX, texMaxY; |
241 static int x = 0; | 245 static int x = 0; |
242 static int y = 0; | 246 static int y = 0; |
243 static int w, h; | 247 static int w, h; |
245 static int delta_y = 1; | 249 static int delta_y = 1; |
246 static Uint32 last_moved = 0; | 250 static Uint32 last_moved = 0; |
247 | 251 |
248 SDL_Surface *screen = SDL_GetVideoSurface(); | 252 SDL_Surface *screen = SDL_GetVideoSurface(); |
249 | 253 |
250 if ( ! texture ) { | 254 if ( ! global_texture ) { |
251 SDL_Surface *image; | 255 SDL_Surface *image; |
252 GLfloat texcoord[4]; | 256 GLfloat texcoord[4]; |
253 | 257 |
254 /* Load the image (could use SDL_image library here) */ | 258 /* Load the image (could use SDL_image library here) */ |
255 image = SDL_LoadBMP(LOGO_FILE); | 259 image = SDL_LoadBMP(LOGO_FILE); |
258 } | 262 } |
259 w = image->w; | 263 w = image->w; |
260 h = image->h; | 264 h = image->h; |
261 | 265 |
262 /* Convert the image into an OpenGL texture */ | 266 /* Convert the image into an OpenGL texture */ |
263 texture = SDL_GL_LoadTexture(image, texcoord); | 267 global_texture = SDL_GL_LoadTexture(image, texcoord); |
264 | 268 |
265 /* Make texture coordinates easy to understand */ | 269 /* Make texture coordinates easy to understand */ |
266 texMinX = texcoord[0]; | 270 texMinX = texcoord[0]; |
267 texMinY = texcoord[1]; | 271 texMinY = texcoord[1]; |
268 texMaxX = texcoord[2]; | 272 texMaxX = texcoord[2]; |
270 | 274 |
271 /* We don't need the original image anymore */ | 275 /* We don't need the original image anymore */ |
272 SDL_FreeSurface(image); | 276 SDL_FreeSurface(image); |
273 | 277 |
274 /* Make sure that the texture conversion is okay */ | 278 /* Make sure that the texture conversion is okay */ |
275 if ( ! texture ) { | 279 if ( ! global_texture ) { |
276 return; | 280 return; |
277 } | 281 } |
278 } | 282 } |
279 | 283 |
280 /* Move the image around */ | 284 /* Move the image around */ |
297 delta_y = -delta_y; | 301 delta_y = -delta_y; |
298 } | 302 } |
299 | 303 |
300 /* Show the image on the screen */ | 304 /* Show the image on the screen */ |
301 SDL_GL_Enter2DMode(); | 305 SDL_GL_Enter2DMode(); |
302 glBindTexture(GL_TEXTURE_2D, texture); | 306 glBindTexture(GL_TEXTURE_2D, global_texture); |
303 glBegin(GL_TRIANGLE_STRIP); | 307 glBegin(GL_TRIANGLE_STRIP); |
304 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y ); | 308 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y ); |
305 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y ); | 309 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y ); |
306 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h); | 310 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h); |
307 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h); | 311 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h); |
310 } | 314 } |
311 | 315 |
312 /* This code is deprecated, but available for speed comparisons */ | 316 /* This code is deprecated, but available for speed comparisons */ |
313 void DrawLogoBlit(void) | 317 void DrawLogoBlit(void) |
314 { | 318 { |
315 static SDL_Surface *image = NULL; | |
316 static GLuint texture; | |
317 static GLfloat texMinX, texMinY; | |
318 static GLfloat texMaxX, texMaxY; | |
319 static int x = 0; | 319 static int x = 0; |
320 static int y = 0; | 320 static int y = 0; |
321 static int w, h; | 321 static int w, h; |
322 static int delta_x = 1; | 322 static int delta_x = 1; |
323 static int delta_y = 1; | 323 static int delta_y = 1; |
324 static Uint32 last_moved = 0; | 324 static Uint32 last_moved = 0; |
325 | 325 |
326 SDL_Rect dst; | 326 SDL_Rect dst; |
327 SDL_Surface *screen = SDL_GetVideoSurface(); | 327 SDL_Surface *screen = SDL_GetVideoSurface(); |
328 | 328 |
329 if ( image == NULL ) { | 329 if ( global_image == NULL ) { |
330 SDL_Surface *temp; | 330 SDL_Surface *temp; |
331 | 331 |
332 /* Load the image (could use SDL_image library here) */ | 332 /* Load the image (could use SDL_image library here) */ |
333 temp = SDL_LoadBMP(LOGO_FILE); | 333 temp = SDL_LoadBMP(LOGO_FILE); |
334 if ( temp == NULL ) { | 334 if ( temp == NULL ) { |
336 } | 336 } |
337 w = temp->w; | 337 w = temp->w; |
338 h = temp->h; | 338 h = temp->h; |
339 | 339 |
340 /* Convert the image into the screen format */ | 340 /* Convert the image into the screen format */ |
341 image = SDL_CreateRGBSurface( | 341 global_image = SDL_CreateRGBSurface( |
342 SDL_SWSURFACE, | 342 SDL_SWSURFACE, |
343 w, h, | 343 w, h, |
344 screen->format->BitsPerPixel, | 344 screen->format->BitsPerPixel, |
345 screen->format->Rmask, | 345 screen->format->Rmask, |
346 screen->format->Gmask, | 346 screen->format->Gmask, |
347 screen->format->Bmask, | 347 screen->format->Bmask, |
348 screen->format->Amask); | 348 screen->format->Amask); |
349 if ( image ) { | 349 if ( global_image ) { |
350 SDL_BlitSurface(temp, NULL, image, NULL); | 350 SDL_BlitSurface(temp, NULL, global_image, NULL); |
351 } | 351 } |
352 SDL_FreeSurface(temp); | 352 SDL_FreeSurface(temp); |
353 | 353 |
354 /* Make sure that the texture conversion is okay */ | 354 /* Make sure that the texture conversion is okay */ |
355 if ( ! image ) { | 355 if ( ! global_image ) { |
356 return; | 356 return; |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 /* Move the image around | 360 /* Move the image around |
384 } | 384 } |
385 dst.x = x; | 385 dst.x = x; |
386 dst.y = y; | 386 dst.y = y; |
387 dst.w = w; | 387 dst.w = w; |
388 dst.h = h; | 388 dst.h = h; |
389 SDL_BlitSurface(image, NULL, screen, &dst); | 389 SDL_BlitSurface(global_image, NULL, screen, &dst); |
390 | 390 |
391 /* Show the image on the screen */ | 391 /* Show the image on the screen */ |
392 SDL_UpdateRects(screen, 1, &dst); | 392 SDL_UpdateRects(screen, 1, &dst); |
393 } | 393 } |
394 | 394 |
676 if ( this_time != start_time ) { | 676 if ( this_time != start_time ) { |
677 printf("%2.2f FPS\n", | 677 printf("%2.2f FPS\n", |
678 ((float)frames/(this_time-start_time))*1000.0); | 678 ((float)frames/(this_time-start_time))*1000.0); |
679 } | 679 } |
680 | 680 |
681 if ( global_image ) { | |
682 SDL_FreeSurface(global_image); | |
683 global_image = NULL; | |
684 } | |
685 if ( global_texture ) { | |
686 glDeleteTextures( 1, &global_texture ); | |
687 global_texture = 0; | |
688 } | |
689 | |
681 /* Destroy our GL context, etc. */ | 690 /* Destroy our GL context, etc. */ |
682 SDL_Quit( ); | 691 SDL_Quit( ); |
683 return(0); | 692 return(0); |
684 } | 693 } |
685 | 694 |
688 int i, logo; | 697 int i, logo; |
689 int numtests; | 698 int numtests; |
690 int bpp = 0; | 699 int bpp = 0; |
691 int slowly; | 700 int slowly; |
692 float gamma = 0.0; | 701 float gamma = 0.0; |
693 int noframe = 0; | 702 int noframe = 0; |
694 | 703 |
695 logo = 0; | 704 logo = 0; |
696 slowly = 0; | 705 slowly = 0; |
697 numtests = 1; | 706 numtests = 1; |
698 for ( i=1; argv[i]; ++i ) { | 707 for ( i=1; argv[i]; ++i ) { |
725 argv[0]); | 734 argv[0]); |
726 exit(0); | 735 exit(0); |
727 } | 736 } |
728 } | 737 } |
729 for ( i=0; i<numtests; ++i ) { | 738 for ( i=0; i<numtests; ++i ) { |
730 RunGLTest(argc, argv, logo, slowly, bpp, gamma, noframe); | 739 RunGLTest(argc, argv, logo, slowly, bpp, gamma, noframe); |
731 } | 740 } |
732 return 0; | 741 return 0; |
733 } | 742 } |
734 | 743 |
735 #else /* HAVE_OPENGL */ | 744 #else /* HAVE_OPENGL */ |