Added an option to show the logo at the cursor position for debugging
authorSam Lantinga <slouken@libsdl.org>
Fri, 20 Aug 2004 22:33:11 +0000
changeset 9334272450dd8d0
parent 932 66761191fc11
child 934 af585d6efec8
Added an option to show the logo at the cursor position for debugging
test/testgl.c
     1.1 --- a/test/testgl.c	Fri Aug 20 22:32:05 2004 +0000
     1.2 +++ b/test/testgl.c	Fri Aug 20 22:33:11 2004 +0000
     1.3 @@ -23,6 +23,7 @@
     1.4  
     1.5  static SDL_Surface *global_image = NULL;
     1.6  static GLuint global_texture = 0;
     1.7 +static GLuint cursor_texture = 0;
     1.8  
     1.9  /**********************************************************************/
    1.10  
    1.11 @@ -237,6 +238,61 @@
    1.12  	return texture;
    1.13  }
    1.14  
    1.15 +void DrawLogoCursor(void)
    1.16 +{
    1.17 +	static GLfloat texMinX, texMinY;
    1.18 +	static GLfloat texMaxX, texMaxY;
    1.19 +	static int w, h;
    1.20 +	int x, y;
    1.21 +
    1.22 +	SDL_Surface *screen = SDL_GetVideoSurface();
    1.23 +
    1.24 +	if ( ! cursor_texture ) {
    1.25 +		SDL_Surface *image;
    1.26 +		GLfloat texcoord[4];
    1.27 +
    1.28 +		/* Load the image (could use SDL_image library here) */
    1.29 +		image = SDL_LoadBMP(LOGO_FILE);
    1.30 +		if ( image == NULL ) {
    1.31 +			return;
    1.32 +		}
    1.33 +		w = image->w;
    1.34 +		h = image->h;
    1.35 +
    1.36 +		/* Convert the image into an OpenGL texture */
    1.37 +		cursor_texture = SDL_GL_LoadTexture(image, texcoord);
    1.38 +
    1.39 +		/* Make texture coordinates easy to understand */
    1.40 +		texMinX = texcoord[0];
    1.41 +		texMinY = texcoord[1];
    1.42 +		texMaxX = texcoord[2];
    1.43 +		texMaxY = texcoord[3];
    1.44 +
    1.45 +		/* We don't need the original image anymore */
    1.46 +		SDL_FreeSurface(image);
    1.47 +
    1.48 +		/* Make sure that the texture conversion is okay */
    1.49 +		if ( ! cursor_texture ) {
    1.50 +			return;
    1.51 +		}
    1.52 +	}
    1.53 +
    1.54 +	/* Move the image around */
    1.55 +	SDL_GetMouseState(&x, &y);
    1.56 +	x -= w/2;
    1.57 +	y -= h/2;
    1.58 +
    1.59 +	/* Show the image on the screen */
    1.60 +	SDL_GL_Enter2DMode();
    1.61 +	glBindTexture(GL_TEXTURE_2D, cursor_texture);
    1.62 +	glBegin(GL_TRIANGLE_STRIP);
    1.63 +	glTexCoord2f(texMinX, texMinY); glVertex2i(x,   y  );
    1.64 +	glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y  );
    1.65 +	glTexCoord2f(texMinX, texMaxY); glVertex2i(x,   y+h);
    1.66 +	glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
    1.67 +	glEnd();
    1.68 +	SDL_GL_Leave2DMode();
    1.69 +}
    1.70  
    1.71  void DrawLogoTexture(void)
    1.72  {
    1.73 @@ -393,7 +449,7 @@
    1.74  }
    1.75  
    1.76  int RunGLTest( int argc, char* argv[],
    1.77 -               int logo, int slowly, int bpp, float gamma, int noframe, int fsaa )
    1.78 +               int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa )
    1.79  {
    1.80  	int i;
    1.81  	int rgb_size[3];
    1.82 @@ -652,6 +708,9 @@
    1.83  				DrawLogoTexture();
    1.84  			}
    1.85  		}
    1.86 +		if ( logocursor ) {
    1.87 +			DrawLogoCursor();
    1.88 +		}
    1.89  
    1.90  		SDL_GL_SwapBuffers( );
    1.91  
    1.92 @@ -696,6 +755,10 @@
    1.93  		glDeleteTextures( 1, &global_texture );
    1.94  		global_texture = 0;
    1.95  	}
    1.96 +	if ( cursor_texture ) {
    1.97 +		glDeleteTextures( 1, &cursor_texture );
    1.98 +		cursor_texture = 0;
    1.99 +	}
   1.100  
   1.101  	/* Destroy our GL context, etc. */
   1.102  	SDL_Quit( );
   1.103 @@ -704,7 +767,7 @@
   1.104  
   1.105  int main(int argc, char *argv[])
   1.106  {
   1.107 -	int i, logo;
   1.108 +	int i, logo, logocursor;
   1.109  	int numtests;
   1.110  	int bpp = 0;
   1.111  	int slowly;
   1.112 @@ -727,6 +790,9 @@
   1.113  			logo = 1;
   1.114  			USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
   1.115  		}
   1.116 +		if ( strcmp(argv[i], "-logocursor") == 0 ) {
   1.117 +			logocursor = 1;
   1.118 +		}
   1.119  		if ( strcmp(argv[i], "-slow") == 0 ) {
   1.120  			slowly = 1;
   1.121  		}
   1.122 @@ -744,13 +810,13 @@
   1.123  		}
   1.124  		if ( strncmp(argv[i], "-h", 2) == 0 ) {
   1.125   		       printf(
   1.126 -"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n",
   1.127 +"Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n",
   1.128   			      argv[0]);
   1.129  			exit(0);
   1.130  		}
   1.131  	}
   1.132  	for ( i=0; i<numtests; ++i ) {
   1.133 - 		RunGLTest(argc, argv, logo, slowly, bpp, gamma, noframe, fsaa);
   1.134 + 		RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa);
   1.135  	}
   1.136  	return 0;
   1.137  }