Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

texture.h File Reference

#include <GL/gl.h>

Go to the source code of this file.

Enumerations

enum  TEXTURE {
  TEX_ROCK, TEX_SNOW, TEX_GRASS, TEX_SAND,
  TEX_N
}

Functions

void initTextures ()
void deleteTextures ()
GLuint texture (TEXTURE t)


Enumeration Type Documentation

enum TEXTURE
 

Enumeration values:
TEX_ROCK 
TEX_SNOW 
TEX_GRASS 
TEX_SAND 
TEX_N 

Definition at line 6 of file texture.h.

00006              {
00007   TEX_ROCK,
00008   TEX_SNOW,
00009   TEX_GRASS,
00010   TEX_SAND,
00011   TEX_N
00012 };


Function Documentation

void deleteTextures  ) 
 

Definition at line 72 of file texture.cpp.

References g_handles, and TEX_N.

00073 {
00074   // Release handles
00075   glDeleteTextures( TEX_N, g_handles );
00076 }

void initTextures  ) 
 

Definition at line 29 of file texture.cpp.

References g_handles, g_strResourceDir, g_texfiles, g_textures, and TEX_N.

Referenced by initGL().

00030 {
00031   // Generate handles
00032   glGenTextures( TEX_N, g_handles );
00033 
00034   // Load textures
00035   for (int i=0; i<TEX_N; i++) {
00036 
00037     // Generate filename
00038     char filename[200];
00039     strcpy( filename, g_strResourceDir );
00040     strcat( filename, g_texfiles[i] );
00041 
00042     // Open and read file (binary mode)
00043     FILE *f = fopen( filename, "rb" );
00044     if (f == NULL) {
00045       printf( "Error opening texture file %s\n.", g_texfiles[i] );
00046       exit(1);
00047     }
00048 
00049     int n = fread( g_textures[i], 4, 256*256, f );
00050     if (n != 256*256) {
00051       printf( "Error reading texture file %s: Only %i pixels read.\n",
00052               g_texfiles[i], n );
00053     }
00054     else {
00055       printf( "Successfully loaded texture %s.\n", g_texfiles[i] );
00056     }
00057 
00058     // Load texture image to OpenGL
00059     glBindTexture( GL_TEXTURE_2D, g_handles[i] );
00060     // Build all mipmap stages
00061     gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, g_textures[i] );
00062 
00063     // Set filtering modes
00064     // LINEAR_MIPMAP_LINEAR specifies the highest quality mode, sometimes called
00065     // "trilinear filtering". Anisotropic is even better, but not yet officially supported in OpenGL.
00066     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
00067     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00068   }
00069 }

GLuint texture TEXTURE  t  ) 
 

Definition at line 80 of file texture.cpp.

References g_handles, and TEX_N.

Referenced by drawHeightField(), and drawTorus().

00081 {
00082   assert( t>=0 && t<TEX_N );
00083   return g_handles[t];
00084 }


Generated on Thu Jan 20 02:47:13 2005 for Projective_Texture_Effect_Demo by doxygen 1.3.6