test/testgl.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 06 Nov 2001 00:15:24 +0000
changeset 233 5b42a7f5fab3
parent 221 50620ec9c86a
child 234 1af4be6a73cd
permissions -rw-r--r--
SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
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
slouken@0
    11
#define SHADED_CUBE
slouken@0
    12
slouken@233
    13
static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
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@233
    99
void SDL_GL_Enter2DMode()
slouken@233
   100
{
slouken@233
   101
	SDL_Surface *screen = SDL_GetVideoSurface();
slouken@233
   102
slouken@233
   103
	/* Note, there may be other things you need to change,
slouken@233
   104
	   depending on how you have your OpenGL state set up.
slouken@233
   105
	*/
slouken@233
   106
	glPushAttrib(GL_ENABLE_BIT);
slouken@233
   107
	glDisable(GL_DEPTH_TEST);
slouken@233
   108
	glDisable(GL_CULL_FACE);
slouken@233
   109
	glEnable(GL_TEXTURE_2D);
slouken@233
   110
slouken@233
   111
	glViewport(0, 0, screen->w, screen->h);
slouken@233
   112
slouken@233
   113
	glMatrixMode(GL_PROJECTION);
slouken@233
   114
	glPushMatrix();
slouken@233
   115
	glLoadIdentity();
slouken@233
   116
slouken@233
   117
	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
slouken@233
   118
slouken@233
   119
	glMatrixMode(GL_MODELVIEW);
slouken@233
   120
	glPushMatrix();
slouken@233
   121
	glLoadIdentity();
slouken@233
   122
slouken@233
   123
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
slouken@233
   124
}
slouken@233
   125
slouken@233
   126
void SDL_GL_Leave2DMode()
slouken@233
   127
{
slouken@233
   128
	glMatrixMode(GL_MODELVIEW);
slouken@233
   129
	glPopMatrix();
slouken@233
   130
slouken@233
   131
	glMatrixMode(GL_PROJECTION);
slouken@233
   132
	glPopMatrix();
slouken@233
   133
slouken@233
   134
	glPopAttrib();
slouken@233
   135
}
slouken@233
   136
slouken@0
   137
void DrawSDLLogo(void)
slouken@0
   138
{
slouken@0
   139
	static SDL_Surface *image = NULL;
slouken@233
   140
	static GLuint texture;
slouken@0
   141
	static int x = 0;
slouken@0
   142
	static int y = 0;
slouken@233
   143
	static int w, h;
slouken@0
   144
	static int delta_x = 1;
slouken@0
   145
	static int delta_y = 1;
slouken@0
   146
	static Uint32 last_moved = 0;
slouken@0
   147
slouken@0
   148
	SDL_Rect dst;
slouken@0
   149
	SDL_Surface *screen;
slouken@0
   150
slouken@0
   151
	if ( image == NULL ) {
slouken@0
   152
		SDL_Surface *temp;
slouken@0
   153
slouken@0
   154
		temp = SDL_LoadBMP("icon.bmp");
slouken@0
   155
		if ( temp == NULL ) {
slouken@0
   156
			return;
slouken@0
   157
		}
slouken@0
   158
		image = SDL_CreateRGBSurface(
slouken@0
   159
				SDL_SWSURFACE,
slouken@0
   160
				temp->w, temp->h,
slouken@0
   161
				32,
slouken@233
   162
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
slouken@0
   163
				0x000000FF, 
slouken@0
   164
				0x0000FF00, 
slouken@0
   165
				0x00FF0000, 
slouken@233
   166
				0xFF000000
slouken@0
   167
#else
slouken@233
   168
				0xFF000000,
slouken@233
   169
				0x00FF0000, 
slouken@233
   170
				0x0000FF00, 
slouken@233
   171
				0x000000FF
slouken@0
   172
#endif
slouken@0
   173
 			       );
slouken@0
   174
		if ( image != NULL ) {
slouken@0
   175
			SDL_BlitSurface(temp, NULL, image, NULL);
slouken@0
   176
		}
slouken@0
   177
		SDL_FreeSurface(temp);
slouken@0
   178
		if ( image == NULL ) {
slouken@0
   179
			return;
slouken@0
   180
		}
slouken@233
   181
		w = image->w;
slouken@233
   182
		h = image->h;
slouken@233
   183
slouken@233
   184
		/* Create an OpenGL texture for the image */
slouken@233
   185
		if ( ! USE_DEPRECATED_OPENGLBLIT ) {
slouken@233
   186
			glGenTextures(1, &texture);
slouken@233
   187
			glBindTexture(GL_TEXTURE_2D, texture);
slouken@233
   188
			glTexParameteri(GL_TEXTURE_2D,
slouken@233
   189
			                GL_TEXTURE_MAG_FILTER,
slouken@233
   190
			                GL_NEAREST);
slouken@233
   191
			glTexParameteri(GL_TEXTURE_2D,
slouken@233
   192
			                GL_TEXTURE_MIN_FILTER,
slouken@233
   193
			                GL_NEAREST);
slouken@233
   194
			glTexImage2D(GL_TEXTURE_2D,
slouken@233
   195
			             0,
slouken@233
   196
			             GL_RGBA,
slouken@233
   197
			             w, h,
slouken@233
   198
			             0,
slouken@233
   199
			             GL_RGBA,
slouken@233
   200
			             GL_UNSIGNED_BYTE,
slouken@233
   201
			             image->pixels);
slouken@233
   202
			SDL_FreeSurface(image); /* No longer needed */
slouken@233
   203
		}
slouken@0
   204
	}
slouken@0
   205
slouken@0
   206
	screen = SDL_GetVideoSurface();
slouken@0
   207
slouken@0
   208
	/* Show the image on the screen */
slouken@0
   209
	dst.x = x;
slouken@0
   210
	dst.y = y;
slouken@233
   211
	dst.w = w;
slouken@233
   212
	dst.h = h;
slouken@0
   213
slouken@0
   214
	/* Move it around
slouken@0
   215
           Note that we do not clear the old position.  This is because we
slouken@0
   216
           perform a glClear() which clears the framebuffer and then only
slouken@0
   217
           update the new area.
slouken@0
   218
           Note that you can also achieve interesting effects by modifying
slouken@0
   219
           the screen surface alpha channel.  It's set to 255 by default..
slouken@0
   220
         */
slouken@0
   221
	if ( (SDL_GetTicks() - last_moved) > 100 ) {
slouken@0
   222
		x += delta_x;
slouken@0
   223
		if ( x < 0 ) {
slouken@0
   224
			x = 0;
slouken@0
   225
			delta_x = -delta_x;
slouken@0
   226
		} else
slouken@233
   227
		if ( (x+w) > screen->w ) {
slouken@233
   228
			x = screen->w-w;
slouken@0
   229
			delta_x = -delta_x;
slouken@0
   230
		}
slouken@0
   231
		y += delta_y;
slouken@0
   232
		if ( y < 0 ) {
slouken@0
   233
			y = 0;
slouken@0
   234
			delta_y = -delta_y;
slouken@0
   235
		} else
slouken@233
   236
		if ( (y+h) > screen->h ) {
slouken@233
   237
			y = screen->h-h;
slouken@0
   238
			delta_y = -delta_y;
slouken@0
   239
		}
slouken@233
   240
		if ( USE_DEPRECATED_OPENGLBLIT ) {
slouken@233
   241
			SDL_BlitSurface(image, NULL, screen, &dst);
slouken@233
   242
		} else {
slouken@233
   243
			SDL_GL_Enter2DMode();
slouken@233
   244
			glBindTexture(GL_TEXTURE_2D, texture);
slouken@233
   245
			glBegin(GL_TRIANGLE_STRIP);
slouken@233
   246
			glTexCoord2f(0.0, 0.0); glVertex2i(x,   y  );
slouken@233
   247
			glTexCoord2f(1.0, 0.0); glVertex2i(x+w, y  );
slouken@233
   248
			glTexCoord2f(0.0, 1.0); glVertex2i(x,   y+h);
slouken@233
   249
			glTexCoord2f(1.0, 1.0); glVertex2i(x+w, y+h);
slouken@233
   250
			glEnd();
slouken@233
   251
			SDL_GL_Leave2DMode();
slouken@233
   252
		}
slouken@0
   253
	}
slouken@233
   254
	if ( USE_DEPRECATED_OPENGLBLIT ) {
slouken@233
   255
		SDL_UpdateRects(screen, 1, &dst);
slouken@233
   256
	}
slouken@0
   257
}
slouken@0
   258
slouken@0
   259
int RunGLTest( int argc, char* argv[],
slouken@0
   260
               int logo, int slowly, int bpp, float gamma )
slouken@0
   261
{
slouken@0
   262
	int i;
slouken@0
   263
	int rgb_size[3];
slouken@0
   264
	int w = 640;
slouken@0
   265
	int h = 480;
slouken@0
   266
	int done = 0;
slouken@0
   267
	int frames;
slouken@0
   268
	Uint32 start_time, this_time;
slouken@0
   269
        float color[8][3]= {{ 1.0,  1.0,  0.0}, 
slouken@0
   270
			    { 1.0,  0.0,  0.0},
slouken@0
   271
			    { 0.0,  0.0,  0.0},
slouken@0
   272
			    { 0.0,  1.0,  0.0},
slouken@0
   273
			    { 0.0,  1.0,  1.0},
slouken@0
   274
			    { 1.0,  1.0,  1.0},
slouken@0
   275
			    { 1.0,  0.0,  1.0},
slouken@0
   276
			    { 0.0,  0.0,  1.0}};
slouken@0
   277
	float cube[8][3]= {{ 0.5,  0.5, -0.5}, 
slouken@0
   278
			   { 0.5, -0.5, -0.5},
slouken@0
   279
			   {-0.5, -0.5, -0.5},
slouken@0
   280
			   {-0.5,  0.5, -0.5},
slouken@0
   281
			   {-0.5,  0.5,  0.5},
slouken@0
   282
			   { 0.5,  0.5,  0.5},
slouken@0
   283
			   { 0.5, -0.5,  0.5},
slouken@0
   284
			   {-0.5, -0.5,  0.5}};
slouken@0
   285
	Uint32 video_flags;
slouken@0
   286
	int value;
slouken@0
   287
slouken@0
   288
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
slouken@0
   289
		fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
slouken@0
   290
		exit( 1 );
slouken@0
   291
	}
slouken@0
   292
slouken@0
   293
	/* See if we should detect the display depth */
slouken@0
   294
	if ( bpp == 0 ) {
slouken@0
   295
		if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
slouken@0
   296
			bpp = 8;
slouken@0
   297
		} else {
slouken@0
   298
			bpp = 16;  /* More doesn't seem to work */
slouken@0
   299
		}
slouken@0
   300
	}
slouken@0
   301
slouken@0
   302
	/* Set the flags we want to use for setting the video mode */
slouken@233
   303
	if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
slouken@0
   304
		video_flags = SDL_OPENGLBLIT;
slouken@0
   305
	} else {
slouken@0
   306
		video_flags = SDL_OPENGL;
slouken@0
   307
	}
slouken@0
   308
	for ( i=1; argv[i]; ++i ) {
slouken@0
   309
		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
slouken@0
   310
			video_flags |= SDL_FULLSCREEN;
slouken@0
   311
		}
slouken@0
   312
	}
slouken@0
   313
slouken@0
   314
	/* Initialize the display */
slouken@0
   315
	switch (bpp) {
slouken@0
   316
	    case 8:
slouken@0
   317
		rgb_size[0] = 2;
slouken@0
   318
		rgb_size[1] = 3;
slouken@0
   319
		rgb_size[2] = 3;
slouken@0
   320
		break;
slouken@0
   321
	    case 15:
slouken@0
   322
	    case 16:
slouken@0
   323
		rgb_size[0] = 5;
slouken@0
   324
		rgb_size[1] = 5;
slouken@0
   325
		rgb_size[2] = 5;
slouken@0
   326
		break;
slouken@0
   327
            default:
slouken@0
   328
		rgb_size[0] = 8;
slouken@0
   329
		rgb_size[1] = 8;
slouken@0
   330
		rgb_size[2] = 8;
slouken@0
   331
		break;
slouken@0
   332
	}
slouken@0
   333
	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
slouken@0
   334
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
slouken@0
   335
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
slouken@0
   336
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
slouken@0
   337
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
slouken@0
   338
	if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
slouken@0
   339
		fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
slouken@0
   340
		SDL_Quit();
slouken@0
   341
		exit(1);
slouken@0
   342
	}
slouken@0
   343
slouken@0
   344
	printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
slouken@0
   345
	printf("\n");
slouken@0
   346
	printf( "Vendor     : %s\n", glGetString( GL_VENDOR ) );
slouken@0
   347
	printf( "Renderer   : %s\n", glGetString( GL_RENDERER ) );
slouken@0
   348
	printf( "Version    : %s\n", glGetString( GL_VERSION ) );
slouken@0
   349
	printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
slouken@0
   350
	printf("\n");
slouken@0
   351
slouken@0
   352
	SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
slouken@0
   353
	printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
slouken@0
   354
	SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
slouken@0
   355
	printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
slouken@0
   356
	SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
slouken@0
   357
	printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
slouken@0
   358
	SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
slouken@0
   359
	printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
slouken@0
   360
	SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
slouken@0
   361
	printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
slouken@0
   362
slouken@0
   363
	/* Set the window manager title bar */
slouken@0
   364
	SDL_WM_SetCaption( "SDL GL test", "testgl" );
slouken@0
   365
slouken@0
   366
	/* Set the gamma for the window */
slouken@0
   367
	if ( gamma != 0.0 ) {
slouken@0
   368
		SDL_SetGamma(gamma, gamma, gamma);
slouken@0
   369
	}
slouken@0
   370
slouken@0
   371
	glViewport( 0, 0, w, h );
slouken@0
   372
	glMatrixMode( GL_PROJECTION );
slouken@0
   373
	glLoadIdentity( );
slouken@0
   374
slouken@0
   375
	glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
slouken@0
   376
slouken@0
   377
	glMatrixMode( GL_MODELVIEW );
slouken@0
   378
	glLoadIdentity( );
slouken@0
   379
slouken@0
   380
	glEnable(GL_DEPTH_TEST);
slouken@0
   381
slouken@0
   382
	glDepthFunc(GL_LESS);
slouken@0
   383
slouken@0
   384
	glShadeModel(GL_SMOOTH);
slouken@0
   385
slouken@0
   386
	/* Loop until done. */
slouken@0
   387
	start_time = SDL_GetTicks();
slouken@0
   388
	frames = 0;
slouken@0
   389
	while( !done ) {
slouken@0
   390
		GLenum gl_error;
slouken@0
   391
		char* sdl_error;
slouken@0
   392
		SDL_Event event;
slouken@0
   393
slouken@0
   394
		/* Do our drawing, too. */
slouken@0
   395
		glClearColor( 0.0, 0.0, 0.0, 1.0 );
slouken@0
   396
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slouken@0
   397
slouken@0
   398
		glBegin( GL_QUADS );
slouken@0
   399
slouken@0
   400
#ifdef SHADED_CUBE
slouken@0
   401
			glColor3fv(color[0]);
slouken@0
   402
			glVertex3fv(cube[0]);
slouken@0
   403
			glColor3fv(color[1]);
slouken@0
   404
			glVertex3fv(cube[1]);
slouken@0
   405
			glColor3fv(color[2]);
slouken@0
   406
			glVertex3fv(cube[2]);
slouken@0
   407
			glColor3fv(color[3]);
slouken@0
   408
			glVertex3fv(cube[3]);
slouken@0
   409
			
slouken@0
   410
			glColor3fv(color[3]);
slouken@0
   411
			glVertex3fv(cube[3]);
slouken@0
   412
			glColor3fv(color[4]);
slouken@0
   413
			glVertex3fv(cube[4]);
slouken@0
   414
			glColor3fv(color[7]);
slouken@0
   415
			glVertex3fv(cube[7]);
slouken@0
   416
			glColor3fv(color[2]);
slouken@0
   417
			glVertex3fv(cube[2]);
slouken@0
   418
			
slouken@0
   419
			glColor3fv(color[0]);
slouken@0
   420
			glVertex3fv(cube[0]);
slouken@0
   421
			glColor3fv(color[5]);
slouken@0
   422
			glVertex3fv(cube[5]);
slouken@0
   423
			glColor3fv(color[6]);
slouken@0
   424
			glVertex3fv(cube[6]);
slouken@0
   425
			glColor3fv(color[1]);
slouken@0
   426
			glVertex3fv(cube[1]);
slouken@0
   427
			
slouken@0
   428
			glColor3fv(color[5]);
slouken@0
   429
			glVertex3fv(cube[5]);
slouken@0
   430
			glColor3fv(color[4]);
slouken@0
   431
			glVertex3fv(cube[4]);
slouken@0
   432
			glColor3fv(color[7]);
slouken@0
   433
			glVertex3fv(cube[7]);
slouken@0
   434
			glColor3fv(color[6]);
slouken@0
   435
			glVertex3fv(cube[6]);
slouken@0
   436
slouken@0
   437
			glColor3fv(color[5]);
slouken@0
   438
			glVertex3fv(cube[5]);
slouken@0
   439
			glColor3fv(color[0]);
slouken@0
   440
			glVertex3fv(cube[0]);
slouken@0
   441
			glColor3fv(color[3]);
slouken@0
   442
			glVertex3fv(cube[3]);
slouken@0
   443
			glColor3fv(color[4]);
slouken@0
   444
			glVertex3fv(cube[4]);
slouken@0
   445
slouken@0
   446
			glColor3fv(color[6]);
slouken@0
   447
			glVertex3fv(cube[6]);
slouken@0
   448
			glColor3fv(color[1]);
slouken@0
   449
			glVertex3fv(cube[1]);
slouken@0
   450
			glColor3fv(color[2]);
slouken@0
   451
			glVertex3fv(cube[2]);
slouken@0
   452
			glColor3fv(color[7]);
slouken@0
   453
			glVertex3fv(cube[7]);
slouken@0
   454
#else // flat cube
slouken@0
   455
			glColor3f(1.0, 0.0, 0.0);
slouken@0
   456
			glVertex3fv(cube[0]);
slouken@0
   457
			glVertex3fv(cube[1]);
slouken@0
   458
			glVertex3fv(cube[2]);
slouken@0
   459
			glVertex3fv(cube[3]);
slouken@0
   460
			
slouken@0
   461
			glColor3f(0.0, 1.0, 0.0);
slouken@0
   462
			glVertex3fv(cube[3]);
slouken@0
   463
			glVertex3fv(cube[4]);
slouken@0
   464
			glVertex3fv(cube[7]);
slouken@0
   465
			glVertex3fv(cube[2]);
slouken@0
   466
			
slouken@0
   467
			glColor3f(0.0, 0.0, 1.0);
slouken@0
   468
			glVertex3fv(cube[0]);
slouken@0
   469
			glVertex3fv(cube[5]);
slouken@0
   470
			glVertex3fv(cube[6]);
slouken@0
   471
			glVertex3fv(cube[1]);
slouken@0
   472
			
slouken@0
   473
			glColor3f(0.0, 1.0, 1.0);
slouken@0
   474
			glVertex3fv(cube[5]);
slouken@0
   475
			glVertex3fv(cube[4]);
slouken@0
   476
			glVertex3fv(cube[7]);
slouken@0
   477
			glVertex3fv(cube[6]);
slouken@0
   478
slouken@0
   479
			glColor3f(1.0, 1.0, 0.0);
slouken@0
   480
			glVertex3fv(cube[5]);
slouken@0
   481
			glVertex3fv(cube[0]);
slouken@0
   482
			glVertex3fv(cube[3]);
slouken@0
   483
			glVertex3fv(cube[4]);
slouken@0
   484
slouken@0
   485
			glColor3f(1.0, 0.0, 1.0);
slouken@0
   486
			glVertex3fv(cube[6]);
slouken@0
   487
			glVertex3fv(cube[1]);
slouken@0
   488
			glVertex3fv(cube[2]);
slouken@0
   489
			glVertex3fv(cube[7]);
slouken@0
   490
#endif /* SHADED_CUBE */
slouken@0
   491
slouken@0
   492
		glEnd( );
slouken@0
   493
		
slouken@0
   494
		glMatrixMode(GL_MODELVIEW);
slouken@0
   495
		glRotatef(5.0, 1.0, 1.0, 1.0);
slouken@0
   496
slouken@0
   497
		/* Draw 2D logo onto the 3D display */
slouken@0
   498
		if ( logo ) {
slouken@0
   499
			DrawSDLLogo();
slouken@0
   500
		}
slouken@0
   501
slouken@0
   502
		SDL_GL_SwapBuffers( );
slouken@0
   503
slouken@0
   504
		/* Check for error conditions. */
slouken@0
   505
		gl_error = glGetError( );
slouken@0
   506
slouken@0
   507
		if( gl_error != GL_NO_ERROR ) {
slouken@0
   508
			fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
slouken@0
   509
		}
slouken@0
   510
slouken@0
   511
		sdl_error = SDL_GetError( );
slouken@0
   512
slouken@0
   513
		if( sdl_error[0] != '\0' ) {
slouken@0
   514
			fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
slouken@0
   515
			SDL_ClearError();
slouken@0
   516
		}
slouken@0
   517
slouken@0
   518
		/* Allow the user to see what's happening */
slouken@0
   519
		if ( slowly ) {
slouken@0
   520
			SDL_Delay( 20 );
slouken@0
   521
		}
slouken@0
   522
slouken@0
   523
		/* Check if there's a pending event. */
slouken@0
   524
		while( SDL_PollEvent( &event ) ) {
slouken@0
   525
			done = HandleEvent(&event);
slouken@0
   526
		}
slouken@0
   527
		++frames;
slouken@0
   528
	}
slouken@0
   529
slouken@0
   530
	/* Print out the frames per second */
slouken@0
   531
	this_time = SDL_GetTicks();
slouken@0
   532
	if ( this_time != start_time ) {
slouken@0
   533
		printf("%2.2f FPS\n",
slouken@0
   534
			((float)frames/(this_time-start_time))*1000.0);
slouken@0
   535
	}
slouken@0
   536
slouken@0
   537
	/* Destroy our GL context, etc. */
slouken@0
   538
	SDL_Quit( );
slouken@0
   539
	return(0);
slouken@0
   540
}
slouken@0
   541
slouken@0
   542
int main(int argc, char *argv[])
slouken@0
   543
{
slouken@0
   544
	int i, logo;
slouken@0
   545
	int numtests;
slouken@0
   546
	int bpp = 0;
slouken@0
   547
	int slowly;
slouken@0
   548
	float gamma = 0.0;
slouken@0
   549
slouken@0
   550
	logo = 0;
slouken@0
   551
	slowly = 0;
slouken@0
   552
	numtests = 1;
slouken@0
   553
	for ( i=1; argv[i]; ++i ) {
slouken@0
   554
		if ( strcmp(argv[i], "-twice") == 0 ) {
slouken@0
   555
			++numtests;
slouken@0
   556
		}
slouken@0
   557
		if ( strcmp(argv[i], "-logo") == 0 ) {
slouken@0
   558
			logo = 1;
slouken@233
   559
			USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
slouken@233
   560
		}
slouken@233
   561
		if ( strcmp(argv[i], "-logoblit") == 0 ) {
slouken@233
   562
			logo = 1;
slouken@233
   563
			USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
slouken@0
   564
		}
slouken@0
   565
		if ( strcmp(argv[i], "-slow") == 0 ) {
slouken@0
   566
			slowly = 1;
slouken@0
   567
		}
slouken@0
   568
		if ( strcmp(argv[i], "-bpp") == 0 ) {
slouken@0
   569
 		       bpp = atoi(argv[++i]);
slouken@0
   570
		}
slouken@0
   571
		if ( strcmp(argv[i], "-gamma") == 0 ) {
slouken@0
   572
 		       gamma = (float)atof(argv[++i]);
slouken@0
   573
		}
slouken@0
   574
		if ( strncmp(argv[i], "-h", 2) == 0 ) {
slouken@0
   575
 		       printf(
slouken@0
   576
"Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n",
slouken@0
   577
 			      argv[0]);
slouken@0
   578
			exit(0);
slouken@0
   579
		}
slouken@0
   580
	}
slouken@0
   581
	for ( i=0; i<numtests; ++i ) {
slouken@0
   582
 	       RunGLTest(argc, argv, logo, slowly, bpp, gamma);
slouken@0
   583
	}
slouken@0
   584
	return 0;
slouken@0
   585
}
slouken@0
   586
slouken@0
   587
#else /* HAVE_OPENGL */
slouken@0
   588
slouken@0
   589
int main(int argc, char *argv[])
slouken@0
   590
{
slouken@0
   591
	printf("No OpenGL support on this system\n");
slouken@0
   592
	return 1;
slouken@0
   593
}
slouken@0
   594
slouken@0
   595
#endif /* HAVE_OPENGL */