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