test/testgl.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/test/testgl.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/testgl.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -25,735 +25,746 @@
     1.4  
     1.5  /**********************************************************************/
     1.6  
     1.7 -void HotKey_ToggleFullScreen(void)
     1.8 +void
     1.9 +HotKey_ToggleFullScreen (void)
    1.10  {
    1.11 -	SDL_Surface *screen;
    1.12 +    SDL_Surface *screen;
    1.13  
    1.14 -	screen = SDL_GetVideoSurface();
    1.15 -	if ( SDL_WM_ToggleFullScreen(screen) ) {
    1.16 -		printf("Toggled fullscreen mode - now %s\n",
    1.17 -		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    1.18 -	} else {
    1.19 -		printf("Unable to toggle fullscreen mode\n");
    1.20 -	}
    1.21 +    screen = SDL_GetVideoSurface ();
    1.22 +    if (SDL_WM_ToggleFullScreen (screen)) {
    1.23 +        printf ("Toggled fullscreen mode - now %s\n",
    1.24 +                (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    1.25 +    } else {
    1.26 +        printf ("Unable to toggle fullscreen mode\n");
    1.27 +    }
    1.28  }
    1.29  
    1.30 -void HotKey_ToggleGrab(void)
    1.31 +void
    1.32 +HotKey_ToggleGrab (void)
    1.33  {
    1.34 -	SDL_GrabMode mode;
    1.35 +    SDL_GrabMode mode;
    1.36  
    1.37 -	printf("Ctrl-G: toggling input grab!\n");
    1.38 -	mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
    1.39 -	if ( mode == SDL_GRAB_ON ) {
    1.40 -		printf("Grab was on\n");
    1.41 -	} else {
    1.42 -		printf("Grab was off\n");
    1.43 -	}
    1.44 -	mode = SDL_WM_GrabInput(!mode);
    1.45 -	if ( mode == SDL_GRAB_ON ) {
    1.46 -		printf("Grab is now on\n");
    1.47 -	} else {
    1.48 -		printf("Grab is now off\n");
    1.49 -	}
    1.50 +    printf ("Ctrl-G: toggling input grab!\n");
    1.51 +    mode = SDL_WM_GrabInput (SDL_GRAB_QUERY);
    1.52 +    if (mode == SDL_GRAB_ON) {
    1.53 +        printf ("Grab was on\n");
    1.54 +    } else {
    1.55 +        printf ("Grab was off\n");
    1.56 +    }
    1.57 +    mode = SDL_WM_GrabInput (!mode);
    1.58 +    if (mode == SDL_GRAB_ON) {
    1.59 +        printf ("Grab is now on\n");
    1.60 +    } else {
    1.61 +        printf ("Grab is now off\n");
    1.62 +    }
    1.63  }
    1.64  
    1.65 -void HotKey_Iconify(void)
    1.66 +void
    1.67 +HotKey_Iconify (void)
    1.68  {
    1.69 -	printf("Ctrl-Z: iconifying window!\n");
    1.70 -	SDL_WM_IconifyWindow();
    1.71 +    printf ("Ctrl-Z: iconifying window!\n");
    1.72 +    SDL_WM_IconifyWindow ();
    1.73  }
    1.74  
    1.75 -int HandleEvent(SDL_Event *event)
    1.76 +int
    1.77 +HandleEvent (SDL_Event * event)
    1.78  {
    1.79 -	int done;
    1.80 +    int done;
    1.81  
    1.82 -	done = 0;
    1.83 -	switch( event->type ) {
    1.84 -	    case SDL_ACTIVEEVENT:
    1.85 -		/* See what happened */
    1.86 -		printf( "app %s ", event->active.gain ? "gained" : "lost" );
    1.87 -		if ( event->active.state & SDL_APPACTIVE ) {
    1.88 -			printf( "active " );
    1.89 -		} else if ( event->active.state & SDL_APPMOUSEFOCUS ) {
    1.90 -			printf( "mouse " );
    1.91 -		} else if ( event->active.state & SDL_APPINPUTFOCUS ) {
    1.92 -			printf( "input " );
    1.93 -		}
    1.94 -		printf( "focus\n" );
    1.95 -		break;
    1.96 -		
    1.97 +    done = 0;
    1.98 +    switch (event->type) {
    1.99 +    case SDL_ACTIVEEVENT:
   1.100 +        /* See what happened */
   1.101 +        printf ("app %s ", event->active.gain ? "gained" : "lost");
   1.102 +        if (event->active.state & SDL_APPACTIVE) {
   1.103 +            printf ("active ");
   1.104 +        } else if (event->active.state & SDL_APPMOUSEFOCUS) {
   1.105 +            printf ("mouse ");
   1.106 +        } else if (event->active.state & SDL_APPINPUTFOCUS) {
   1.107 +            printf ("input ");
   1.108 +        }
   1.109 +        printf ("focus\n");
   1.110 +        break;
   1.111  
   1.112 -	    case SDL_KEYDOWN:
   1.113 -		if ( event->key.keysym.sym == SDLK_ESCAPE ) {
   1.114 -			done = 1;
   1.115 -		}
   1.116 -		if ( (event->key.keysym.sym == SDLK_g) &&
   1.117 -		     (event->key.keysym.mod & KMOD_CTRL) ) {
   1.118 -			HotKey_ToggleGrab();
   1.119 -		}
   1.120 -		if ( (event->key.keysym.sym == SDLK_z) &&
   1.121 -		     (event->key.keysym.mod & KMOD_CTRL) ) {
   1.122 -			HotKey_Iconify();
   1.123 -		}
   1.124 -		if ( (event->key.keysym.sym == SDLK_RETURN) &&
   1.125 -		     (event->key.keysym.mod & KMOD_ALT) ) {
   1.126 -			HotKey_ToggleFullScreen();
   1.127 -		}
   1.128 -		printf("key '%s' pressed\n", 
   1.129 -			SDL_GetKeyName(event->key.keysym.sym));
   1.130 -		break;
   1.131 -	    case SDL_QUIT:
   1.132 -		done = 1;
   1.133 -		break;
   1.134 -	}
   1.135 -	return(done);
   1.136 +
   1.137 +    case SDL_KEYDOWN:
   1.138 +        if (event->key.keysym.sym == SDLK_ESCAPE) {
   1.139 +            done = 1;
   1.140 +        }
   1.141 +        if ((event->key.keysym.sym == SDLK_g) &&
   1.142 +            (event->key.keysym.mod & KMOD_CTRL)) {
   1.143 +            HotKey_ToggleGrab ();
   1.144 +        }
   1.145 +        if ((event->key.keysym.sym == SDLK_z) &&
   1.146 +            (event->key.keysym.mod & KMOD_CTRL)) {
   1.147 +            HotKey_Iconify ();
   1.148 +        }
   1.149 +        if ((event->key.keysym.sym == SDLK_RETURN) &&
   1.150 +            (event->key.keysym.mod & KMOD_ALT)) {
   1.151 +            HotKey_ToggleFullScreen ();
   1.152 +        }
   1.153 +        printf ("key '%s' pressed\n", SDL_GetKeyName (event->key.keysym.sym));
   1.154 +        break;
   1.155 +    case SDL_QUIT:
   1.156 +        done = 1;
   1.157 +        break;
   1.158 +    }
   1.159 +    return (done);
   1.160  }
   1.161  
   1.162 -void SDL_GL_Enter2DMode()
   1.163 +void
   1.164 +SDL_GL_Enter2DMode ()
   1.165  {
   1.166 -	SDL_Surface *screen = SDL_GetVideoSurface();
   1.167 +    SDL_Surface *screen = SDL_GetVideoSurface ();
   1.168  
   1.169 -	/* Note, there may be other things you need to change,
   1.170 -	   depending on how you have your OpenGL state set up.
   1.171 -	*/
   1.172 -	glPushAttrib(GL_ENABLE_BIT);
   1.173 -	glDisable(GL_DEPTH_TEST);
   1.174 -	glDisable(GL_CULL_FACE);
   1.175 -	glEnable(GL_TEXTURE_2D);
   1.176 +    /* Note, there may be other things you need to change,
   1.177 +       depending on how you have your OpenGL state set up.
   1.178 +     */
   1.179 +    glPushAttrib (GL_ENABLE_BIT);
   1.180 +    glDisable (GL_DEPTH_TEST);
   1.181 +    glDisable (GL_CULL_FACE);
   1.182 +    glEnable (GL_TEXTURE_2D);
   1.183  
   1.184 -	/* This allows alpha blending of 2D textures with the scene */
   1.185 -	glEnable(GL_BLEND);
   1.186 -	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   1.187 +    /* This allows alpha blending of 2D textures with the scene */
   1.188 +    glEnable (GL_BLEND);
   1.189 +    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   1.190  
   1.191 -	glViewport(0, 0, screen->w, screen->h);
   1.192 +    glViewport (0, 0, screen->w, screen->h);
   1.193  
   1.194 -	glMatrixMode(GL_PROJECTION);
   1.195 -	glPushMatrix();
   1.196 -	glLoadIdentity();
   1.197 +    glMatrixMode (GL_PROJECTION);
   1.198 +    glPushMatrix ();
   1.199 +    glLoadIdentity ();
   1.200  
   1.201 -	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
   1.202 +    glOrtho (0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0);
   1.203  
   1.204 -	glMatrixMode(GL_MODELVIEW);
   1.205 -	glPushMatrix();
   1.206 -	glLoadIdentity();
   1.207 +    glMatrixMode (GL_MODELVIEW);
   1.208 +    glPushMatrix ();
   1.209 +    glLoadIdentity ();
   1.210  
   1.211 -	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   1.212 +    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   1.213  }
   1.214  
   1.215 -void SDL_GL_Leave2DMode()
   1.216 +void
   1.217 +SDL_GL_Leave2DMode ()
   1.218  {
   1.219 -	glMatrixMode(GL_MODELVIEW);
   1.220 -	glPopMatrix();
   1.221 +    glMatrixMode (GL_MODELVIEW);
   1.222 +    glPopMatrix ();
   1.223  
   1.224 -	glMatrixMode(GL_PROJECTION);
   1.225 -	glPopMatrix();
   1.226 +    glMatrixMode (GL_PROJECTION);
   1.227 +    glPopMatrix ();
   1.228  
   1.229 -	glPopAttrib();
   1.230 +    glPopAttrib ();
   1.231  }
   1.232  
   1.233  /* Quick utility function for texture creation */
   1.234 -static int power_of_two(int input)
   1.235 +static int
   1.236 +power_of_two (int input)
   1.237  {
   1.238 -	int value = 1;
   1.239 +    int value = 1;
   1.240  
   1.241 -	while ( value < input ) {
   1.242 -		value <<= 1;
   1.243 -	}
   1.244 -	return value;
   1.245 +    while (value < input) {
   1.246 +        value <<= 1;
   1.247 +    }
   1.248 +    return value;
   1.249  }
   1.250  
   1.251 -GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
   1.252 +GLuint
   1.253 +SDL_GL_LoadTexture (SDL_Surface * surface, GLfloat * texcoord)
   1.254  {
   1.255 -	GLuint texture;
   1.256 -	int w, h;
   1.257 -	SDL_Surface *image;
   1.258 -	SDL_Rect area;
   1.259 -	Uint32 saved_flags;
   1.260 -	Uint8  saved_alpha;
   1.261 +    GLuint texture;
   1.262 +    int w, h;
   1.263 +    SDL_Surface *image;
   1.264 +    SDL_Rect area;
   1.265 +    Uint32 saved_flags;
   1.266 +    Uint8 saved_alpha;
   1.267  
   1.268 -	/* Use the surface width and height expanded to powers of 2 */
   1.269 -	w = power_of_two(surface->w);
   1.270 -	h = power_of_two(surface->h);
   1.271 -	texcoord[0] = 0.0f;			/* Min X */
   1.272 -	texcoord[1] = 0.0f;			/* Min Y */
   1.273 -	texcoord[2] = (GLfloat)surface->w / w;	/* Max X */
   1.274 -	texcoord[3] = (GLfloat)surface->h / h;	/* Max Y */
   1.275 +    /* Use the surface width and height expanded to powers of 2 */
   1.276 +    w = power_of_two (surface->w);
   1.277 +    h = power_of_two (surface->h);
   1.278 +    texcoord[0] = 0.0f;         /* Min X */
   1.279 +    texcoord[1] = 0.0f;         /* Min Y */
   1.280 +    texcoord[2] = (GLfloat) surface->w / w;     /* Max X */
   1.281 +    texcoord[3] = (GLfloat) surface->h / h;     /* Max Y */
   1.282  
   1.283 -	image = SDL_CreateRGBSurface(
   1.284 -			SDL_SWSURFACE,
   1.285 -			w, h,
   1.286 -			32,
   1.287 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
   1.288 -			0x000000FF, 
   1.289 -			0x0000FF00, 
   1.290 -			0x00FF0000, 
   1.291 -			0xFF000000
   1.292 +    image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32,
   1.293 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN     /* OpenGL RGBA masks */
   1.294 +                                  0x000000FF,
   1.295 +                                  0x0000FF00, 0x00FF0000, 0xFF000000
   1.296  #else
   1.297 -			0xFF000000,
   1.298 -			0x00FF0000, 
   1.299 -			0x0000FF00, 
   1.300 -			0x000000FF
   1.301 +                                  0xFF000000,
   1.302 +                                  0x00FF0000, 0x0000FF00, 0x000000FF
   1.303  #endif
   1.304 -		       );
   1.305 -	if ( image == NULL ) {
   1.306 -		return 0;
   1.307 -	}
   1.308 +        );
   1.309 +    if (image == NULL) {
   1.310 +        return 0;
   1.311 +    }
   1.312  
   1.313 -	/* Save the alpha blending attributes */
   1.314 -	saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
   1.315 -	saved_alpha = surface->format->alpha;
   1.316 -	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
   1.317 -		SDL_SetAlpha(surface, 0, 0);
   1.318 -	}
   1.319 +    /* Save the alpha blending attributes */
   1.320 +    saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   1.321 +    saved_alpha = surface->format->alpha;
   1.322 +    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   1.323 +        SDL_SetAlpha (surface, 0, 0);
   1.324 +    }
   1.325  
   1.326 -	/* Copy the surface into the GL texture image */
   1.327 -	area.x = 0;
   1.328 -	area.y = 0;
   1.329 -	area.w = surface->w;
   1.330 -	area.h = surface->h;
   1.331 -	SDL_BlitSurface(surface, &area, image, &area);
   1.332 +    /* Copy the surface into the GL texture image */
   1.333 +    area.x = 0;
   1.334 +    area.y = 0;
   1.335 +    area.w = surface->w;
   1.336 +    area.h = surface->h;
   1.337 +    SDL_BlitSurface (surface, &area, image, &area);
   1.338  
   1.339 -	/* Restore the alpha blending attributes */
   1.340 -	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
   1.341 -		SDL_SetAlpha(surface, saved_flags, saved_alpha);
   1.342 -	}
   1.343 +    /* Restore the alpha blending attributes */
   1.344 +    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   1.345 +        SDL_SetAlpha (surface, saved_flags, saved_alpha);
   1.346 +    }
   1.347  
   1.348 -	/* Create an OpenGL texture for the image */
   1.349 -	glGenTextures(1, &texture);
   1.350 -	glBindTexture(GL_TEXTURE_2D, texture);
   1.351 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   1.352 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   1.353 -	glTexImage2D(GL_TEXTURE_2D,
   1.354 -		     0,
   1.355 -		     GL_RGBA,
   1.356 -		     w, h,
   1.357 -		     0,
   1.358 -		     GL_RGBA,
   1.359 -		     GL_UNSIGNED_BYTE,
   1.360 -		     image->pixels);
   1.361 -	SDL_FreeSurface(image); /* No longer needed */
   1.362 +    /* Create an OpenGL texture for the image */
   1.363 +    glGenTextures (1, &texture);
   1.364 +    glBindTexture (GL_TEXTURE_2D, texture);
   1.365 +    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   1.366 +    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   1.367 +    glTexImage2D (GL_TEXTURE_2D,
   1.368 +                  0,
   1.369 +                  GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
   1.370 +    SDL_FreeSurface (image);    /* No longer needed */
   1.371  
   1.372 -	return texture;
   1.373 +    return texture;
   1.374  }
   1.375  
   1.376 -void DrawLogoCursor(void)
   1.377 +void
   1.378 +DrawLogoCursor (void)
   1.379  {
   1.380 -	static GLfloat texMinX, texMinY;
   1.381 -	static GLfloat texMaxX, texMaxY;
   1.382 -	static int w, h;
   1.383 -	int x, y;
   1.384 +    static GLfloat texMinX, texMinY;
   1.385 +    static GLfloat texMaxX, texMaxY;
   1.386 +    static int w, h;
   1.387 +    int x, y;
   1.388  
   1.389 -	if ( ! cursor_texture ) {
   1.390 -		SDL_Surface *image;
   1.391 -		GLfloat texcoord[4];
   1.392 +    if (!cursor_texture) {
   1.393 +        SDL_Surface *image;
   1.394 +        GLfloat texcoord[4];
   1.395  
   1.396 -		/* Load the image (could use SDL_image library here) */
   1.397 -		image = SDL_LoadBMP(LOGO_FILE);
   1.398 -		if ( image == NULL ) {
   1.399 -			return;
   1.400 -		}
   1.401 -		w = image->w;
   1.402 -		h = image->h;
   1.403 +        /* Load the image (could use SDL_image library here) */
   1.404 +        image = SDL_LoadBMP (LOGO_FILE);
   1.405 +        if (image == NULL) {
   1.406 +            return;
   1.407 +        }
   1.408 +        w = image->w;
   1.409 +        h = image->h;
   1.410  
   1.411 -		/* Convert the image into an OpenGL texture */
   1.412 -		cursor_texture = SDL_GL_LoadTexture(image, texcoord);
   1.413 +        /* Convert the image into an OpenGL texture */
   1.414 +        cursor_texture = SDL_GL_LoadTexture (image, texcoord);
   1.415  
   1.416 -		/* Make texture coordinates easy to understand */
   1.417 -		texMinX = texcoord[0];
   1.418 -		texMinY = texcoord[1];
   1.419 -		texMaxX = texcoord[2];
   1.420 -		texMaxY = texcoord[3];
   1.421 +        /* Make texture coordinates easy to understand */
   1.422 +        texMinX = texcoord[0];
   1.423 +        texMinY = texcoord[1];
   1.424 +        texMaxX = texcoord[2];
   1.425 +        texMaxY = texcoord[3];
   1.426  
   1.427 -		/* We don't need the original image anymore */
   1.428 -		SDL_FreeSurface(image);
   1.429 +        /* We don't need the original image anymore */
   1.430 +        SDL_FreeSurface (image);
   1.431  
   1.432 -		/* Make sure that the texture conversion is okay */
   1.433 -		if ( ! cursor_texture ) {
   1.434 -			return;
   1.435 -		}
   1.436 -	}
   1.437 +        /* Make sure that the texture conversion is okay */
   1.438 +        if (!cursor_texture) {
   1.439 +            return;
   1.440 +        }
   1.441 +    }
   1.442  
   1.443 -	/* Move the image around */
   1.444 -	SDL_GetMouseState(&x, &y);
   1.445 -	x -= w/2;
   1.446 -	y -= h/2;
   1.447 +    /* Move the image around */
   1.448 +    SDL_GetMouseState (&x, &y);
   1.449 +    x -= w / 2;
   1.450 +    y -= h / 2;
   1.451  
   1.452 -	/* Show the image on the screen */
   1.453 -	SDL_GL_Enter2DMode();
   1.454 -	glBindTexture(GL_TEXTURE_2D, cursor_texture);
   1.455 -	glBegin(GL_TRIANGLE_STRIP);
   1.456 -	glTexCoord2f(texMinX, texMinY); glVertex2i(x,   y  );
   1.457 -	glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y  );
   1.458 -	glTexCoord2f(texMinX, texMaxY); glVertex2i(x,   y+h);
   1.459 -	glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
   1.460 -	glEnd();
   1.461 -	SDL_GL_Leave2DMode();
   1.462 +    /* Show the image on the screen */
   1.463 +    SDL_GL_Enter2DMode ();
   1.464 +    glBindTexture (GL_TEXTURE_2D, cursor_texture);
   1.465 +    glBegin (GL_TRIANGLE_STRIP);
   1.466 +    glTexCoord2f (texMinX, texMinY);
   1.467 +    glVertex2i (x, y);
   1.468 +    glTexCoord2f (texMaxX, texMinY);
   1.469 +    glVertex2i (x + w, y);
   1.470 +    glTexCoord2f (texMinX, texMaxY);
   1.471 +    glVertex2i (x, y + h);
   1.472 +    glTexCoord2f (texMaxX, texMaxY);
   1.473 +    glVertex2i (x + w, y + h);
   1.474 +    glEnd ();
   1.475 +    SDL_GL_Leave2DMode ();
   1.476  }
   1.477  
   1.478 -void DrawLogoTexture(void)
   1.479 +void
   1.480 +DrawLogoTexture (void)
   1.481  {
   1.482 -	static GLfloat texMinX, texMinY;
   1.483 -	static GLfloat texMaxX, texMaxY;
   1.484 -	static int x = 0;
   1.485 -	static int y = 0;
   1.486 -	static int w, h;
   1.487 -	static int delta_x = 1;
   1.488 -	static int delta_y = 1;
   1.489 +    static GLfloat texMinX, texMinY;
   1.490 +    static GLfloat texMaxX, texMaxY;
   1.491 +    static int x = 0;
   1.492 +    static int y = 0;
   1.493 +    static int w, h;
   1.494 +    static int delta_x = 1;
   1.495 +    static int delta_y = 1;
   1.496  
   1.497 -	SDL_Surface *screen = SDL_GetVideoSurface();
   1.498 +    SDL_Surface *screen = SDL_GetVideoSurface ();
   1.499  
   1.500 -	if ( ! global_texture ) {
   1.501 -		SDL_Surface *image;
   1.502 -		GLfloat texcoord[4];
   1.503 +    if (!global_texture) {
   1.504 +        SDL_Surface *image;
   1.505 +        GLfloat texcoord[4];
   1.506  
   1.507 -		/* Load the image (could use SDL_image library here) */
   1.508 -		image = SDL_LoadBMP(LOGO_FILE);
   1.509 -		if ( image == NULL ) {
   1.510 -			return;
   1.511 -		}
   1.512 -		w = image->w;
   1.513 -		h = image->h;
   1.514 +        /* Load the image (could use SDL_image library here) */
   1.515 +        image = SDL_LoadBMP (LOGO_FILE);
   1.516 +        if (image == NULL) {
   1.517 +            return;
   1.518 +        }
   1.519 +        w = image->w;
   1.520 +        h = image->h;
   1.521  
   1.522 -		/* Convert the image into an OpenGL texture */
   1.523 -		global_texture = SDL_GL_LoadTexture(image, texcoord);
   1.524 +        /* Convert the image into an OpenGL texture */
   1.525 +        global_texture = SDL_GL_LoadTexture (image, texcoord);
   1.526  
   1.527 -		/* Make texture coordinates easy to understand */
   1.528 -		texMinX = texcoord[0];
   1.529 -		texMinY = texcoord[1];
   1.530 -		texMaxX = texcoord[2];
   1.531 -		texMaxY = texcoord[3];
   1.532 +        /* Make texture coordinates easy to understand */
   1.533 +        texMinX = texcoord[0];
   1.534 +        texMinY = texcoord[1];
   1.535 +        texMaxX = texcoord[2];
   1.536 +        texMaxY = texcoord[3];
   1.537  
   1.538 -		/* We don't need the original image anymore */
   1.539 -		SDL_FreeSurface(image);
   1.540 +        /* We don't need the original image anymore */
   1.541 +        SDL_FreeSurface (image);
   1.542  
   1.543 -		/* Make sure that the texture conversion is okay */
   1.544 -		if ( ! global_texture ) {
   1.545 -			return;
   1.546 -		}
   1.547 -	}
   1.548 +        /* Make sure that the texture conversion is okay */
   1.549 +        if (!global_texture) {
   1.550 +            return;
   1.551 +        }
   1.552 +    }
   1.553  
   1.554 -	/* Move the image around */
   1.555 -	x += delta_x;
   1.556 -	if ( x < 0 ) {
   1.557 -		x = 0;
   1.558 -		delta_x = -delta_x;
   1.559 -	} else
   1.560 -	if ( (x+w) > screen->w ) {
   1.561 -		x = screen->w-w;
   1.562 -		delta_x = -delta_x;
   1.563 -	}
   1.564 -	y += delta_y;
   1.565 -	if ( y < 0 ) {
   1.566 -		y = 0;
   1.567 -		delta_y = -delta_y;
   1.568 -	} else
   1.569 -	if ( (y+h) > screen->h ) {
   1.570 -		y = screen->h-h;
   1.571 -		delta_y = -delta_y;
   1.572 -	}
   1.573 +    /* Move the image around */
   1.574 +    x += delta_x;
   1.575 +    if (x < 0) {
   1.576 +        x = 0;
   1.577 +        delta_x = -delta_x;
   1.578 +    } else if ((x + w) > screen->w) {
   1.579 +        x = screen->w - w;
   1.580 +        delta_x = -delta_x;
   1.581 +    }
   1.582 +    y += delta_y;
   1.583 +    if (y < 0) {
   1.584 +        y = 0;
   1.585 +        delta_y = -delta_y;
   1.586 +    } else if ((y + h) > screen->h) {
   1.587 +        y = screen->h - h;
   1.588 +        delta_y = -delta_y;
   1.589 +    }
   1.590  
   1.591 -	/* Show the image on the screen */
   1.592 -	SDL_GL_Enter2DMode();
   1.593 -	glBindTexture(GL_TEXTURE_2D, global_texture);
   1.594 -	glBegin(GL_TRIANGLE_STRIP);
   1.595 -	glTexCoord2f(texMinX, texMinY); glVertex2i(x,   y  );
   1.596 -	glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y  );
   1.597 -	glTexCoord2f(texMinX, texMaxY); glVertex2i(x,   y+h);
   1.598 -	glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
   1.599 -	glEnd();
   1.600 -	SDL_GL_Leave2DMode();
   1.601 +    /* Show the image on the screen */
   1.602 +    SDL_GL_Enter2DMode ();
   1.603 +    glBindTexture (GL_TEXTURE_2D, global_texture);
   1.604 +    glBegin (GL_TRIANGLE_STRIP);
   1.605 +    glTexCoord2f (texMinX, texMinY);
   1.606 +    glVertex2i (x, y);
   1.607 +    glTexCoord2f (texMaxX, texMinY);
   1.608 +    glVertex2i (x + w, y);
   1.609 +    glTexCoord2f (texMinX, texMaxY);
   1.610 +    glVertex2i (x, y + h);
   1.611 +    glTexCoord2f (texMaxX, texMaxY);
   1.612 +    glVertex2i (x + w, y + h);
   1.613 +    glEnd ();
   1.614 +    SDL_GL_Leave2DMode ();
   1.615  }
   1.616  
   1.617 -int RunGLTest( int argc, char* argv[],
   1.618 -               int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa, int sync, int accel )
   1.619 +int
   1.620 +RunGLTest (int argc, char *argv[],
   1.621 +           int logo, int logocursor, int slowly, int bpp, float gamma,
   1.622 +           int noframe, int fsaa, int sync, int accel)
   1.623  {
   1.624 -	int i;
   1.625 -	int rgb_size[3];
   1.626 -	int w = 640;
   1.627 -	int h = 480;
   1.628 -	int done = 0;
   1.629 -	int frames;
   1.630 -	Uint32 start_time, this_time;
   1.631 -        float color[8][3]= {{ 1.0,  1.0,  0.0}, 
   1.632 -			    { 1.0,  0.0,  0.0},
   1.633 -			    { 0.0,  0.0,  0.0},
   1.634 -			    { 0.0,  1.0,  0.0},
   1.635 -			    { 0.0,  1.0,  1.0},
   1.636 -			    { 1.0,  1.0,  1.0},
   1.637 -			    { 1.0,  0.0,  1.0},
   1.638 -			    { 0.0,  0.0,  1.0}};
   1.639 -	float cube[8][3]= {{ 0.5,  0.5, -0.5}, 
   1.640 -			   { 0.5, -0.5, -0.5},
   1.641 -			   {-0.5, -0.5, -0.5},
   1.642 -			   {-0.5,  0.5, -0.5},
   1.643 -			   {-0.5,  0.5,  0.5},
   1.644 -			   { 0.5,  0.5,  0.5},
   1.645 -			   { 0.5, -0.5,  0.5},
   1.646 -			   {-0.5, -0.5,  0.5}};
   1.647 -	Uint32 video_flags;
   1.648 -	int value;
   1.649 +    int i;
   1.650 +    int rgb_size[3];
   1.651 +    int w = 640;
   1.652 +    int h = 480;
   1.653 +    int done = 0;
   1.654 +    int frames;
   1.655 +    Uint32 start_time, this_time;
   1.656 +    float color[8][3] = { {1.0, 1.0, 0.0},
   1.657 +    {1.0, 0.0, 0.0},
   1.658 +    {0.0, 0.0, 0.0},
   1.659 +    {0.0, 1.0, 0.0},
   1.660 +    {0.0, 1.0, 1.0},
   1.661 +    {1.0, 1.0, 1.0},
   1.662 +    {1.0, 0.0, 1.0},
   1.663 +    {0.0, 0.0, 1.0}
   1.664 +    };
   1.665 +    float cube[8][3] = { {0.5, 0.5, -0.5},
   1.666 +    {0.5, -0.5, -0.5},
   1.667 +    {-0.5, -0.5, -0.5},
   1.668 +    {-0.5, 0.5, -0.5},
   1.669 +    {-0.5, 0.5, 0.5},
   1.670 +    {0.5, 0.5, 0.5},
   1.671 +    {0.5, -0.5, 0.5},
   1.672 +    {-0.5, -0.5, 0.5}
   1.673 +    };
   1.674 +    Uint32 video_flags;
   1.675 +    int value;
   1.676  
   1.677 -	if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
   1.678 -		fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
   1.679 -		exit( 1 );
   1.680 -	}
   1.681 +    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
   1.682 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.683 +        exit (1);
   1.684 +    }
   1.685  
   1.686 -	/* See if we should detect the display depth */
   1.687 -	if ( bpp == 0 ) {
   1.688 -		if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
   1.689 -			bpp = 8;
   1.690 -		} else {
   1.691 -			bpp = 16;  /* More doesn't seem to work */
   1.692 -		}
   1.693 -	}
   1.694 +    /* See if we should detect the display depth */
   1.695 +    if (bpp == 0) {
   1.696 +        if (SDL_GetVideoInfo ()->vfmt->BitsPerPixel <= 8) {
   1.697 +            bpp = 8;
   1.698 +        } else {
   1.699 +            bpp = 16;           /* More doesn't seem to work */
   1.700 +        }
   1.701 +    }
   1.702  
   1.703 -	/* Set the flags we want to use for setting the video mode */
   1.704 -	video_flags = SDL_OPENGL;
   1.705 -	for ( i=1; argv[i]; ++i ) {
   1.706 -		if ( strcmp(argv[i], "-fullscreen") == 0 ) {
   1.707 -			video_flags |= SDL_FULLSCREEN;
   1.708 -		}
   1.709 -	}
   1.710 +    /* Set the flags we want to use for setting the video mode */
   1.711 +    video_flags = SDL_OPENGL;
   1.712 +    for (i = 1; argv[i]; ++i) {
   1.713 +        if (strcmp (argv[i], "-fullscreen") == 0) {
   1.714 +            video_flags |= SDL_FULLSCREEN;
   1.715 +        }
   1.716 +    }
   1.717  
   1.718 -        if (noframe) {
   1.719 -           video_flags |= SDL_NOFRAME;
   1.720 +    if (noframe) {
   1.721 +        video_flags |= SDL_NOFRAME;
   1.722 +    }
   1.723 +
   1.724 +    /* Initialize the display */
   1.725 +    switch (bpp) {
   1.726 +    case 8:
   1.727 +        rgb_size[0] = 3;
   1.728 +        rgb_size[1] = 3;
   1.729 +        rgb_size[2] = 2;
   1.730 +        break;
   1.731 +    case 15:
   1.732 +    case 16:
   1.733 +        rgb_size[0] = 5;
   1.734 +        rgb_size[1] = 5;
   1.735 +        rgb_size[2] = 5;
   1.736 +        break;
   1.737 +    default:
   1.738 +        rgb_size[0] = 8;
   1.739 +        rgb_size[1] = 8;
   1.740 +        rgb_size[2] = 8;
   1.741 +        break;
   1.742 +    }
   1.743 +    SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]);
   1.744 +    SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]);
   1.745 +    SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]);
   1.746 +    SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
   1.747 +    SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
   1.748 +    if (fsaa) {
   1.749 +        SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
   1.750 +        SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, fsaa);
   1.751 +    }
   1.752 +    if (accel) {
   1.753 +        SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
   1.754 +    }
   1.755 +    if (sync) {
   1.756 +        SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
   1.757 +    } else {
   1.758 +        SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 0);
   1.759 +    }
   1.760 +    if (SDL_SetVideoMode (w, h, bpp, video_flags) == NULL) {
   1.761 +        fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ());
   1.762 +        SDL_Quit ();
   1.763 +        exit (1);
   1.764 +    }
   1.765 +
   1.766 +    printf ("Screen BPP: %d\n", SDL_GetVideoSurface ()->format->BitsPerPixel);
   1.767 +    printf ("\n");
   1.768 +    printf ("Vendor     : %s\n", glGetString (GL_VENDOR));
   1.769 +    printf ("Renderer   : %s\n", glGetString (GL_RENDERER));
   1.770 +    printf ("Version    : %s\n", glGetString (GL_VERSION));
   1.771 +    printf ("Extensions : %s\n", glGetString (GL_EXTENSIONS));
   1.772 +    printf ("\n");
   1.773 +
   1.774 +    SDL_GL_GetAttribute (SDL_GL_RED_SIZE, &value);
   1.775 +    printf ("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value);
   1.776 +    SDL_GL_GetAttribute (SDL_GL_GREEN_SIZE, &value);
   1.777 +    printf ("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value);
   1.778 +    SDL_GL_GetAttribute (SDL_GL_BLUE_SIZE, &value);
   1.779 +    printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value);
   1.780 +    SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value);
   1.781 +    printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value);
   1.782 +    SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value);
   1.783 +    printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
   1.784 +    if (fsaa) {
   1.785 +        SDL_GL_GetAttribute (SDL_GL_MULTISAMPLEBUFFERS, &value);
   1.786 +        printf ("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   1.787 +        SDL_GL_GetAttribute (SDL_GL_MULTISAMPLESAMPLES, &value);
   1.788 +        printf ("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   1.789 +                value);
   1.790 +    }
   1.791 +    if (accel) {
   1.792 +        SDL_GL_GetAttribute (SDL_GL_ACCELERATED_VISUAL, &value);
   1.793 +        printf ("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   1.794 +    }
   1.795 +    if (sync) {
   1.796 +        SDL_GL_GetAttribute (SDL_GL_SWAP_CONTROL, &value);
   1.797 +        printf ("SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value);
   1.798 +    }
   1.799 +
   1.800 +    /* Set the window manager title bar */
   1.801 +    SDL_WM_SetCaption ("SDL GL test", "testgl");
   1.802 +
   1.803 +    /* Set the gamma for the window */
   1.804 +    if (gamma != 0.0) {
   1.805 +        SDL_SetGamma (gamma, gamma, gamma);
   1.806 +    }
   1.807 +
   1.808 +    glViewport (0, 0, w, h);
   1.809 +    glMatrixMode (GL_PROJECTION);
   1.810 +    glLoadIdentity ();
   1.811 +
   1.812 +    glOrtho (-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
   1.813 +
   1.814 +    glMatrixMode (GL_MODELVIEW);
   1.815 +    glLoadIdentity ();
   1.816 +
   1.817 +    glEnable (GL_DEPTH_TEST);
   1.818 +
   1.819 +    glDepthFunc (GL_LESS);
   1.820 +
   1.821 +    glShadeModel (GL_SMOOTH);
   1.822 +
   1.823 +    /* Loop until done. */
   1.824 +    start_time = SDL_GetTicks ();
   1.825 +    frames = 0;
   1.826 +    while (!done) {
   1.827 +        GLenum gl_error;
   1.828 +        char *sdl_error;
   1.829 +        SDL_Event event;
   1.830 +
   1.831 +        /* Do our drawing, too. */
   1.832 +        glClearColor (0.0, 0.0, 0.0, 1.0);
   1.833 +        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   1.834 +
   1.835 +        glBegin (GL_QUADS);
   1.836 +
   1.837 +#ifdef SHADED_CUBE
   1.838 +        glColor3fv (color[0]);
   1.839 +        glVertex3fv (cube[0]);
   1.840 +        glColor3fv (color[1]);
   1.841 +        glVertex3fv (cube[1]);
   1.842 +        glColor3fv (color[2]);
   1.843 +        glVertex3fv (cube[2]);
   1.844 +        glColor3fv (color[3]);
   1.845 +        glVertex3fv (cube[3]);
   1.846 +
   1.847 +        glColor3fv (color[3]);
   1.848 +        glVertex3fv (cube[3]);
   1.849 +        glColor3fv (color[4]);
   1.850 +        glVertex3fv (cube[4]);
   1.851 +        glColor3fv (color[7]);
   1.852 +        glVertex3fv (cube[7]);
   1.853 +        glColor3fv (color[2]);
   1.854 +        glVertex3fv (cube[2]);
   1.855 +
   1.856 +        glColor3fv (color[0]);
   1.857 +        glVertex3fv (cube[0]);
   1.858 +        glColor3fv (color[5]);
   1.859 +        glVertex3fv (cube[5]);
   1.860 +        glColor3fv (color[6]);
   1.861 +        glVertex3fv (cube[6]);
   1.862 +        glColor3fv (color[1]);
   1.863 +        glVertex3fv (cube[1]);
   1.864 +
   1.865 +        glColor3fv (color[5]);
   1.866 +        glVertex3fv (cube[5]);
   1.867 +        glColor3fv (color[4]);
   1.868 +        glVertex3fv (cube[4]);
   1.869 +        glColor3fv (color[7]);
   1.870 +        glVertex3fv (cube[7]);
   1.871 +        glColor3fv (color[6]);
   1.872 +        glVertex3fv (cube[6]);
   1.873 +
   1.874 +        glColor3fv (color[5]);
   1.875 +        glVertex3fv (cube[5]);
   1.876 +        glColor3fv (color[0]);
   1.877 +        glVertex3fv (cube[0]);
   1.878 +        glColor3fv (color[3]);
   1.879 +        glVertex3fv (cube[3]);
   1.880 +        glColor3fv (color[4]);
   1.881 +        glVertex3fv (cube[4]);
   1.882 +
   1.883 +        glColor3fv (color[6]);
   1.884 +        glVertex3fv (cube[6]);
   1.885 +        glColor3fv (color[1]);
   1.886 +        glVertex3fv (cube[1]);
   1.887 +        glColor3fv (color[2]);
   1.888 +        glVertex3fv (cube[2]);
   1.889 +        glColor3fv (color[7]);
   1.890 +        glVertex3fv (cube[7]);
   1.891 +#else /* flat cube */
   1.892 +        glColor3f (1.0, 0.0, 0.0);
   1.893 +        glVertex3fv (cube[0]);
   1.894 +        glVertex3fv (cube[1]);
   1.895 +        glVertex3fv (cube[2]);
   1.896 +        glVertex3fv (cube[3]);
   1.897 +
   1.898 +        glColor3f (0.0, 1.0, 0.0);
   1.899 +        glVertex3fv (cube[3]);
   1.900 +        glVertex3fv (cube[4]);
   1.901 +        glVertex3fv (cube[7]);
   1.902 +        glVertex3fv (cube[2]);
   1.903 +
   1.904 +        glColor3f (0.0, 0.0, 1.0);
   1.905 +        glVertex3fv (cube[0]);
   1.906 +        glVertex3fv (cube[5]);
   1.907 +        glVertex3fv (cube[6]);
   1.908 +        glVertex3fv (cube[1]);
   1.909 +
   1.910 +        glColor3f (0.0, 1.0, 1.0);
   1.911 +        glVertex3fv (cube[5]);
   1.912 +        glVertex3fv (cube[4]);
   1.913 +        glVertex3fv (cube[7]);
   1.914 +        glVertex3fv (cube[6]);
   1.915 +
   1.916 +        glColor3f (1.0, 1.0, 0.0);
   1.917 +        glVertex3fv (cube[5]);
   1.918 +        glVertex3fv (cube[0]);
   1.919 +        glVertex3fv (cube[3]);
   1.920 +        glVertex3fv (cube[4]);
   1.921 +
   1.922 +        glColor3f (1.0, 0.0, 1.0);
   1.923 +        glVertex3fv (cube[6]);
   1.924 +        glVertex3fv (cube[1]);
   1.925 +        glVertex3fv (cube[2]);
   1.926 +        glVertex3fv (cube[7]);
   1.927 +#endif /* SHADED_CUBE */
   1.928 +
   1.929 +        glEnd ();
   1.930 +
   1.931 +        glMatrixMode (GL_MODELVIEW);
   1.932 +        glRotatef (5.0, 1.0, 1.0, 1.0);
   1.933 +
   1.934 +        /* Draw 2D logo onto the 3D display */
   1.935 +        if (logo) {
   1.936 +            DrawLogoTexture ();
   1.937 +        }
   1.938 +        if (logocursor) {
   1.939 +            DrawLogoCursor ();
   1.940          }
   1.941  
   1.942 -	/* Initialize the display */
   1.943 -	switch (bpp) {
   1.944 -	    case 8:
   1.945 -		rgb_size[0] = 3;
   1.946 -		rgb_size[1] = 3;
   1.947 -		rgb_size[2] = 2;
   1.948 -		break;
   1.949 -	    case 15:
   1.950 -	    case 16:
   1.951 -		rgb_size[0] = 5;
   1.952 -		rgb_size[1] = 5;
   1.953 -		rgb_size[2] = 5;
   1.954 -		break;
   1.955 -            default:
   1.956 -		rgb_size[0] = 8;
   1.957 -		rgb_size[1] = 8;
   1.958 -		rgb_size[2] = 8;
   1.959 -		break;
   1.960 -	}
   1.961 -	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
   1.962 -	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
   1.963 -	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
   1.964 -	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
   1.965 -	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
   1.966 -	if ( fsaa ) {
   1.967 -		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
   1.968 -		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, fsaa );
   1.969 -	}
   1.970 -	if ( accel ) {
   1.971 -		SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
   1.972 -	}
   1.973 -	if ( sync ) {
   1.974 -		SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );
   1.975 -	} else {
   1.976 -		SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 );
   1.977 -	}
   1.978 -	if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
   1.979 -		fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
   1.980 -		SDL_Quit();
   1.981 -		exit(1);
   1.982 -	}
   1.983 +        SDL_GL_SwapBuffers ();
   1.984  
   1.985 -	printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
   1.986 -	printf("\n");
   1.987 -	printf( "Vendor     : %s\n", glGetString( GL_VENDOR ) );
   1.988 -	printf( "Renderer   : %s\n", glGetString( GL_RENDERER ) );
   1.989 -	printf( "Version    : %s\n", glGetString( GL_VERSION ) );
   1.990 -	printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
   1.991 -	printf("\n");
   1.992 +        /* Check for error conditions. */
   1.993 +        gl_error = glGetError ();
   1.994  
   1.995 -	SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
   1.996 -	printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
   1.997 -	SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
   1.998 -	printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
   1.999 -	SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
  1.1000 -	printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
  1.1001 -	SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
  1.1002 -	printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
  1.1003 -	SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
  1.1004 -	printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
  1.1005 -	if ( fsaa ) {
  1.1006 -		SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value );
  1.1007 -		printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value );
  1.1008 -		SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value );
  1.1009 -		printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value );
  1.1010 -	}
  1.1011 -	if ( accel ) {
  1.1012 -		SDL_GL_GetAttribute( SDL_GL_ACCELERATED_VISUAL, &value );
  1.1013 -		printf( "SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value );
  1.1014 -	}
  1.1015 -	if ( sync ) {
  1.1016 -		SDL_GL_GetAttribute( SDL_GL_SWAP_CONTROL, &value );
  1.1017 -		printf( "SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value );
  1.1018 -	}
  1.1019 +        if (gl_error != GL_NO_ERROR) {
  1.1020 +            fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error);
  1.1021 +        }
  1.1022  
  1.1023 -	/* Set the window manager title bar */
  1.1024 -	SDL_WM_SetCaption( "SDL GL test", "testgl" );
  1.1025 +        sdl_error = SDL_GetError ();
  1.1026  
  1.1027 -	/* Set the gamma for the window */
  1.1028 -	if ( gamma != 0.0 ) {
  1.1029 -		SDL_SetGamma(gamma, gamma, gamma);
  1.1030 -	}
  1.1031 +        if (sdl_error[0] != '\0') {
  1.1032 +            fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error);
  1.1033 +            SDL_ClearError ();
  1.1034 +        }
  1.1035  
  1.1036 -	glViewport( 0, 0, w, h );
  1.1037 -	glMatrixMode( GL_PROJECTION );
  1.1038 -	glLoadIdentity( );
  1.1039 +        /* Allow the user to see what's happening */
  1.1040 +        if (slowly) {
  1.1041 +            SDL_Delay (20);
  1.1042 +        }
  1.1043  
  1.1044 -	glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
  1.1045 +        /* Check if there's a pending event. */
  1.1046 +        while (SDL_PollEvent (&event)) {
  1.1047 +            done = HandleEvent (&event);
  1.1048 +        }
  1.1049 +        ++frames;
  1.1050 +    }
  1.1051  
  1.1052 -	glMatrixMode( GL_MODELVIEW );
  1.1053 -	glLoadIdentity( );
  1.1054 +    /* Print out the frames per second */
  1.1055 +    this_time = SDL_GetTicks ();
  1.1056 +    if (this_time != start_time) {
  1.1057 +        printf ("%2.2f FPS\n",
  1.1058 +                ((float) frames / (this_time - start_time)) * 1000.0);
  1.1059 +    }
  1.1060  
  1.1061 -	glEnable(GL_DEPTH_TEST);
  1.1062 +    if (global_image) {
  1.1063 +        SDL_FreeSurface (global_image);
  1.1064 +        global_image = NULL;
  1.1065 +    }
  1.1066 +    if (global_texture) {
  1.1067 +        glDeleteTextures (1, &global_texture);
  1.1068 +        global_texture = 0;
  1.1069 +    }
  1.1070 +    if (cursor_texture) {
  1.1071 +        glDeleteTextures (1, &cursor_texture);
  1.1072 +        cursor_texture = 0;
  1.1073 +    }
  1.1074  
  1.1075 -	glDepthFunc(GL_LESS);
  1.1076 -
  1.1077 -	glShadeModel(GL_SMOOTH);
  1.1078 -
  1.1079 -	/* Loop until done. */
  1.1080 -	start_time = SDL_GetTicks();
  1.1081 -	frames = 0;
  1.1082 -	while( !done ) {
  1.1083 -		GLenum gl_error;
  1.1084 -		char* sdl_error;
  1.1085 -		SDL_Event event;
  1.1086 -
  1.1087 -		/* Do our drawing, too. */
  1.1088 -		glClearColor( 0.0, 0.0, 0.0, 1.0 );
  1.1089 -		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1.1090 -
  1.1091 -		glBegin( GL_QUADS );
  1.1092 -
  1.1093 -#ifdef SHADED_CUBE
  1.1094 -			glColor3fv(color[0]);
  1.1095 -			glVertex3fv(cube[0]);
  1.1096 -			glColor3fv(color[1]);
  1.1097 -			glVertex3fv(cube[1]);
  1.1098 -			glColor3fv(color[2]);
  1.1099 -			glVertex3fv(cube[2]);
  1.1100 -			glColor3fv(color[3]);
  1.1101 -			glVertex3fv(cube[3]);
  1.1102 -			
  1.1103 -			glColor3fv(color[3]);
  1.1104 -			glVertex3fv(cube[3]);
  1.1105 -			glColor3fv(color[4]);
  1.1106 -			glVertex3fv(cube[4]);
  1.1107 -			glColor3fv(color[7]);
  1.1108 -			glVertex3fv(cube[7]);
  1.1109 -			glColor3fv(color[2]);
  1.1110 -			glVertex3fv(cube[2]);
  1.1111 -			
  1.1112 -			glColor3fv(color[0]);
  1.1113 -			glVertex3fv(cube[0]);
  1.1114 -			glColor3fv(color[5]);
  1.1115 -			glVertex3fv(cube[5]);
  1.1116 -			glColor3fv(color[6]);
  1.1117 -			glVertex3fv(cube[6]);
  1.1118 -			glColor3fv(color[1]);
  1.1119 -			glVertex3fv(cube[1]);
  1.1120 -			
  1.1121 -			glColor3fv(color[5]);
  1.1122 -			glVertex3fv(cube[5]);
  1.1123 -			glColor3fv(color[4]);
  1.1124 -			glVertex3fv(cube[4]);
  1.1125 -			glColor3fv(color[7]);
  1.1126 -			glVertex3fv(cube[7]);
  1.1127 -			glColor3fv(color[6]);
  1.1128 -			glVertex3fv(cube[6]);
  1.1129 -
  1.1130 -			glColor3fv(color[5]);
  1.1131 -			glVertex3fv(cube[5]);
  1.1132 -			glColor3fv(color[0]);
  1.1133 -			glVertex3fv(cube[0]);
  1.1134 -			glColor3fv(color[3]);
  1.1135 -			glVertex3fv(cube[3]);
  1.1136 -			glColor3fv(color[4]);
  1.1137 -			glVertex3fv(cube[4]);
  1.1138 -
  1.1139 -			glColor3fv(color[6]);
  1.1140 -			glVertex3fv(cube[6]);
  1.1141 -			glColor3fv(color[1]);
  1.1142 -			glVertex3fv(cube[1]);
  1.1143 -			glColor3fv(color[2]);
  1.1144 -			glVertex3fv(cube[2]);
  1.1145 -			glColor3fv(color[7]);
  1.1146 -			glVertex3fv(cube[7]);
  1.1147 -#else /* flat cube */
  1.1148 -			glColor3f(1.0, 0.0, 0.0);
  1.1149 -			glVertex3fv(cube[0]);
  1.1150 -			glVertex3fv(cube[1]);
  1.1151 -			glVertex3fv(cube[2]);
  1.1152 -			glVertex3fv(cube[3]);
  1.1153 -			
  1.1154 -			glColor3f(0.0, 1.0, 0.0);
  1.1155 -			glVertex3fv(cube[3]);
  1.1156 -			glVertex3fv(cube[4]);
  1.1157 -			glVertex3fv(cube[7]);
  1.1158 -			glVertex3fv(cube[2]);
  1.1159 -			
  1.1160 -			glColor3f(0.0, 0.0, 1.0);
  1.1161 -			glVertex3fv(cube[0]);
  1.1162 -			glVertex3fv(cube[5]);
  1.1163 -			glVertex3fv(cube[6]);
  1.1164 -			glVertex3fv(cube[1]);
  1.1165 -			
  1.1166 -			glColor3f(0.0, 1.0, 1.0);
  1.1167 -			glVertex3fv(cube[5]);
  1.1168 -			glVertex3fv(cube[4]);
  1.1169 -			glVertex3fv(cube[7]);
  1.1170 -			glVertex3fv(cube[6]);
  1.1171 -
  1.1172 -			glColor3f(1.0, 1.0, 0.0);
  1.1173 -			glVertex3fv(cube[5]);
  1.1174 -			glVertex3fv(cube[0]);
  1.1175 -			glVertex3fv(cube[3]);
  1.1176 -			glVertex3fv(cube[4]);
  1.1177 -
  1.1178 -			glColor3f(1.0, 0.0, 1.0);
  1.1179 -			glVertex3fv(cube[6]);
  1.1180 -			glVertex3fv(cube[1]);
  1.1181 -			glVertex3fv(cube[2]);
  1.1182 -			glVertex3fv(cube[7]);
  1.1183 -#endif /* SHADED_CUBE */
  1.1184 -
  1.1185 -		glEnd( );
  1.1186 -		
  1.1187 -		glMatrixMode(GL_MODELVIEW);
  1.1188 -		glRotatef(5.0, 1.0, 1.0, 1.0);
  1.1189 -
  1.1190 -		/* Draw 2D logo onto the 3D display */
  1.1191 -		if ( logo ) {
  1.1192 -			DrawLogoTexture();
  1.1193 -		}
  1.1194 -		if ( logocursor ) {
  1.1195 -			DrawLogoCursor();
  1.1196 -		}
  1.1197 -
  1.1198 -		SDL_GL_SwapBuffers( );
  1.1199 -
  1.1200 -		/* Check for error conditions. */
  1.1201 -		gl_error = glGetError( );
  1.1202 -
  1.1203 -		if( gl_error != GL_NO_ERROR ) {
  1.1204 -			fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
  1.1205 -		}
  1.1206 -
  1.1207 -		sdl_error = SDL_GetError( );
  1.1208 -
  1.1209 -		if( sdl_error[0] != '\0' ) {
  1.1210 -			fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
  1.1211 -			SDL_ClearError();
  1.1212 -		}
  1.1213 -
  1.1214 -		/* Allow the user to see what's happening */
  1.1215 -		if ( slowly ) {
  1.1216 -			SDL_Delay( 20 );
  1.1217 -		}
  1.1218 -
  1.1219 -		/* Check if there's a pending event. */
  1.1220 -		while( SDL_PollEvent( &event ) ) {
  1.1221 -			done = HandleEvent(&event);
  1.1222 -		}
  1.1223 -		++frames;
  1.1224 -	}
  1.1225 -
  1.1226 -	/* Print out the frames per second */
  1.1227 -	this_time = SDL_GetTicks();
  1.1228 -	if ( this_time != start_time ) {
  1.1229 -		printf("%2.2f FPS\n",
  1.1230 -			((float)frames/(this_time-start_time))*1000.0);
  1.1231 -	}
  1.1232 -
  1.1233 -	if ( global_image ) {
  1.1234 -	   	SDL_FreeSurface(global_image);
  1.1235 -		global_image = NULL;
  1.1236 -	}
  1.1237 -	if ( global_texture ) {
  1.1238 -		glDeleteTextures( 1, &global_texture );
  1.1239 -		global_texture = 0;
  1.1240 -	}
  1.1241 -	if ( cursor_texture ) {
  1.1242 -		glDeleteTextures( 1, &cursor_texture );
  1.1243 -		cursor_texture = 0;
  1.1244 -	}
  1.1245 -
  1.1246 -	/* Destroy our GL context, etc. */
  1.1247 -	SDL_Quit( );
  1.1248 -	return(0);
  1.1249 +    /* Destroy our GL context, etc. */
  1.1250 +    SDL_Quit ();
  1.1251 +    return (0);
  1.1252  }
  1.1253  
  1.1254 -int main(int argc, char *argv[])
  1.1255 +int
  1.1256 +main (int argc, char *argv[])
  1.1257  {
  1.1258 -	int i, logo, logocursor = 0;
  1.1259 -	int numtests;
  1.1260 -	int bpp = 0;
  1.1261 -	int slowly;
  1.1262 -	float gamma = 0.0;
  1.1263 -	int noframe = 0;
  1.1264 -	int fsaa = 0;
  1.1265 -	int accel = 0;
  1.1266 -	int sync = 0;
  1.1267 +    int i, logo, logocursor = 0;
  1.1268 +    int numtests;
  1.1269 +    int bpp = 0;
  1.1270 +    int slowly;
  1.1271 +    float gamma = 0.0;
  1.1272 +    int noframe = 0;
  1.1273 +    int fsaa = 0;
  1.1274 +    int accel = 0;
  1.1275 +    int sync = 0;
  1.1276  
  1.1277 -	logo = 0;
  1.1278 -	slowly = 0;
  1.1279 -	numtests = 1;
  1.1280 -	for ( i=1; argv[i]; ++i ) {
  1.1281 -		if ( strcmp(argv[i], "-twice") == 0 ) {
  1.1282 -			++numtests;
  1.1283 -		}
  1.1284 -		if ( strcmp(argv[i], "-logo") == 0 ) {
  1.1285 -			logo = 1;
  1.1286 -		}
  1.1287 -		if ( strcmp(argv[i], "-logocursor") == 0 ) {
  1.1288 -			logocursor = 1;
  1.1289 -		}
  1.1290 -		if ( strcmp(argv[i], "-slow") == 0 ) {
  1.1291 -			slowly = 1;
  1.1292 -		}
  1.1293 -		if ( strcmp(argv[i], "-bpp") == 0 ) {
  1.1294 - 		       bpp = atoi(argv[++i]);
  1.1295 -		}
  1.1296 -		if ( strcmp(argv[i], "-gamma") == 0 ) {
  1.1297 - 		       gamma = (float)atof(argv[++i]);
  1.1298 -		}
  1.1299 -		if ( strcmp(argv[i], "-noframe") == 0 ) {
  1.1300 - 		       noframe = 1;
  1.1301 -		}
  1.1302 -		if ( strcmp(argv[i], "-fsaa") == 0 ) {
  1.1303 - 		       ++fsaa;
  1.1304 -		}
  1.1305 -		if ( strcmp(argv[i], "-accel") == 0 ) {
  1.1306 - 		       ++accel;
  1.1307 -		}
  1.1308 -		if ( strcmp(argv[i], "-sync") == 0 ) {
  1.1309 - 		       ++sync;
  1.1310 -		}
  1.1311 -		if ( strncmp(argv[i], "-h", 2) == 0 ) {
  1.1312 - 		       printf(
  1.1313 -"Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n",
  1.1314 - 			      argv[0]);
  1.1315 -			exit(0);
  1.1316 -		}
  1.1317 -	}
  1.1318 -	for ( i=0; i<numtests; ++i ) {
  1.1319 - 		RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa, sync, accel);
  1.1320 -	}
  1.1321 -	return 0;
  1.1322 +    logo = 0;
  1.1323 +    slowly = 0;
  1.1324 +    numtests = 1;
  1.1325 +    for (i = 1; argv[i]; ++i) {
  1.1326 +        if (strcmp (argv[i], "-twice") == 0) {
  1.1327 +            ++numtests;
  1.1328 +        }
  1.1329 +        if (strcmp (argv[i], "-logo") == 0) {
  1.1330 +            logo = 1;
  1.1331 +        }
  1.1332 +        if (strcmp (argv[i], "-logocursor") == 0) {
  1.1333 +            logocursor = 1;
  1.1334 +        }
  1.1335 +        if (strcmp (argv[i], "-slow") == 0) {
  1.1336 +            slowly = 1;
  1.1337 +        }
  1.1338 +        if (strcmp (argv[i], "-bpp") == 0) {
  1.1339 +            bpp = atoi (argv[++i]);
  1.1340 +        }
  1.1341 +        if (strcmp (argv[i], "-gamma") == 0) {
  1.1342 +            gamma = (float) atof (argv[++i]);
  1.1343 +        }
  1.1344 +        if (strcmp (argv[i], "-noframe") == 0) {
  1.1345 +            noframe = 1;
  1.1346 +        }
  1.1347 +        if (strcmp (argv[i], "-fsaa") == 0) {
  1.1348 +            ++fsaa;
  1.1349 +        }
  1.1350 +        if (strcmp (argv[i], "-accel") == 0) {
  1.1351 +            ++accel;
  1.1352 +        }
  1.1353 +        if (strcmp (argv[i], "-sync") == 0) {
  1.1354 +            ++sync;
  1.1355 +        }
  1.1356 +        if (strncmp (argv[i], "-h", 2) == 0) {
  1.1357 +            printf
  1.1358 +                ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-fullscreen]\n",
  1.1359 +                 argv[0]);
  1.1360 +            exit (0);
  1.1361 +        }
  1.1362 +    }
  1.1363 +    for (i = 0; i < numtests; ++i) {
  1.1364 +        RunGLTest (argc, argv, logo, logocursor, slowly, bpp, gamma,
  1.1365 +                   noframe, fsaa, sync, accel);
  1.1366 +    }
  1.1367 +    return 0;
  1.1368  }
  1.1369  
  1.1370  #else /* HAVE_OPENGL */
  1.1371  
  1.1372 -int main(int argc, char *argv[])
  1.1373 +int
  1.1374 +main (int argc, char *argv[])
  1.1375  {
  1.1376 -	printf("No OpenGL support on this system\n");
  1.1377 -	return 1;
  1.1378 +    printf ("No OpenGL support on this system\n");
  1.1379 +    return 1;
  1.1380  }
  1.1381  
  1.1382  #endif /* HAVE_OPENGL */