test/testgl.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 16 Sep 2002 06:17:34 +0000
changeset 492 c59692dcdce0
parent 363 ca0b4ba5313e
child 655 9c42ee1b7d77
permissions -rw-r--r--
*** empty log message ***
     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 
    22 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
    23 
    24 static SDL_Surface *global_image = NULL;
    25 static GLuint global_texture = 0;
    26 
    27 /**********************************************************************/
    28 
    29 void HotKey_ToggleFullScreen(void)
    30 {
    31 	SDL_Surface *screen;
    32 
    33 	screen = SDL_GetVideoSurface();
    34 	if ( SDL_WM_ToggleFullScreen(screen) ) {
    35 		printf("Toggled fullscreen mode - now %s\n",
    36 		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    37 	} else {
    38 		printf("Unable to toggle fullscreen mode\n");
    39 	}
    40 }
    41 
    42 void HotKey_ToggleGrab(void)
    43 {
    44 	SDL_GrabMode mode;
    45 
    46 	printf("Ctrl-G: toggling input grab!\n");
    47 	mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
    48 	if ( mode == SDL_GRAB_ON ) {
    49 		printf("Grab was on\n");
    50 	} else {
    51 		printf("Grab was off\n");
    52 	}
    53 	mode = SDL_WM_GrabInput(!mode);
    54 	if ( mode == SDL_GRAB_ON ) {
    55 		printf("Grab is now on\n");
    56 	} else {
    57 		printf("Grab is now off\n");
    58 	}
    59 }
    60 
    61 void HotKey_Iconify(void)
    62 {
    63 	printf("Ctrl-Z: iconifying window!\n");
    64 	SDL_WM_IconifyWindow();
    65 }
    66 
    67 int HandleEvent(SDL_Event *event)
    68 {
    69 	int done;
    70 
    71 	done = 0;
    72 	switch( event->type ) {
    73 	    case SDL_ACTIVEEVENT:
    74 		/* See what happened */
    75 		printf( "app %s ", event->active.gain ? "gained" : "lost" );
    76 		if ( event->active.state & SDL_APPACTIVE ) {
    77 			printf( "active " );
    78 		} else if ( event->active.state & SDL_APPMOUSEFOCUS ) {
    79 			printf( "mouse " );
    80 		} else if ( event->active.state & SDL_APPINPUTFOCUS ) {
    81 			printf( "input " );
    82 		}
    83 		printf( "focus\n" );
    84 		break;
    85 		
    86 
    87 	    case SDL_KEYDOWN:
    88 		if ( event->key.keysym.sym == SDLK_ESCAPE ) {
    89 			done = 1;
    90 		}
    91 		if ( (event->key.keysym.sym == SDLK_g) &&
    92 		     (event->key.keysym.mod & KMOD_CTRL) ) {
    93 			HotKey_ToggleGrab();
    94 		}
    95 		if ( (event->key.keysym.sym == SDLK_z) &&
    96 		     (event->key.keysym.mod & KMOD_CTRL) ) {
    97 			HotKey_Iconify();
    98 		}
    99 		if ( (event->key.keysym.sym == SDLK_RETURN) &&
   100 		     (event->key.keysym.mod & KMOD_ALT) ) {
   101 			HotKey_ToggleFullScreen();
   102 		}
   103 		printf("key '%s' pressed\n", 
   104 			SDL_GetKeyName(event->key.keysym.sym));
   105 		break;
   106 	    case SDL_QUIT:
   107 		done = 1;
   108 		break;
   109 	}
   110 	return(done);
   111 }
   112 
   113 void SDL_GL_Enter2DMode()
   114 {
   115 	SDL_Surface *screen = SDL_GetVideoSurface();
   116 
   117 	/* Note, there may be other things you need to change,
   118 	   depending on how you have your OpenGL state set up.
   119 	*/
   120 	glPushAttrib(GL_ENABLE_BIT);
   121 	glDisable(GL_DEPTH_TEST);
   122 	glDisable(GL_CULL_FACE);
   123 	glEnable(GL_TEXTURE_2D);
   124 
   125 	/* This allows alpha blending of 2D textures with the scene */
   126 	glEnable(GL_BLEND);
   127 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   128 
   129 	glViewport(0, 0, screen->w, screen->h);
   130 
   131 	glMatrixMode(GL_PROJECTION);
   132 	glPushMatrix();
   133 	glLoadIdentity();
   134 
   135 	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
   136 
   137 	glMatrixMode(GL_MODELVIEW);
   138 	glPushMatrix();
   139 	glLoadIdentity();
   140 
   141 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   142 }
   143 
   144 void SDL_GL_Leave2DMode()
   145 {
   146 	glMatrixMode(GL_MODELVIEW);
   147 	glPopMatrix();
   148 
   149 	glMatrixMode(GL_PROJECTION);
   150 	glPopMatrix();
   151 
   152 	glPopAttrib();
   153 }
   154 
   155 /* Quick utility function for texture creation */
   156 static int power_of_two(int input)
   157 {
   158 	int value = 1;
   159 
   160 	while ( value < input ) {
   161 		value <<= 1;
   162 	}
   163 	return value;
   164 }
   165 
   166 GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
   167 {
   168 	GLuint texture;
   169 	int w, h;
   170 	SDL_Surface *image;
   171 	SDL_Rect area;
   172 	Uint32 saved_flags;
   173 	Uint8  saved_alpha;
   174 
   175 	/* Use the surface width and height expanded to powers of 2 */
   176 	w = power_of_two(surface->w);
   177 	h = power_of_two(surface->h);
   178 	texcoord[0] = 0.0f;			/* Min X */
   179 	texcoord[1] = 0.0f;			/* Min Y */
   180 	texcoord[2] = (GLfloat)surface->w / w;	/* Max X */
   181 	texcoord[3] = (GLfloat)surface->h / h;	/* Max Y */
   182 
   183 	image = SDL_CreateRGBSurface(
   184 			SDL_SWSURFACE,
   185 			w, h,
   186 			32,
   187 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
   188 			0x000000FF, 
   189 			0x0000FF00, 
   190 			0x00FF0000, 
   191 			0xFF000000
   192 #else
   193 			0xFF000000,
   194 			0x00FF0000, 
   195 			0x0000FF00, 
   196 			0x000000FF
   197 #endif
   198 		       );
   199 	if ( image == NULL ) {
   200 		return 0;
   201 	}
   202 
   203 	/* Save the alpha blending attributes */
   204 	saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
   205 	saved_alpha = surface->format->alpha;
   206 	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
   207 		SDL_SetAlpha(surface, 0, 0);
   208 	}
   209 
   210 	/* Copy the surface into the GL texture image */
   211 	area.x = 0;
   212 	area.y = 0;
   213 	area.w = surface->w;
   214 	area.h = surface->h;
   215 	SDL_BlitSurface(surface, &area, image, &area);
   216 
   217 	/* Restore the alpha blending attributes */
   218 	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
   219 		SDL_SetAlpha(surface, saved_flags, saved_alpha);
   220 	}
   221 
   222 	/* Create an OpenGL texture for the image */
   223 	glGenTextures(1, &texture);
   224 	glBindTexture(GL_TEXTURE_2D, texture);
   225 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   226 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   227 	glTexImage2D(GL_TEXTURE_2D,
   228 		     0,
   229 		     GL_RGBA,
   230 		     w, h,
   231 		     0,
   232 		     GL_RGBA,
   233 		     GL_UNSIGNED_BYTE,
   234 		     image->pixels);
   235 	SDL_FreeSurface(image); /* No longer needed */
   236 
   237 	return texture;
   238 }
   239 
   240 
   241 void DrawLogoTexture(void)
   242 {
   243 	static GLfloat texMinX, texMinY;
   244 	static GLfloat texMaxX, texMaxY;
   245 	static int x = 0;
   246 	static int y = 0;
   247 	static int w, h;
   248 	static int delta_x = 1;
   249 	static int delta_y = 1;
   250 	static Uint32 last_moved = 0;
   251 
   252 	SDL_Surface *screen = SDL_GetVideoSurface();
   253 
   254 	if ( ! global_texture ) {
   255 		SDL_Surface *image;
   256 		GLfloat texcoord[4];
   257 
   258 		/* Load the image (could use SDL_image library here) */
   259 		image = SDL_LoadBMP(LOGO_FILE);
   260 		if ( image == NULL ) {
   261 			return;
   262 		}
   263 		w = image->w;
   264 		h = image->h;
   265 
   266 		/* Convert the image into an OpenGL texture */
   267 		global_texture = SDL_GL_LoadTexture(image, texcoord);
   268 
   269 		/* Make texture coordinates easy to understand */
   270 		texMinX = texcoord[0];
   271 		texMinY = texcoord[1];
   272 		texMaxX = texcoord[2];
   273 		texMaxY = texcoord[3];
   274 
   275 		/* We don't need the original image anymore */
   276 		SDL_FreeSurface(image);
   277 
   278 		/* Make sure that the texture conversion is okay */
   279 		if ( ! global_texture ) {
   280 			return;
   281 		}
   282 	}
   283 
   284 	/* Move the image around */
   285 	x += delta_x;
   286 	if ( x < 0 ) {
   287 		x = 0;
   288 		delta_x = -delta_x;
   289 	} else
   290 	if ( (x+w) > screen->w ) {
   291 		x = screen->w-w;
   292 		delta_x = -delta_x;
   293 	}
   294 	y += delta_y;
   295 	if ( y < 0 ) {
   296 		y = 0;
   297 		delta_y = -delta_y;
   298 	} else
   299 	if ( (y+h) > screen->h ) {
   300 		y = screen->h-h;
   301 		delta_y = -delta_y;
   302 	}
   303 
   304 	/* Show the image on the screen */
   305 	SDL_GL_Enter2DMode();
   306 	glBindTexture(GL_TEXTURE_2D, global_texture);
   307 	glBegin(GL_TRIANGLE_STRIP);
   308 	glTexCoord2f(texMinX, texMinY); glVertex2i(x,   y  );
   309 	glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y  );
   310 	glTexCoord2f(texMinX, texMaxY); glVertex2i(x,   y+h);
   311 	glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
   312 	glEnd();
   313 	SDL_GL_Leave2DMode();
   314 }
   315 
   316 /* This code is deprecated, but available for speed comparisons */
   317 void DrawLogoBlit(void)
   318 {
   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 ( global_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 		global_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 ( global_image ) {
   350 			SDL_BlitSurface(temp, NULL, global_image, NULL);
   351 		}
   352 		SDL_FreeSurface(temp);
   353 
   354 		/* Make sure that the texture conversion is okay */
   355 		if ( ! global_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(global_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, int noframe )
   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         if (noframe) {
   451            video_flags |= SDL_NOFRAME;
   452         }
   453 
   454 	/* Initialize the display */
   455 	switch (bpp) {
   456 	    case 8:
   457 		rgb_size[0] = 3;
   458 		rgb_size[1] = 3;
   459 		rgb_size[2] = 2;
   460 		break;
   461 	    case 15:
   462 	    case 16:
   463 		rgb_size[0] = 5;
   464 		rgb_size[1] = 5;
   465 		rgb_size[2] = 5;
   466 		break;
   467             default:
   468 		rgb_size[0] = 8;
   469 		rgb_size[1] = 8;
   470 		rgb_size[2] = 8;
   471 		break;
   472 	}
   473 	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
   474 	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
   475 	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
   476 	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
   477 	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
   478 	if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
   479 		fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
   480 		SDL_Quit();
   481 		exit(1);
   482 	}
   483 
   484 	printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
   485 	printf("\n");
   486 	printf( "Vendor     : %s\n", glGetString( GL_VENDOR ) );
   487 	printf( "Renderer   : %s\n", glGetString( GL_RENDERER ) );
   488 	printf( "Version    : %s\n", glGetString( GL_VERSION ) );
   489 	printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
   490 	printf("\n");
   491 
   492 	SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
   493 	printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
   494 	SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
   495 	printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
   496 	SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
   497 	printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
   498 	SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
   499 	printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
   500 	SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
   501 	printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
   502 
   503 	/* Set the window manager title bar */
   504 	SDL_WM_SetCaption( "SDL GL test", "testgl" );
   505 
   506 	/* Set the gamma for the window */
   507 	if ( gamma != 0.0 ) {
   508 		SDL_SetGamma(gamma, gamma, gamma);
   509 	}
   510 
   511 	glViewport( 0, 0, w, h );
   512 	glMatrixMode( GL_PROJECTION );
   513 	glLoadIdentity( );
   514 
   515 	glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
   516 
   517 	glMatrixMode( GL_MODELVIEW );
   518 	glLoadIdentity( );
   519 
   520 	glEnable(GL_DEPTH_TEST);
   521 
   522 	glDepthFunc(GL_LESS);
   523 
   524 	glShadeModel(GL_SMOOTH);
   525 
   526 	/* Loop until done. */
   527 	start_time = SDL_GetTicks();
   528 	frames = 0;
   529 	while( !done ) {
   530 		GLenum gl_error;
   531 		char* sdl_error;
   532 		SDL_Event event;
   533 
   534 		/* Do our drawing, too. */
   535 		glClearColor( 0.0, 0.0, 0.0, 1.0 );
   536 		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   537 
   538 		glBegin( GL_QUADS );
   539 
   540 #ifdef SHADED_CUBE
   541 			glColor3fv(color[0]);
   542 			glVertex3fv(cube[0]);
   543 			glColor3fv(color[1]);
   544 			glVertex3fv(cube[1]);
   545 			glColor3fv(color[2]);
   546 			glVertex3fv(cube[2]);
   547 			glColor3fv(color[3]);
   548 			glVertex3fv(cube[3]);
   549 			
   550 			glColor3fv(color[3]);
   551 			glVertex3fv(cube[3]);
   552 			glColor3fv(color[4]);
   553 			glVertex3fv(cube[4]);
   554 			glColor3fv(color[7]);
   555 			glVertex3fv(cube[7]);
   556 			glColor3fv(color[2]);
   557 			glVertex3fv(cube[2]);
   558 			
   559 			glColor3fv(color[0]);
   560 			glVertex3fv(cube[0]);
   561 			glColor3fv(color[5]);
   562 			glVertex3fv(cube[5]);
   563 			glColor3fv(color[6]);
   564 			glVertex3fv(cube[6]);
   565 			glColor3fv(color[1]);
   566 			glVertex3fv(cube[1]);
   567 			
   568 			glColor3fv(color[5]);
   569 			glVertex3fv(cube[5]);
   570 			glColor3fv(color[4]);
   571 			glVertex3fv(cube[4]);
   572 			glColor3fv(color[7]);
   573 			glVertex3fv(cube[7]);
   574 			glColor3fv(color[6]);
   575 			glVertex3fv(cube[6]);
   576 
   577 			glColor3fv(color[5]);
   578 			glVertex3fv(cube[5]);
   579 			glColor3fv(color[0]);
   580 			glVertex3fv(cube[0]);
   581 			glColor3fv(color[3]);
   582 			glVertex3fv(cube[3]);
   583 			glColor3fv(color[4]);
   584 			glVertex3fv(cube[4]);
   585 
   586 			glColor3fv(color[6]);
   587 			glVertex3fv(cube[6]);
   588 			glColor3fv(color[1]);
   589 			glVertex3fv(cube[1]);
   590 			glColor3fv(color[2]);
   591 			glVertex3fv(cube[2]);
   592 			glColor3fv(color[7]);
   593 			glVertex3fv(cube[7]);
   594 #else // flat cube
   595 			glColor3f(1.0, 0.0, 0.0);
   596 			glVertex3fv(cube[0]);
   597 			glVertex3fv(cube[1]);
   598 			glVertex3fv(cube[2]);
   599 			glVertex3fv(cube[3]);
   600 			
   601 			glColor3f(0.0, 1.0, 0.0);
   602 			glVertex3fv(cube[3]);
   603 			glVertex3fv(cube[4]);
   604 			glVertex3fv(cube[7]);
   605 			glVertex3fv(cube[2]);
   606 			
   607 			glColor3f(0.0, 0.0, 1.0);
   608 			glVertex3fv(cube[0]);
   609 			glVertex3fv(cube[5]);
   610 			glVertex3fv(cube[6]);
   611 			glVertex3fv(cube[1]);
   612 			
   613 			glColor3f(0.0, 1.0, 1.0);
   614 			glVertex3fv(cube[5]);
   615 			glVertex3fv(cube[4]);
   616 			glVertex3fv(cube[7]);
   617 			glVertex3fv(cube[6]);
   618 
   619 			glColor3f(1.0, 1.0, 0.0);
   620 			glVertex3fv(cube[5]);
   621 			glVertex3fv(cube[0]);
   622 			glVertex3fv(cube[3]);
   623 			glVertex3fv(cube[4]);
   624 
   625 			glColor3f(1.0, 0.0, 1.0);
   626 			glVertex3fv(cube[6]);
   627 			glVertex3fv(cube[1]);
   628 			glVertex3fv(cube[2]);
   629 			glVertex3fv(cube[7]);
   630 #endif /* SHADED_CUBE */
   631 
   632 		glEnd( );
   633 		
   634 		glMatrixMode(GL_MODELVIEW);
   635 		glRotatef(5.0, 1.0, 1.0, 1.0);
   636 
   637 		/* Draw 2D logo onto the 3D display */
   638 		if ( logo ) {
   639 			if ( USE_DEPRECATED_OPENGLBLIT ) {
   640 				DrawLogoBlit();
   641 			} else {
   642 				DrawLogoTexture();
   643 			}
   644 		}
   645 
   646 		SDL_GL_SwapBuffers( );
   647 
   648 		/* Check for error conditions. */
   649 		gl_error = glGetError( );
   650 
   651 		if( gl_error != GL_NO_ERROR ) {
   652 			fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
   653 		}
   654 
   655 		sdl_error = SDL_GetError( );
   656 
   657 		if( sdl_error[0] != '\0' ) {
   658 			fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
   659 			SDL_ClearError();
   660 		}
   661 
   662 		/* Allow the user to see what's happening */
   663 		if ( slowly ) {
   664 			SDL_Delay( 20 );
   665 		}
   666 
   667 		/* Check if there's a pending event. */
   668 		while( SDL_PollEvent( &event ) ) {
   669 			done = HandleEvent(&event);
   670 		}
   671 		++frames;
   672 	}
   673 
   674 	/* Print out the frames per second */
   675 	this_time = SDL_GetTicks();
   676 	if ( this_time != start_time ) {
   677 		printf("%2.2f FPS\n",
   678 			((float)frames/(this_time-start_time))*1000.0);
   679 	}
   680 
   681 	if ( global_image ) {
   682 	   	SDL_FreeSurface(global_image);
   683 		global_image = NULL;
   684 	}
   685 	if ( global_texture ) {
   686 		glDeleteTextures( 1, &global_texture );
   687 		global_texture = 0;
   688 	}
   689 
   690 	/* Destroy our GL context, etc. */
   691 	SDL_Quit( );
   692 	return(0);
   693 }
   694 
   695 int main(int argc, char *argv[])
   696 {
   697 	int i, logo;
   698 	int numtests;
   699 	int bpp = 0;
   700 	int slowly;
   701 	float gamma = 0.0;
   702 	int noframe = 0;
   703 
   704 	logo = 0;
   705 	slowly = 0;
   706 	numtests = 1;
   707 	for ( i=1; argv[i]; ++i ) {
   708 		if ( strcmp(argv[i], "-twice") == 0 ) {
   709 			++numtests;
   710 		}
   711 		if ( strcmp(argv[i], "-logo") == 0 ) {
   712 			logo = 1;
   713 			USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
   714 		}
   715 		if ( strcmp(argv[i], "-logoblit") == 0 ) {
   716 			logo = 1;
   717 			USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
   718 		}
   719 		if ( strcmp(argv[i], "-slow") == 0 ) {
   720 			slowly = 1;
   721 		}
   722 		if ( strcmp(argv[i], "-bpp") == 0 ) {
   723  		       bpp = atoi(argv[++i]);
   724 		}
   725 		if ( strcmp(argv[i], "-gamma") == 0 ) {
   726  		       gamma = (float)atof(argv[++i]);
   727 		}
   728 		if ( strcmp(argv[i], "-noframe") == 0 ) {
   729  		       noframe = 1;
   730 		}
   731 		if ( strncmp(argv[i], "-h", 2) == 0 ) {
   732  		       printf(
   733 "Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe]\n",
   734  			      argv[0]);
   735 			exit(0);
   736 		}
   737 	}
   738 	for ( i=0; i<numtests; ++i ) {
   739  		RunGLTest(argc, argv, logo, slowly, bpp, gamma, noframe);
   740 	}
   741 	return 0;
   742 }
   743 
   744 #else /* HAVE_OPENGL */
   745 
   746 int main(int argc, char *argv[])
   747 {
   748 	printf("No OpenGL support on this system\n");
   749 	return 1;
   750 }
   751 
   752 #endif /* HAVE_OPENGL */