#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <string.h>#include <GL/glu.h>#include "config.h"#include "texture.h"Go to the source code of this file.
Typedefs | |
| typedef unsigned char | rgba [4] |
| typedef rgba | teximage [256 *256] |
Functions | |
| void | initTextures () |
| void | deleteTextures () |
| GLuint | texture (TEXTURE t) |
Variables | |
| const char * | g_texfiles [TEX_N] |
| GLuint | g_handles [TEX_N] |
| teximage | g_textures [TEX_N] |
|
|
Definition at line 23 of file texture.cpp. |
|
|
Definition at line 24 of file texture.cpp. |
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 21 of file texture.cpp. Referenced by deleteTextures(), initTextures(), and texture(). |
|
|
Initial value: {
"rock.raw_256x256_rgba_byte",
"snow.raw_256x256_rgba_byte",
"grass.raw_256x256_rgba_byte",
"sand.raw_256x256_rgba_byte"
}
Definition at line 13 of file texture.cpp. Referenced by initTextures(). |
|
|
Definition at line 25 of file texture.cpp. Referenced by initTextures(). |
1.3.6