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