test/testgl.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 06 Nov 2001 01:48:36 +0000
changeset 234 1af4be6a73cd
parent 233 5b42a7f5fab3
child 243 cf4944faad96
permissions -rw-r--r--
Modified the logo texture load to accept any width/height image
     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 	glViewport(0, 0, screen->w, screen->h);
   122 
   123 	glMatrixMode(GL_PROJECTION);
   124 	glPushMatrix();
   125 	glLoadIdentity();
   126 
   127 	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
   128 
   129 	glMatrixMode(GL_MODELVIEW);
   130 	glPushMatrix();
   131 	glLoadIdentity();
   132 
   133 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   134 }
   135 
   136 void SDL_GL_Leave2DMode()
   137 {
   138 	glMatrixMode(GL_MODELVIEW);
   139 	glPopMatrix();
   140 
   141 	glMatrixMode(GL_PROJECTION);
   142 	glPopMatrix();
   143 
   144 	glPopAttrib();
   145 }
   146 
   147 /* Quick utility function for texture creation */
   148 static int power_of_two(int input)
   149 {
   150 	int value = 1;
   151 
   152 	while ( value < input ) {
   153 		value <<= 1;
   154 	}
   155 	return value;
   156 }
   157 
   158 GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
   159 {
   160 	GLuint texture;
   161 	int w, h;
   162 	SDL_Surface *image;
   163 	SDL_Rect area;
   164 	Uint32 saved_flags;
   165 	Uint8  saved_alpha;
   166 
   167 	/* Use the surface width and height expanded to powers of 2 */
   168 	w = power_of_two(surface->w);
   169 	h = power_of_two(surface->h);
   170 	texcoord[0] = 0.0f;			/* Min X */
   171 	texcoord[1] = 0.0f;			/* Min Y */
   172 	texcoord[2] = (GLfloat)surface->w / w;	/* Max X */
   173 	texcoord[3] = (GLfloat)surface->h / h;	/* Max Y */
   174 
   175 	image = SDL_CreateRGBSurface(
   176 			SDL_SWSURFACE,
   177 			w, h,
   178 			32,
   179 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
   180 			0x000000FF, 
   181 			0x0000FF00, 
   182 			0x00FF0000, 
   183 			0xFF000000
   184 #else
   185 			0xFF000000,
   186 			0x00FF0000, 
   187 			0x0000FF00, 
   188 			0x000000FF
   189 #endif
   190 		       );
   191 	if ( image == NULL ) {
   192 		return 0;
   193 	}
   194 
   195 	/* Save the alpha blending attributes */
   196 	saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
   197 	saved_alpha = surface->format->alpha;
   198 	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
   199 		SDL_SetAlpha(surface, 0, 0);
   200 	}
   201 
   202 	/* Copy the surface into the GL texture image */
   203 	area.x = 0;
   204 	area.y = 0;
   205 	area.w = surface->w;
   206 	area.h = surface->h;
   207 	SDL_BlitSurface(surface, &area, image, &area);
   208 
   209 	/* Restore the alpha blending attributes */
   210 	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
   211 		SDL_SetAlpha(surface, saved_flags, saved_alpha);
   212 	}
   213 
   214 	/* Create an OpenGL texture for the image */
   215 	glGenTextures(1, &texture);
   216 	glBindTexture(GL_TEXTURE_2D, texture);
   217 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   218 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   219 	glTexImage2D(GL_TEXTURE_2D,
   220 		     0,
   221 		     GL_RGBA,
   222 		     w, h,
   223 		     0,
   224 		     GL_RGBA,
   225 		     GL_UNSIGNED_BYTE,
   226 		     image->pixels);
   227 	SDL_FreeSurface(image); /* No longer needed */
   228 
   229 	return texture;
   230 }
   231 
   232 void DrawLogoTexture(void)
   233 {
   234 	static GLuint texture;
   235 	static GLfloat texMinX, texMinY;
   236 	static GLfloat texMaxX, texMaxY;
   237 	static int x = 0;
   238 	static int y = 0;
   239 	static int w, h;
   240 	static int delta_x = 1;
   241 	static int delta_y = 1;
   242 	static Uint32 last_moved = 0;
   243 
   244 	SDL_Surface *screen = SDL_GetVideoSurface();
   245 
   246 	if ( ! texture ) {
   247 		SDL_Surface *image;
   248 		GLfloat texcoord[4];
   249 
   250 		/* Load the image (could use SDL_image library here) */
   251 		image = SDL_LoadBMP(LOGO_FILE);
   252 		if ( image == NULL ) {
   253 			return;
   254 		}
   255 		w = image->w;
   256 		h = image->h;
   257 
   258 		/* Convert the image into an OpenGL texture */
   259 		texture = SDL_GL_LoadTexture(image, texcoord);
   260 
   261 		/* Make texture coordinates easy to understand */
   262 		texMinX = texcoord[0];
   263 		texMinY = texcoord[1];
   264 		texMaxX = texcoord[2];
   265 		texMaxY = texcoord[3];
   266 
   267 		/* We don't need the original image anymore */
   268 		SDL_FreeSurface(image);
   269 
   270 		/* Make sure that the texture conversion is okay */
   271 		if ( ! texture ) {
   272 			return;
   273 		}
   274 	}
   275 
   276 	/* Move the image around */
   277 	x += delta_x;
   278 	if ( x < 0 ) {
   279 		x = 0;
   280 		delta_x = -delta_x;
   281 	} else
   282 	if ( (x+w) > screen->w ) {
   283 		x = screen->w-w;
   284 		delta_x = -delta_x;
   285 	}
   286 	y += delta_y;
   287 	if ( y < 0 ) {
   288 		y = 0;
   289 		delta_y = -delta_y;
   290 	} else
   291 	if ( (y+h) > screen->h ) {
   292 		y = screen->h-h;
   293 		delta_y = -delta_y;
   294 	}
   295 
   296 	/* Show the image on the screen */
   297 	SDL_GL_Enter2DMode();
   298 	glBindTexture(GL_TEXTURE_2D, texture);
   299 	glBegin(GL_TRIANGLE_STRIP);
   300 	glTexCoord2f(texMinX, texMinY); glVertex2i(x,   y  );
   301 	glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y  );
   302 	glTexCoord2f(texMinX, texMaxY); glVertex2i(x,   y+h);
   303 	glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
   304 	glEnd();
   305 	SDL_GL_Leave2DMode();
   306 }
   307 
   308 /* This code is deprecated, but available for speed comparisons */
   309 void DrawLogoBlit(void)
   310 {
   311 	static SDL_Surface *image = NULL;
   312 	static GLuint texture;
   313 	static GLfloat texMinX, texMinY;
   314 	static GLfloat texMaxX, texMaxY;
   315 	static int x = 0;
   316 	static int y = 0;
   317 	static int w, h;
   318 	static int delta_x = 1;
   319 	static int delta_y = 1;
   320 	static Uint32 last_moved = 0;
   321 
   322 	SDL_Rect dst;
   323 	SDL_Surface *screen = SDL_GetVideoSurface();
   324 
   325 	if ( image == NULL ) {
   326 		SDL_Surface *temp;
   327 
   328 		/* Load the image (could use SDL_image library here) */
   329 		temp = SDL_LoadBMP(LOGO_FILE);
   330 		if ( temp == NULL ) {
   331 			return;
   332 		}
   333 		w = temp->w;
   334 		h = temp->h;
   335 
   336 		/* Convert the image into the screen format */
   337 		image = SDL_CreateRGBSurface(
   338 				SDL_SWSURFACE,
   339 				w, h,
   340 				screen->format->BitsPerPixel,
   341 				screen->format->Rmask,
   342 				screen->format->Gmask,
   343 				screen->format->Bmask,
   344 				screen->format->Amask);
   345 		if ( image ) {
   346 			SDL_BlitSurface(temp, NULL, image, NULL);
   347 		}
   348 		SDL_FreeSurface(temp);
   349 
   350 		/* Make sure that the texture conversion is okay */
   351 		if ( ! image ) {
   352 			return;
   353 		}
   354 	}
   355 
   356 	/* Move the image around
   357            Note that we do not clear the old position.  This is because we
   358            perform a glClear() which clears the framebuffer and then only
   359            update the new area.
   360            Note that you can also achieve interesting effects by modifying
   361            the screen surface alpha channel.  It's set to 255 by default..
   362          */
   363 	x += delta_x;
   364 	if ( x < 0 ) {
   365 		x = 0;
   366 		delta_x = -delta_x;
   367 	} else
   368 	if ( (x+w) > screen->w ) {
   369 		x = screen->w-w;
   370 		delta_x = -delta_x;
   371 	}
   372 	y += delta_y;
   373 	if ( y < 0 ) {
   374 		y = 0;
   375 		delta_y = -delta_y;
   376 	} else
   377 	if ( (y+h) > screen->h ) {
   378 		y = screen->h-h;
   379 		delta_y = -delta_y;
   380 	}
   381 	dst.x = x;
   382 	dst.y = y;
   383 	dst.w = w;
   384 	dst.h = h;
   385 	SDL_BlitSurface(image, NULL, screen, &dst);
   386 
   387 	/* Show the image on the screen */
   388 	SDL_UpdateRects(screen, 1, &dst);
   389 }
   390 
   391 int RunGLTest( int argc, char* argv[],
   392                int logo, int slowly, int bpp, float gamma )
   393 {
   394 	int i;
   395 	int rgb_size[3];
   396 	int w = 640;
   397 	int h = 480;
   398 	int done = 0;
   399 	int frames;
   400 	Uint32 start_time, this_time;
   401         float color[8][3]= {{ 1.0,  1.0,  0.0}, 
   402 			    { 1.0,  0.0,  0.0},
   403 			    { 0.0,  0.0,  0.0},
   404 			    { 0.0,  1.0,  0.0},
   405 			    { 0.0,  1.0,  1.0},
   406 			    { 1.0,  1.0,  1.0},
   407 			    { 1.0,  0.0,  1.0},
   408 			    { 0.0,  0.0,  1.0}};
   409 	float cube[8][3]= {{ 0.5,  0.5, -0.5}, 
   410 			   { 0.5, -0.5, -0.5},
   411 			   {-0.5, -0.5, -0.5},
   412 			   {-0.5,  0.5, -0.5},
   413 			   {-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 	Uint32 video_flags;
   418 	int value;
   419 
   420 	if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
   421 		fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
   422 		exit( 1 );
   423 	}
   424 
   425 	/* See if we should detect the display depth */
   426 	if ( bpp == 0 ) {
   427 		if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
   428 			bpp = 8;
   429 		} else {
   430 			bpp = 16;  /* More doesn't seem to work */
   431 		}
   432 	}
   433 
   434 	/* Set the flags we want to use for setting the video mode */
   435 	if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
   436 		video_flags = SDL_OPENGLBLIT;
   437 	} else {
   438 		video_flags = SDL_OPENGL;
   439 	}
   440 	for ( i=1; argv[i]; ++i ) {
   441 		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
   442 			video_flags |= SDL_FULLSCREEN;
   443 		}
   444 	}
   445 
   446 	/* Initialize the display */
   447 	switch (bpp) {
   448 	    case 8:
   449 		rgb_size[0] = 2;
   450 		rgb_size[1] = 3;
   451 		rgb_size[2] = 3;
   452 		break;
   453 	    case 15:
   454 	    case 16:
   455 		rgb_size[0] = 5;
   456 		rgb_size[1] = 5;
   457 		rgb_size[2] = 5;
   458 		break;
   459             default:
   460 		rgb_size[0] = 8;
   461 		rgb_size[1] = 8;
   462 		rgb_size[2] = 8;
   463 		break;
   464 	}
   465 	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
   466 	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
   467 	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
   468 	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
   469 	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
   470 	if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
   471 		fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
   472 		SDL_Quit();
   473 		exit(1);
   474 	}
   475 
   476 	printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
   477 	printf("\n");
   478 	printf( "Vendor     : %s\n", glGetString( GL_VENDOR ) );
   479 	printf( "Renderer   : %s\n", glGetString( GL_RENDERER ) );
   480 	printf( "Version    : %s\n", glGetString( GL_VERSION ) );
   481 	printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
   482 	printf("\n");
   483 
   484 	SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
   485 	printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
   486 	SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
   487 	printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
   488 	SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
   489 	printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
   490 	SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
   491 	printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
   492 	SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
   493 	printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
   494 
   495 	/* Set the window manager title bar */
   496 	SDL_WM_SetCaption( "SDL GL test", "testgl" );
   497 
   498 	/* Set the gamma for the window */
   499 	if ( gamma != 0.0 ) {
   500 		SDL_SetGamma(gamma, gamma, gamma);
   501 	}
   502 
   503 	glViewport( 0, 0, w, h );
   504 	glMatrixMode( GL_PROJECTION );
   505 	glLoadIdentity( );
   506 
   507 	glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
   508 
   509 	glMatrixMode( GL_MODELVIEW );
   510 	glLoadIdentity( );
   511 
   512 	glEnable(GL_DEPTH_TEST);
   513 
   514 	glDepthFunc(GL_LESS);
   515 
   516 	glShadeModel(GL_SMOOTH);
   517 
   518 	/* Loop until done. */
   519 	start_time = SDL_GetTicks();
   520 	frames = 0;
   521 	while( !done ) {
   522 		GLenum gl_error;
   523 		char* sdl_error;
   524 		SDL_Event event;
   525 
   526 		/* Do our drawing, too. */
   527 		glClearColor( 0.0, 0.0, 0.0, 1.0 );
   528 		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   529 
   530 		glBegin( GL_QUADS );
   531 
   532 #ifdef SHADED_CUBE
   533 			glColor3fv(color[0]);
   534 			glVertex3fv(cube[0]);
   535 			glColor3fv(color[1]);
   536 			glVertex3fv(cube[1]);
   537 			glColor3fv(color[2]);
   538 			glVertex3fv(cube[2]);
   539 			glColor3fv(color[3]);
   540 			glVertex3fv(cube[3]);
   541 			
   542 			glColor3fv(color[3]);
   543 			glVertex3fv(cube[3]);
   544 			glColor3fv(color[4]);
   545 			glVertex3fv(cube[4]);
   546 			glColor3fv(color[7]);
   547 			glVertex3fv(cube[7]);
   548 			glColor3fv(color[2]);
   549 			glVertex3fv(cube[2]);
   550 			
   551 			glColor3fv(color[0]);
   552 			glVertex3fv(cube[0]);
   553 			glColor3fv(color[5]);
   554 			glVertex3fv(cube[5]);
   555 			glColor3fv(color[6]);
   556 			glVertex3fv(cube[6]);
   557 			glColor3fv(color[1]);
   558 			glVertex3fv(cube[1]);
   559 			
   560 			glColor3fv(color[5]);
   561 			glVertex3fv(cube[5]);
   562 			glColor3fv(color[4]);
   563 			glVertex3fv(cube[4]);
   564 			glColor3fv(color[7]);
   565 			glVertex3fv(cube[7]);
   566 			glColor3fv(color[6]);
   567 			glVertex3fv(cube[6]);
   568 
   569 			glColor3fv(color[5]);
   570 			glVertex3fv(cube[5]);
   571 			glColor3fv(color[0]);
   572 			glVertex3fv(cube[0]);
   573 			glColor3fv(color[3]);
   574 			glVertex3fv(cube[3]);
   575 			glColor3fv(color[4]);
   576 			glVertex3fv(cube[4]);
   577 
   578 			glColor3fv(color[6]);
   579 			glVertex3fv(cube[6]);
   580 			glColor3fv(color[1]);
   581 			glVertex3fv(cube[1]);
   582 			glColor3fv(color[2]);
   583 			glVertex3fv(cube[2]);
   584 			glColor3fv(color[7]);
   585 			glVertex3fv(cube[7]);
   586 #else // flat cube
   587 			glColor3f(1.0, 0.0, 0.0);
   588 			glVertex3fv(cube[0]);
   589 			glVertex3fv(cube[1]);
   590 			glVertex3fv(cube[2]);
   591 			glVertex3fv(cube[3]);
   592 			
   593 			glColor3f(0.0, 1.0, 0.0);
   594 			glVertex3fv(cube[3]);
   595 			glVertex3fv(cube[4]);
   596 			glVertex3fv(cube[7]);
   597 			glVertex3fv(cube[2]);
   598 			
   599 			glColor3f(0.0, 0.0, 1.0);
   600 			glVertex3fv(cube[0]);
   601 			glVertex3fv(cube[5]);
   602 			glVertex3fv(cube[6]);
   603 			glVertex3fv(cube[1]);
   604 			
   605 			glColor3f(0.0, 1.0, 1.0);
   606 			glVertex3fv(cube[5]);
   607 			glVertex3fv(cube[4]);
   608 			glVertex3fv(cube[7]);
   609 			glVertex3fv(cube[6]);
   610 
   611 			glColor3f(1.0, 1.0, 0.0);
   612 			glVertex3fv(cube[5]);
   613 			glVertex3fv(cube[0]);
   614 			glVertex3fv(cube[3]);
   615 			glVertex3fv(cube[4]);
   616 
   617 			glColor3f(1.0, 0.0, 1.0);
   618 			glVertex3fv(cube[6]);
   619 			glVertex3fv(cube[1]);
   620 			glVertex3fv(cube[2]);
   621 			glVertex3fv(cube[7]);
   622 #endif /* SHADED_CUBE */
   623 
   624 		glEnd( );
   625 		
   626 		glMatrixMode(GL_MODELVIEW);
   627 		glRotatef(5.0, 1.0, 1.0, 1.0);
   628 
   629 		/* Draw 2D logo onto the 3D display */
   630 		if ( logo ) {
   631 			if ( USE_DEPRECATED_OPENGLBLIT ) {
   632 				DrawLogoBlit();
   633 			} else {
   634 				DrawLogoTexture();
   635 			}
   636 		}
   637 
   638 		SDL_GL_SwapBuffers( );
   639 
   640 		/* Check for error conditions. */
   641 		gl_error = glGetError( );
   642 
   643 		if( gl_error != GL_NO_ERROR ) {
   644 			fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
   645 		}
   646 
   647 		sdl_error = SDL_GetError( );
   648 
   649 		if( sdl_error[0] != '\0' ) {
   650 			fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
   651 			SDL_ClearError();
   652 		}
   653 
   654 		/* Allow the user to see what's happening */
   655 		if ( slowly ) {
   656 			SDL_Delay( 20 );
   657 		}
   658 
   659 		/* Check if there's a pending event. */
   660 		while( SDL_PollEvent( &event ) ) {
   661 			done = HandleEvent(&event);
   662 		}
   663 		++frames;
   664 	}
   665 
   666 	/* Print out the frames per second */
   667 	this_time = SDL_GetTicks();
   668 	if ( this_time != start_time ) {
   669 		printf("%2.2f FPS\n",
   670 			((float)frames/(this_time-start_time))*1000.0);
   671 	}
   672 
   673 	/* Destroy our GL context, etc. */
   674 	SDL_Quit( );
   675 	return(0);
   676 }
   677 
   678 int main(int argc, char *argv[])
   679 {
   680 	int i, logo;
   681 	int numtests;
   682 	int bpp = 0;
   683 	int slowly;
   684 	float gamma = 0.0;
   685 
   686 	logo = 0;
   687 	slowly = 0;
   688 	numtests = 1;
   689 	for ( i=1; argv[i]; ++i ) {
   690 		if ( strcmp(argv[i], "-twice") == 0 ) {
   691 			++numtests;
   692 		}
   693 		if ( strcmp(argv[i], "-logo") == 0 ) {
   694 			logo = 1;
   695 			USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
   696 		}
   697 		if ( strcmp(argv[i], "-logoblit") == 0 ) {
   698 			logo = 1;
   699 			USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
   700 		}
   701 		if ( strcmp(argv[i], "-slow") == 0 ) {
   702 			slowly = 1;
   703 		}
   704 		if ( strcmp(argv[i], "-bpp") == 0 ) {
   705  		       bpp = atoi(argv[++i]);
   706 		}
   707 		if ( strcmp(argv[i], "-gamma") == 0 ) {
   708  		       gamma = (float)atof(argv[++i]);
   709 		}
   710 		if ( strncmp(argv[i], "-h", 2) == 0 ) {
   711  		       printf(
   712 "Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n",
   713  			      argv[0]);
   714 			exit(0);
   715 		}
   716 	}
   717 	for ( i=0; i<numtests; ++i ) {
   718  	       RunGLTest(argc, argv, logo, slowly, bpp, gamma);
   719 	}
   720 	return 0;
   721 }
   722 
   723 #else /* HAVE_OPENGL */
   724 
   725 int main(int argc, char *argv[])
   726 {
   727 	printf("No OpenGL support on this system\n");
   728 	return 1;
   729 }
   730 
   731 #endif /* HAVE_OPENGL */