test/testgl.c
changeset 233 5b42a7f5fab3
parent 221 50620ec9c86a
child 234 1af4be6a73cd
     1.1 --- a/test/testgl.c	Tue Nov 06 00:15:04 2001 +0000
     1.2 +++ b/test/testgl.c	Tue Nov 06 00:15:24 2001 +0000
     1.3 @@ -10,6 +10,7 @@
     1.4  
     1.5  #define SHADED_CUBE
     1.6  
     1.7 +static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
     1.8  
     1.9  void HotKey_ToggleFullScreen(void)
    1.10  {
    1.11 @@ -95,11 +96,51 @@
    1.12  	return(done);
    1.13  }
    1.14  
    1.15 +void SDL_GL_Enter2DMode()
    1.16 +{
    1.17 +	SDL_Surface *screen = SDL_GetVideoSurface();
    1.18 +
    1.19 +	/* Note, there may be other things you need to change,
    1.20 +	   depending on how you have your OpenGL state set up.
    1.21 +	*/
    1.22 +	glPushAttrib(GL_ENABLE_BIT);
    1.23 +	glDisable(GL_DEPTH_TEST);
    1.24 +	glDisable(GL_CULL_FACE);
    1.25 +	glEnable(GL_TEXTURE_2D);
    1.26 +
    1.27 +	glViewport(0, 0, screen->w, screen->h);
    1.28 +
    1.29 +	glMatrixMode(GL_PROJECTION);
    1.30 +	glPushMatrix();
    1.31 +	glLoadIdentity();
    1.32 +
    1.33 +	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
    1.34 +
    1.35 +	glMatrixMode(GL_MODELVIEW);
    1.36 +	glPushMatrix();
    1.37 +	glLoadIdentity();
    1.38 +
    1.39 +	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    1.40 +}
    1.41 +
    1.42 +void SDL_GL_Leave2DMode()
    1.43 +{
    1.44 +	glMatrixMode(GL_MODELVIEW);
    1.45 +	glPopMatrix();
    1.46 +
    1.47 +	glMatrixMode(GL_PROJECTION);
    1.48 +	glPopMatrix();
    1.49 +
    1.50 +	glPopAttrib();
    1.51 +}
    1.52 +
    1.53  void DrawSDLLogo(void)
    1.54  {
    1.55  	static SDL_Surface *image = NULL;
    1.56 +	static GLuint texture;
    1.57  	static int x = 0;
    1.58  	static int y = 0;
    1.59 +	static int w, h;
    1.60  	static int delta_x = 1;
    1.61  	static int delta_y = 1;
    1.62  	static Uint32 last_moved = 0;
    1.63 @@ -118,16 +159,16 @@
    1.64  				SDL_SWSURFACE,
    1.65  				temp->w, temp->h,
    1.66  				32,
    1.67 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
    1.68 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    1.69  				0x000000FF, 
    1.70  				0x0000FF00, 
    1.71  				0x00FF0000, 
    1.72 - 			       0xFF000000
    1.73 +				0xFF000000
    1.74  #else
    1.75 - 			       0xFF000000,
    1.76 - 			       0x00FF0000, 
    1.77 - 			       0x0000FF00, 
    1.78 - 			       0x000000FF
    1.79 +				0xFF000000,
    1.80 +				0x00FF0000, 
    1.81 +				0x0000FF00, 
    1.82 +				0x000000FF
    1.83  #endif
    1.84   			       );
    1.85  		if ( image != NULL ) {
    1.86 @@ -137,6 +178,29 @@
    1.87  		if ( image == NULL ) {
    1.88  			return;
    1.89  		}
    1.90 +		w = image->w;
    1.91 +		h = image->h;
    1.92 +
    1.93 +		/* Create an OpenGL texture for the image */
    1.94 +		if ( ! USE_DEPRECATED_OPENGLBLIT ) {
    1.95 +			glGenTextures(1, &texture);
    1.96 +			glBindTexture(GL_TEXTURE_2D, texture);
    1.97 +			glTexParameteri(GL_TEXTURE_2D,
    1.98 +			                GL_TEXTURE_MAG_FILTER,
    1.99 +			                GL_NEAREST);
   1.100 +			glTexParameteri(GL_TEXTURE_2D,
   1.101 +			                GL_TEXTURE_MIN_FILTER,
   1.102 +			                GL_NEAREST);
   1.103 +			glTexImage2D(GL_TEXTURE_2D,
   1.104 +			             0,
   1.105 +			             GL_RGBA,
   1.106 +			             w, h,
   1.107 +			             0,
   1.108 +			             GL_RGBA,
   1.109 +			             GL_UNSIGNED_BYTE,
   1.110 +			             image->pixels);
   1.111 +			SDL_FreeSurface(image); /* No longer needed */
   1.112 +		}
   1.113  	}
   1.114  
   1.115  	screen = SDL_GetVideoSurface();
   1.116 @@ -144,8 +208,8 @@
   1.117  	/* Show the image on the screen */
   1.118  	dst.x = x;
   1.119  	dst.y = y;
   1.120 -	dst.w = image->w;
   1.121 -	dst.h = image->h;
   1.122 +	dst.w = w;
   1.123 +	dst.h = h;
   1.124  
   1.125  	/* Move it around
   1.126             Note that we do not clear the old position.  This is because we
   1.127 @@ -160,8 +224,8 @@
   1.128  			x = 0;
   1.129  			delta_x = -delta_x;
   1.130  		} else
   1.131 -		if ( (x+image->w) > screen->w ) {
   1.132 -			x = screen->w-image->w;
   1.133 +		if ( (x+w) > screen->w ) {
   1.134 +			x = screen->w-w;
   1.135  			delta_x = -delta_x;
   1.136  		}
   1.137  		y += delta_y;
   1.138 @@ -169,13 +233,27 @@
   1.139  			y = 0;
   1.140  			delta_y = -delta_y;
   1.141  		} else
   1.142 -		if ( (y+image->h) > screen->h ) {
   1.143 -			y = screen->h-image->h;
   1.144 +		if ( (y+h) > screen->h ) {
   1.145 +			y = screen->h-h;
   1.146  			delta_y = -delta_y;
   1.147  		}
   1.148 -		SDL_BlitSurface(image, NULL, screen, &dst);
   1.149 +		if ( USE_DEPRECATED_OPENGLBLIT ) {
   1.150 +			SDL_BlitSurface(image, NULL, screen, &dst);
   1.151 +		} else {
   1.152 +			SDL_GL_Enter2DMode();
   1.153 +			glBindTexture(GL_TEXTURE_2D, texture);
   1.154 +			glBegin(GL_TRIANGLE_STRIP);
   1.155 +			glTexCoord2f(0.0, 0.0); glVertex2i(x,   y  );
   1.156 +			glTexCoord2f(1.0, 0.0); glVertex2i(x+w, y  );
   1.157 +			glTexCoord2f(0.0, 1.0); glVertex2i(x,   y+h);
   1.158 +			glTexCoord2f(1.0, 1.0); glVertex2i(x+w, y+h);
   1.159 +			glEnd();
   1.160 +			SDL_GL_Leave2DMode();
   1.161 +		}
   1.162  	}
   1.163 -	SDL_UpdateRects(screen, 1, &dst);
   1.164 +	if ( USE_DEPRECATED_OPENGLBLIT ) {
   1.165 +		SDL_UpdateRects(screen, 1, &dst);
   1.166 +	}
   1.167  }
   1.168  
   1.169  int RunGLTest( int argc, char* argv[],
   1.170 @@ -222,7 +300,7 @@
   1.171  	}
   1.172  
   1.173  	/* Set the flags we want to use for setting the video mode */
   1.174 -	if ( logo ) {
   1.175 +	if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
   1.176  		video_flags = SDL_OPENGLBLIT;
   1.177  	} else {
   1.178  		video_flags = SDL_OPENGL;
   1.179 @@ -478,6 +556,11 @@
   1.180  		}
   1.181  		if ( strcmp(argv[i], "-logo") == 0 ) {
   1.182  			logo = 1;
   1.183 +			USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
   1.184 +		}
   1.185 +		if ( strcmp(argv[i], "-logoblit") == 0 ) {
   1.186 +			logo = 1;
   1.187 +			USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
   1.188  		}
   1.189  		if ( strcmp(argv[i], "-slow") == 0 ) {
   1.190  			slowly = 1;