#include <CTexture.h>
Inherits CTexture.
Inheritance diagram for CTextureTGA:
Public Member Functions | |
CTextureTGA () | |
int | Load (char *name, int id, int textureMode, bool keepimagedata) |
Local implementation of CTexture:Load function to load TGA files only. | |
~CTextureTGA () |
Definition at line 105 of file CTexture.h.
|
Constructor. Definition at line 56 of file CTextureTGA.cpp. 00057 {
00058 m_ImageDataKept = false;
00059 }
|
|
Free image data if it was kept. If the imagedata was kept for some reason... Definition at line 67 of file CTextureTGA.cpp. 00068 {
00070 if(m_ImageDataKept)
00071 free(m_ImageData);
00072 }
|
|
Local implementation of CTexture:Load function to load TGA files only. Reads in TGA image data in 8, 24 or 32 bit uncompressed and binds it to a texture ID. TGA files are stored using Intel byte ordering... Implements CTexture. Definition at line 132 of file CTextureTGA.cpp. References TGA_HEADER::colourmap, TGA_HEADER::depth, TGA_HEADER::height, TGA_HEADER::imagetype, and TGA_HEADER::width. 00133 { 00134 TGA_HEADER header; 00135 FILE *file; 00136 int error = 0; 00137 00138 if(!(file = fopen(name, "r"))) 00139 { 00140 g_pGlobalLog->LogError("CTextureTGA::Load() Filename does not exist:"); 00141 } 00142 else 00143 { 00144 fread(&header, sizeof(TGA_HEADER), 1, file); 00145 00146 if(header.colourmap != 0 || (header.imagetype != 2 && header.imagetype != 3)) 00147 { 00148 g_pGlobalLog->LogError("CTextureTGA::Load() TGA is compressed: %s", name); 00149 } 00150 else 00151 { 00153 m_ImageWidth = header.width[0] + header.width[1] * 256; 00154 m_ImageHeight = header.height[0] + header.height[1] * 256; 00155 m_ImageDepth = header.depth; 00156 m_ImagePixelSize = header.depth / 8; 00157 00158 if(!IsPowerOf2(m_ImageWidth) || !IsPowerOf2(m_ImageHeight)) 00159 { 00160 g_pGlobalLog->LogError("CTextureTGA::Load() Bad height or width in %s", name); 00161 } 00162 else 00163 { 00164 if(m_ImageDepth != 32 && m_ImageDepth != 24 && m_ImageDepth != 8) 00165 { 00166 g_pGlobalLog->LogError("CTextureTGA::Load() Bad bitdepth of %d in %s", m_ImageDepth, name); 00167 } 00168 else 00169 { 00170 00171 m_ImageData = ReadData(file); 00172 00173 if(m_ImageData == NULL) 00174 { 00175 g_pGlobalLog->LogError("CTextureTGA::Load() Bad data in %s", name); 00176 } 00177 else 00178 { 00179 glBindTexture(GL_TEXTURE_2D, id); 00180 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00181 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 00182 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 00183 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texturemode); 00184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); 00185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 00186 gluBuild2DMipmaps(GL_TEXTURE_2D, texturemode, m_ImageWidth, m_ImageHeight, texturemode, GL_UNSIGNED_BYTE, m_ImageData); 00187 } 00188 if(!keepimagedata) 00189 free(m_ImageData); 00190 } 00191 } 00192 } 00193 fclose (file); 00194 } 00195 return error; 00196 }
|