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