test/testgl.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 25 Oct 2001 05:37:32 +0000
changeset 214 0e5d6dd77bda
parent 0 74212992fb08
child 221 50620ec9c86a
permissions -rw-r--r--
Added platform independent OpenGL header - SDL_opengl.h
slouken@0
     1
#include <stdlib.h>
slouken@0
     2
#include <stdio.h>
slouken@0
     3
#include <string.h>
slouken@0
     4
#include <math.h>
slouken@0
     5
slouken@0
     6
#include "SDL.h"
slouken@0
     7
slouken@0
     8
#ifdef HAVE_OPENGL
slouken@214
     9
#include "SDL_opengl.h"
slouken@0
    10
#endif
slouken@0
    11
slouken@0
    12
#define SHADED_CUBE
slouken@0
    13
slouken@0
    14
slouken@0
    15
void HotKey_ToggleFullScreen(void)
slouken@0
    16
{
slouken@0
    17
	SDL_Surface *screen;
slouken@0
    18
slouken@0
    19
	screen = SDL_GetVideoSurface();
slouken@0
    20
	if ( SDL_WM_ToggleFullScreen(screen) ) {
slouken@0
    21
		printf("Toggled fullscreen mode - now %s\n",
slouken@0
    22
		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
slouken@0
    23
	} else {
slouken@0
    24
		printf("Unable to toggle fullscreen mode\n");
slouken@0
    25
	}
slouken@0
    26
}
slouken@0
    27
slouken@0
    28
void HotKey_ToggleGrab(void)
slouken@0
    29
{
slouken@0
    30
	SDL_GrabMode mode;
slouken@0
    31
slouken@0
    32
	printf("Ctrl-G: toggling input grab!\n");
slouken@0
    33
	mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
slouken@0
    34
	if ( mode == SDL_GRAB_ON ) {
slouken@0
    35
		printf("Grab was on\n");
slouken@0
    36
	} else {
slouken@0
    37
		printf("Grab was off\n");
slouken@0
    38
	}
slouken@0
    39
	mode = SDL_WM_GrabInput(!mode);
slouken@0
    40
	if ( mode == SDL_GRAB_ON ) {
slouken@0
    41
		printf("Grab is now on\n");
slouken@0
    42
	} else {
slouken@0
    43
		printf("Grab is now off\n");
slouken@0
    44
	}
slouken@0
    45
}
slouken@0
    46
slouken@0
    47
void HotKey_Iconify(void)
slouken@0
    48
{
slouken@0
    49
	printf("Ctrl-Z: iconifying window!\n");
slouken@0
    50
	SDL_WM_IconifyWindow();
slouken@0
    51
}
slouken@0
    52
slouken@0
    53
int HandleEvent(SDL_Event *event)
slouken@0
    54
{
slouken@0
    55
	int done;
slouken@0
    56
slouken@0
    57
	done = 0;
slouken@0
    58
	switch( event->type ) {
slouken@0
    59
	    case SDL_ACTIVEEVENT:
slouken@0
    60
		/* See what happened */
slouken@0
    61
		printf( "app %s ", event->active.gain ? "gained" : "lost" );
slouken@0
    62
		if ( event->active.state & SDL_APPACTIVE ) {
slouken@0
    63
			printf( "active " );
slouken@0
    64
		} else if ( event->active.state & SDL_APPMOUSEFOCUS ) {
slouken@0
    65
			printf( "mouse " );
slouken@0
    66
		} else if ( event->active.state & SDL_APPINPUTFOCUS ) {
slouken@0
    67
			printf( "input " );
slouken@0
    68
		}
slouken@0
    69
		printf( "focus\n" );
slouken@0
    70
		break;
slouken@0
    71
		
slouken@0
    72
slouken@0
    73
	    case SDL_KEYDOWN:
slouken@0
    74
		if ( event->key.keysym.sym == SDLK_ESCAPE ) {
slouken@0
    75
			done = 1;
slouken@0
    76
		}
slouken@0
    77
		if ( (event->key.keysym.sym == SDLK_g) &&
slouken@0
    78
		     (event->key.keysym.mod & KMOD_CTRL) ) {
slouken@0
    79
			HotKey_ToggleGrab();
slouken@0
    80
		}
slouken@0
    81
		if ( (event->key.keysym.sym == SDLK_z) &&
slouken@0
    82
		     (event->key.keysym.mod & KMOD_CTRL) ) {
slouken@0
    83
			HotKey_Iconify();
slouken@0
    84
		}
slouken@0
    85
		if ( (event->key.keysym.sym == SDLK_RETURN) &&
slouken@0
    86
		     (event->key.keysym.mod & KMOD_ALT) ) {
slouken@0
    87
			HotKey_ToggleFullScreen();
slouken@0
    88
		}
slouken@0
    89
		printf("key '%s' pressed\n", 
slouken@0
    90
			SDL_GetKeyName(event->key.keysym.sym));
slouken@0
    91
		break;
slouken@0
    92
	    case SDL_QUIT:
slouken@0
    93
		done = 1;
slouken@0
    94
		break;
slouken@0
    95
	}
slouken@0
    96
	return(done);
slouken@0
    97
}
slouken@0
    98
slouken@0
    99
void DrawSDLLogo(void)
slouken@0
   100
{
slouken@0
   101
	static SDL_Surface *image = NULL;
slouken@0
   102
	static int x = 0;
slouken@0
   103
	static int y = 0;
slouken@0
   104
	static int delta_x = 1;
slouken@0
   105
	static int delta_y = 1;
slouken@0
   106
	static Uint32 last_moved = 0;
slouken@0
   107
slouken@0
   108
	SDL_Rect dst;
slouken@0
   109
	SDL_Surface *screen;
slouken@0
   110
slouken@0
   111
	if ( image == NULL ) {
slouken@0
   112
		SDL_Surface *temp;
slouken@0
   113
slouken@0
   114
		temp = SDL_LoadBMP("icon.bmp");
slouken@0
   115
		if ( temp == NULL ) {
slouken@0
   116
			return;
slouken@0
   117
		}
slouken@0
   118
		image = SDL_CreateRGBSurface(
slouken@0
   119
				SDL_SWSURFACE,
slouken@0
   120
				temp->w, temp->h,
slouken@0
   121
				32,
slouken@0
   122
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@0
   123
				0x000000FF, 
slouken@0
   124
				0x0000FF00, 
slouken@0
   125
				0x00FF0000, 
slouken@0
   126
 			       0xFF000000
slouken@0
   127
#else
slouken@0
   128
 			       0xFF000000,
slouken@0
   129
 			       0x00FF0000, 
slouken@0
   130
 			       0x0000FF00, 
slouken@0
   131
 			       0x000000FF
slouken@0
   132
#endif
slouken@0
   133
 			       );
slouken@0
   134
		if ( image != NULL ) {
slouken@0
   135
			SDL_BlitSurface(temp, NULL, image, NULL);
slouken@0
   136
		}
slouken@0
   137
		SDL_FreeSurface(temp);
slouken@0
   138
		if ( image == NULL ) {
slouken@0
   139
			return;
slouken@0
   140
		}
slouken@0
   141
	}
slouken@0
   142
slouken@0
   143
	screen = SDL_GetVideoSurface();
slouken@0
   144
slouken@0
   145
	/* Show the image on the screen */
slouken@0
   146
	dst.x = x;
slouken@0
   147
	dst.y = y;
slouken@0
   148
	dst.w = image->w;
slouken@0
   149
	dst.h = image->h;
slouken@0
   150
slouken@0
   151
	/* Move it around
slouken@0
   152
           Note that we do not clear the old position.  This is because we
slouken@0
   153
           perform a glClear() which clears the framebuffer and then only
slouken@0
   154
           update the new area.
slouken@0
   155
           Note that you can also achieve interesting effects by modifying
slouken@0
   156
           the screen surface alpha channel.  It's set to 255 by default..
slouken@0
   157
         */
slouken@0
   158
	if ( (SDL_GetTicks() - last_moved) > 100 ) {
slouken@0
   159
		x += delta_x;
slouken@0
   160
		if ( x < 0 ) {
slouken@0
   161
			x = 0;
slouken@0
   162
			delta_x = -delta_x;
slouken@0
   163
		} else
slouken@0
   164
		if ( (x+image->w) > screen->w ) {
slouken@0
   165
			x = screen->w-image->w;
slouken@0
   166
			delta_x = -delta_x;
slouken@0
   167
		}
slouken@0
   168
		y += delta_y;
slouken@0
   169
		if ( y < 0 ) {
slouken@0
   170
			y = 0;
slouken@0
   171
			delta_y = -delta_y;
slouken@0
   172
		} else
slouken@0
   173
		if ( (y+image->h) > screen->h ) {
slouken@0
   174
			y = screen->h-image->h;
slouken@0
   175
			delta_y = -delta_y;
slouken@0
   176
		}
slouken@0
   177
		SDL_BlitSurface(image, NULL, screen, &dst);
slouken@0
   178
	}
slouken@0
   179
	SDL_UpdateRects(screen, 1, &dst);
slouken@0
   180
}
slouken@0
   181
slouken@0
   182
int RunGLTest( int argc, char* argv[],
slouken@0
   183
               int logo, int slowly, int bpp, float gamma )
slouken@0
   184
{
slouken@0
   185
	int i;
slouken@0
   186
	int rgb_size[3];
slouken@0
   187
	int w = 640;
slouken@0
   188
	int h = 480;
slouken@0
   189
	int done = 0;
slouken@0
   190
	int frames;
slouken@0
   191
	Uint32 start_time, this_time;
slouken@0
   192
        float color[8][3]= {{ 1.0,  1.0,  0.0}, 
slouken@0
   193
			    { 1.0,  0.0,  0.0},
slouken@0
   194
			    { 0.0,  0.0,  0.0},
slouken@0
   195
			    { 0.0,  1.0,  0.0},
slouken@0
   196
			    { 0.0,  1.0,  1.0},
slouken@0
   197
			    { 1.0,  1.0,  1.0},
slouken@0
   198
			    { 1.0,  0.0,  1.0},
slouken@0
   199
			    { 0.0,  0.0,  1.0}};
slouken@0
   200
	float cube[8][3]= {{ 0.5,  0.5, -0.5}, 
slouken@0
   201
			   { 0.5, -0.5, -0.5},
slouken@0
   202
			   {-0.5, -0.5, -0.5},
slouken@0
   203
			   {-0.5,  0.5, -0.5},
slouken@0
   204
			   {-0.5,  0.5,  0.5},
slouken@0
   205
			   { 0.5,  0.5,  0.5},
slouken@0
   206
			   { 0.5, -0.5,  0.5},
slouken@0
   207
			   {-0.5, -0.5,  0.5}};
slouken@0
   208
	Uint32 video_flags;
slouken@0
   209
	int value;
slouken@0
   210
slouken@0
   211
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
slouken@0
   212
		fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
slouken@0
   213
		exit( 1 );
slouken@0
   214
	}
slouken@0
   215
slouken@0
   216
	/* See if we should detect the display depth */
slouken@0
   217
	if ( bpp == 0 ) {
slouken@0
   218
		if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
slouken@0
   219
			bpp = 8;
slouken@0
   220
		} else {
slouken@0
   221
			bpp = 16;  /* More doesn't seem to work */
slouken@0
   222
		}
slouken@0
   223
	}
slouken@0
   224
slouken@0
   225
	/* Set the flags we want to use for setting the video mode */
slouken@0
   226
	if ( logo ) {
slouken@0
   227
		video_flags = SDL_OPENGLBLIT;
slouken@0
   228
	} else {
slouken@0
   229
		video_flags = SDL_OPENGL;
slouken@0
   230
	}
slouken@0
   231
	for ( i=1; argv[i]; ++i ) {
slouken@0
   232
		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
slouken@0
   233
			video_flags |= SDL_FULLSCREEN;
slouken@0
   234
		}
slouken@0
   235
	}
slouken@0
   236
slouken@0
   237
	/* Initialize the display */
slouken@0
   238
	switch (bpp) {
slouken@0
   239
	    case 8:
slouken@0
   240
		rgb_size[0] = 2;
slouken@0
   241
		rgb_size[1] = 3;
slouken@0
   242
		rgb_size[2] = 3;
slouken@0
   243
		break;
slouken@0
   244
	    case 15:
slouken@0
   245
	    case 16:
slouken@0
   246
		rgb_size[0] = 5;
slouken@0
   247
		rgb_size[1] = 5;
slouken@0
   248
		rgb_size[2] = 5;
slouken@0
   249
		break;
slouken@0
   250
            default:
slouken@0
   251
		rgb_size[0] = 8;
slouken@0
   252
		rgb_size[1] = 8;
slouken@0
   253
		rgb_size[2] = 8;
slouken@0
   254
		break;
slouken@0
   255
	}
slouken@0
   256
	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
slouken@0
   257
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
slouken@0
   258
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
slouken@0
   259
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
slouken@0
   260
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
slouken@0
   261
	if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
slouken@0
   262
		fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
slouken@0
   263
		SDL_Quit();
slouken@0
   264
		exit(1);
slouken@0
   265
	}
slouken@0
   266
slouken@0
   267
	printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
slouken@0
   268
	printf("\n");
slouken@0
   269
	printf( "Vendor     : %s\n", glGetString( GL_VENDOR ) );
slouken@0
   270
	printf( "Renderer   : %s\n", glGetString( GL_RENDERER ) );
slouken@0
   271
	printf( "Version    : %s\n", glGetString( GL_VERSION ) );
slouken@0
   272
	printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
slouken@0
   273
	printf("\n");
slouken@0
   274
slouken@0
   275
	SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
slouken@0
   276
	printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
slouken@0
   277
	SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
slouken@0
   278
	printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
slouken@0
   279
	SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
slouken@0
   280
	printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
slouken@0
   281
	SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
slouken@0
   282
	printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
slouken@0
   283
	SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
slouken@0
   284
	printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
slouken@0
   285
slouken@0
   286
	/* Set the window manager title bar */
slouken@0
   287
	SDL_WM_SetCaption( "SDL GL test", "testgl" );
slouken@0
   288
slouken@0
   289
	/* Set the gamma for the window */
slouken@0
   290
	if ( gamma != 0.0 ) {
slouken@0
   291
		SDL_SetGamma(gamma, gamma, gamma);
slouken@0
   292
	}
slouken@0
   293
slouken@0
   294
	glViewport( 0, 0, w, h );
slouken@0
   295
	glMatrixMode( GL_PROJECTION );
slouken@0
   296
	glLoadIdentity( );
slouken@0
   297
slouken@0
   298
	glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
slouken@0
   299
slouken@0
   300
	glMatrixMode( GL_MODELVIEW );
slouken@0
   301
	glLoadIdentity( );
slouken@0
   302
slouken@0
   303
	glEnable(GL_DEPTH_TEST);
slouken@0
   304
slouken@0
   305
	glDepthFunc(GL_LESS);
slouken@0
   306
slouken@0
   307
	glShadeModel(GL_SMOOTH);
slouken@0
   308
slouken@0
   309
	/* Loop until done. */
slouken@0
   310
	start_time = SDL_GetTicks();
slouken@0
   311
	frames = 0;
slouken@0
   312
	while( !done ) {
slouken@0
   313
		GLenum gl_error;
slouken@0
   314
		char* sdl_error;
slouken@0
   315
		SDL_Event event;
slouken@0
   316
slouken@0
   317
		/* Do our drawing, too. */
slouken@0
   318
		glClearColor( 0.0, 0.0, 0.0, 1.0 );
slouken@0
   319
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slouken@0
   320
slouken@0
   321
		glBegin( GL_QUADS );
slouken@0
   322
slouken@0
   323
#ifdef SHADED_CUBE
slouken@0
   324
			glColor3fv(color[0]);
slouken@0
   325
			glVertex3fv(cube[0]);
slouken@0
   326
			glColor3fv(color[1]);
slouken@0
   327
			glVertex3fv(cube[1]);
slouken@0
   328
			glColor3fv(color[2]);
slouken@0
   329
			glVertex3fv(cube[2]);
slouken@0
   330
			glColor3fv(color[3]);
slouken@0
   331
			glVertex3fv(cube[3]);
slouken@0
   332
			
slouken@0
   333
			glColor3fv(color[3]);
slouken@0
   334
			glVertex3fv(cube[3]);
slouken@0
   335
			glColor3fv(color[4]);
slouken@0
   336
			glVertex3fv(cube[4]);
slouken@0
   337
			glColor3fv(color[7]);
slouken@0
   338
			glVertex3fv(cube[7]);
slouken@0
   339
			glColor3fv(color[2]);
slouken@0
   340
			glVertex3fv(cube[2]);
slouken@0
   341
			
slouken@0
   342
			glColor3fv(color[0]);
slouken@0
   343
			glVertex3fv(cube[0]);
slouken@0
   344
			glColor3fv(color[5]);
slouken@0
   345
			glVertex3fv(cube[5]);
slouken@0
   346
			glColor3fv(color[6]);
slouken@0
   347
			glVertex3fv(cube[6]);
slouken@0
   348
			glColor3fv(color[1]);
slouken@0
   349
			glVertex3fv(cube[1]);
slouken@0
   350
			
slouken@0
   351
			glColor3fv(color[5]);
slouken@0
   352
			glVertex3fv(cube[5]);
slouken@0
   353
			glColor3fv(color[4]);
slouken@0
   354
			glVertex3fv(cube[4]);
slouken@0
   355
			glColor3fv(color[7]);
slouken@0
   356
			glVertex3fv(cube[7]);
slouken@0
   357
			glColor3fv(color[6]);
slouken@0
   358
			glVertex3fv(cube[6]);
slouken@0
   359
slouken@0
   360
			glColor3fv(color[5]);
slouken@0
   361
			glVertex3fv(cube[5]);
slouken@0
   362
			glColor3fv(color[0]);
slouken@0
   363
			glVertex3fv(cube[0]);
slouken@0
   364
			glColor3fv(color[3]);
slouken@0
   365
			glVertex3fv(cube[3]);
slouken@0
   366
			glColor3fv(color[4]);
slouken@0
   367
			glVertex3fv(cube[4]);
slouken@0
   368
slouken@0
   369
			glColor3fv(color[6]);
slouken@0
   370
			glVertex3fv(cube[6]);
slouken@0
   371
			glColor3fv(color[1]);
slouken@0
   372
			glVertex3fv(cube[1]);
slouken@0
   373
			glColor3fv(color[2]);
slouken@0
   374
			glVertex3fv(cube[2]);
slouken@0
   375
			glColor3fv(color[7]);
slouken@0
   376
			glVertex3fv(cube[7]);
slouken@0
   377
#else // flat cube
slouken@0
   378
			glColor3f(1.0, 0.0, 0.0);
slouken@0
   379
			glVertex3fv(cube[0]);
slouken@0
   380
			glVertex3fv(cube[1]);
slouken@0
   381
			glVertex3fv(cube[2]);
slouken@0
   382
			glVertex3fv(cube[3]);
slouken@0
   383
			
slouken@0
   384
			glColor3f(0.0, 1.0, 0.0);
slouken@0
   385
			glVertex3fv(cube[3]);
slouken@0
   386
			glVertex3fv(cube[4]);
slouken@0
   387
			glVertex3fv(cube[7]);
slouken@0
   388
			glVertex3fv(cube[2]);
slouken@0
   389
			
slouken@0
   390
			glColor3f(0.0, 0.0, 1.0);
slouken@0
   391
			glVertex3fv(cube[0]);
slouken@0
   392
			glVertex3fv(cube[5]);
slouken@0
   393
			glVertex3fv(cube[6]);
slouken@0
   394
			glVertex3fv(cube[1]);
slouken@0
   395
			
slouken@0
   396
			glColor3f(0.0, 1.0, 1.0);
slouken@0
   397
			glVertex3fv(cube[5]);
slouken@0
   398
			glVertex3fv(cube[4]);
slouken@0
   399
			glVertex3fv(cube[7]);
slouken@0
   400
			glVertex3fv(cube[6]);
slouken@0
   401
slouken@0
   402
			glColor3f(1.0, 1.0, 0.0);
slouken@0
   403
			glVertex3fv(cube[5]);
slouken@0
   404
			glVertex3fv(cube[0]);
slouken@0
   405
			glVertex3fv(cube[3]);
slouken@0
   406
			glVertex3fv(cube[4]);
slouken@0
   407
slouken@0
   408
			glColor3f(1.0, 0.0, 1.0);
slouken@0
   409
			glVertex3fv(cube[6]);
slouken@0
   410
			glVertex3fv(cube[1]);
slouken@0
   411
			glVertex3fv(cube[2]);
slouken@0
   412
			glVertex3fv(cube[7]);
slouken@0
   413
#endif /* SHADED_CUBE */
slouken@0
   414
slouken@0
   415
		glEnd( );
slouken@0
   416
		
slouken@0
   417
		glMatrixMode(GL_MODELVIEW);
slouken@0
   418
		glRotatef(5.0, 1.0, 1.0, 1.0);
slouken@0
   419
slouken@0
   420
		/* Draw 2D logo onto the 3D display */
slouken@0
   421
		if ( logo ) {
slouken@0
   422
			DrawSDLLogo();
slouken@0
   423
		}
slouken@0
   424
slouken@0
   425
		SDL_GL_SwapBuffers( );
slouken@0
   426
slouken@0
   427
		/* Check for error conditions. */
slouken@0
   428
		gl_error = glGetError( );
slouken@0
   429
slouken@0
   430
		if( gl_error != GL_NO_ERROR ) {
slouken@0
   431
			fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
slouken@0
   432
		}
slouken@0
   433
slouken@0
   434
		sdl_error = SDL_GetError( );
slouken@0
   435
slouken@0
   436
		if( sdl_error[0] != '\0' ) {
slouken@0
   437
			fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
slouken@0
   438
			SDL_ClearError();
slouken@0
   439
		}
slouken@0
   440
slouken@0
   441
		/* Allow the user to see what's happening */
slouken@0
   442
		if ( slowly ) {
slouken@0
   443
			SDL_Delay( 20 );
slouken@0
   444
		}
slouken@0
   445
slouken@0
   446
		/* Check if there's a pending event. */
slouken@0
   447
		while( SDL_PollEvent( &event ) ) {
slouken@0
   448
			done = HandleEvent(&event);
slouken@0
   449
		}
slouken@0
   450
		++frames;
slouken@0
   451
	}
slouken@0
   452
slouken@0
   453
	/* Print out the frames per second */
slouken@0
   454
	this_time = SDL_GetTicks();
slouken@0
   455
	if ( this_time != start_time ) {
slouken@0
   456
		printf("%2.2f FPS\n",
slouken@0
   457
			((float)frames/(this_time-start_time))*1000.0);
slouken@0
   458
	}
slouken@0
   459
slouken@0
   460
	/* Destroy our GL context, etc. */
slouken@0
   461
	SDL_Quit( );
slouken@0
   462
	return(0);
slouken@0
   463
}
slouken@0
   464
slouken@0
   465
int main(int argc, char *argv[])
slouken@0
   466
{
slouken@0
   467
	int i, logo;
slouken@0
   468
	int numtests;
slouken@0
   469
	int bpp = 0;
slouken@0
   470
	int slowly;
slouken@0
   471
	float gamma = 0.0;
slouken@0
   472
slouken@0
   473
	logo = 0;
slouken@0
   474
	slowly = 0;
slouken@0
   475
	numtests = 1;
slouken@0
   476
	for ( i=1; argv[i]; ++i ) {
slouken@0
   477
		if ( strcmp(argv[i], "-twice") == 0 ) {
slouken@0
   478
			++numtests;
slouken@0
   479
		}
slouken@0
   480
		if ( strcmp(argv[i], "-logo") == 0 ) {
slouken@0
   481
			logo = 1;
slouken@0
   482
		}
slouken@0
   483
		if ( strcmp(argv[i], "-slow") == 0 ) {
slouken@0
   484
			slowly = 1;
slouken@0
   485
		}
slouken@0
   486
		if ( strcmp(argv[i], "-bpp") == 0 ) {
slouken@0
   487
 		       bpp = atoi(argv[++i]);
slouken@0
   488
		}
slouken@0
   489
		if ( strcmp(argv[i], "-gamma") == 0 ) {
slouken@0
   490
 		       gamma = (float)atof(argv[++i]);
slouken@0
   491
		}
slouken@0
   492
		if ( strncmp(argv[i], "-h", 2) == 0 ) {
slouken@0
   493
 		       printf(
slouken@0
   494
"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n",
slouken@0
   495
 			      argv[0]);
slouken@0
   496
			exit(0);
slouken@0
   497
		}
slouken@0
   498
	}
slouken@0
   499
	for ( i=0; i<numtests; ++i ) {
slouken@0
   500
 	       RunGLTest(argc, argv, logo, slowly, bpp, gamma);
slouken@0
   501
	}
slouken@0
   502
	return 0;
slouken@0
   503
}
slouken@0
   504
slouken@0
   505
#else /* HAVE_OPENGL */
slouken@0
   506
slouken@0
   507
int main(int argc, char *argv[])
slouken@0
   508
{
slouken@0
   509
	printf("No OpenGL support on this system\n");
slouken@0
   510
	return 1;
slouken@0
   511
}
slouken@0
   512
slouken@0
   513
#endif /* HAVE_OPENGL */