Mercurial > sdl-ios-xcode
comparison test/testgl.c @ 933:4272450dd8d0
Added an option to show the logo at the cursor position for debugging
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 20 Aug 2004 22:33:11 +0000 |
parents | 4ab6d1fd028f |
children | 670e74bf5cc8 |
comparison
equal
deleted
inserted
replaced
932:66761191fc11 | 933:4272450dd8d0 |
---|---|
21 | 21 |
22 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE; | 22 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE; |
23 | 23 |
24 static SDL_Surface *global_image = NULL; | 24 static SDL_Surface *global_image = NULL; |
25 static GLuint global_texture = 0; | 25 static GLuint global_texture = 0; |
26 static GLuint cursor_texture = 0; | |
26 | 27 |
27 /**********************************************************************/ | 28 /**********************************************************************/ |
28 | 29 |
29 void HotKey_ToggleFullScreen(void) | 30 void HotKey_ToggleFullScreen(void) |
30 { | 31 { |
235 SDL_FreeSurface(image); /* No longer needed */ | 236 SDL_FreeSurface(image); /* No longer needed */ |
236 | 237 |
237 return texture; | 238 return texture; |
238 } | 239 } |
239 | 240 |
241 void DrawLogoCursor(void) | |
242 { | |
243 static GLfloat texMinX, texMinY; | |
244 static GLfloat texMaxX, texMaxY; | |
245 static int w, h; | |
246 int x, y; | |
247 | |
248 SDL_Surface *screen = SDL_GetVideoSurface(); | |
249 | |
250 if ( ! cursor_texture ) { | |
251 SDL_Surface *image; | |
252 GLfloat texcoord[4]; | |
253 | |
254 /* Load the image (could use SDL_image library here) */ | |
255 image = SDL_LoadBMP(LOGO_FILE); | |
256 if ( image == NULL ) { | |
257 return; | |
258 } | |
259 w = image->w; | |
260 h = image->h; | |
261 | |
262 /* Convert the image into an OpenGL texture */ | |
263 cursor_texture = SDL_GL_LoadTexture(image, texcoord); | |
264 | |
265 /* Make texture coordinates easy to understand */ | |
266 texMinX = texcoord[0]; | |
267 texMinY = texcoord[1]; | |
268 texMaxX = texcoord[2]; | |
269 texMaxY = texcoord[3]; | |
270 | |
271 /* We don't need the original image anymore */ | |
272 SDL_FreeSurface(image); | |
273 | |
274 /* Make sure that the texture conversion is okay */ | |
275 if ( ! cursor_texture ) { | |
276 return; | |
277 } | |
278 } | |
279 | |
280 /* Move the image around */ | |
281 SDL_GetMouseState(&x, &y); | |
282 x -= w/2; | |
283 y -= h/2; | |
284 | |
285 /* Show the image on the screen */ | |
286 SDL_GL_Enter2DMode(); | |
287 glBindTexture(GL_TEXTURE_2D, cursor_texture); | |
288 glBegin(GL_TRIANGLE_STRIP); | |
289 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y ); | |
290 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y ); | |
291 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h); | |
292 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h); | |
293 glEnd(); | |
294 SDL_GL_Leave2DMode(); | |
295 } | |
240 | 296 |
241 void DrawLogoTexture(void) | 297 void DrawLogoTexture(void) |
242 { | 298 { |
243 static GLfloat texMinX, texMinY; | 299 static GLfloat texMinX, texMinY; |
244 static GLfloat texMaxX, texMaxY; | 300 static GLfloat texMaxX, texMaxY; |
391 /* Show the image on the screen */ | 447 /* Show the image on the screen */ |
392 SDL_UpdateRects(screen, 1, &dst); | 448 SDL_UpdateRects(screen, 1, &dst); |
393 } | 449 } |
394 | 450 |
395 int RunGLTest( int argc, char* argv[], | 451 int RunGLTest( int argc, char* argv[], |
396 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa ) | 452 int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa ) |
397 { | 453 { |
398 int i; | 454 int i; |
399 int rgb_size[3]; | 455 int rgb_size[3]; |
400 int w = 640; | 456 int w = 640; |
401 int h = 480; | 457 int h = 480; |
650 DrawLogoBlit(); | 706 DrawLogoBlit(); |
651 } else { | 707 } else { |
652 DrawLogoTexture(); | 708 DrawLogoTexture(); |
653 } | 709 } |
654 } | 710 } |
711 if ( logocursor ) { | |
712 DrawLogoCursor(); | |
713 } | |
655 | 714 |
656 SDL_GL_SwapBuffers( ); | 715 SDL_GL_SwapBuffers( ); |
657 | 716 |
658 /* Check for error conditions. */ | 717 /* Check for error conditions. */ |
659 gl_error = glGetError( ); | 718 gl_error = glGetError( ); |
694 } | 753 } |
695 if ( global_texture ) { | 754 if ( global_texture ) { |
696 glDeleteTextures( 1, &global_texture ); | 755 glDeleteTextures( 1, &global_texture ); |
697 global_texture = 0; | 756 global_texture = 0; |
698 } | 757 } |
758 if ( cursor_texture ) { | |
759 glDeleteTextures( 1, &cursor_texture ); | |
760 cursor_texture = 0; | |
761 } | |
699 | 762 |
700 /* Destroy our GL context, etc. */ | 763 /* Destroy our GL context, etc. */ |
701 SDL_Quit( ); | 764 SDL_Quit( ); |
702 return(0); | 765 return(0); |
703 } | 766 } |
704 | 767 |
705 int main(int argc, char *argv[]) | 768 int main(int argc, char *argv[]) |
706 { | 769 { |
707 int i, logo; | 770 int i, logo, logocursor; |
708 int numtests; | 771 int numtests; |
709 int bpp = 0; | 772 int bpp = 0; |
710 int slowly; | 773 int slowly; |
711 float gamma = 0.0; | 774 float gamma = 0.0; |
712 int noframe = 0; | 775 int noframe = 0; |
725 } | 788 } |
726 if ( strcmp(argv[i], "-logoblit") == 0 ) { | 789 if ( strcmp(argv[i], "-logoblit") == 0 ) { |
727 logo = 1; | 790 logo = 1; |
728 USE_DEPRECATED_OPENGLBLIT = SDL_TRUE; | 791 USE_DEPRECATED_OPENGLBLIT = SDL_TRUE; |
729 } | 792 } |
793 if ( strcmp(argv[i], "-logocursor") == 0 ) { | |
794 logocursor = 1; | |
795 } | |
730 if ( strcmp(argv[i], "-slow") == 0 ) { | 796 if ( strcmp(argv[i], "-slow") == 0 ) { |
731 slowly = 1; | 797 slowly = 1; |
732 } | 798 } |
733 if ( strcmp(argv[i], "-bpp") == 0 ) { | 799 if ( strcmp(argv[i], "-bpp") == 0 ) { |
734 bpp = atoi(argv[++i]); | 800 bpp = atoi(argv[++i]); |
742 if ( strcmp(argv[i], "-fsaa") == 0 ) { | 808 if ( strcmp(argv[i], "-fsaa") == 0 ) { |
743 ++fsaa; | 809 ++fsaa; |
744 } | 810 } |
745 if ( strncmp(argv[i], "-h", 2) == 0 ) { | 811 if ( strncmp(argv[i], "-h", 2) == 0 ) { |
746 printf( | 812 printf( |
747 "Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n", | 813 "Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n", |
748 argv[0]); | 814 argv[0]); |
749 exit(0); | 815 exit(0); |
750 } | 816 } |
751 } | 817 } |
752 for ( i=0; i<numtests; ++i ) { | 818 for ( i=0; i<numtests; ++i ) { |
753 RunGLTest(argc, argv, logo, slowly, bpp, gamma, noframe, fsaa); | 819 RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa); |
754 } | 820 } |
755 return 0; | 821 return 0; |
756 } | 822 } |
757 | 823 |
758 #else /* HAVE_OPENGL */ | 824 #else /* HAVE_OPENGL */ |