Original Post
I want to load TGA in my engine but i dont know much bout it!
I took a little bit of Nate Miller and a little bit of Shninig knights tutos...
the result is shit...
I want to see how it works and how good tga''s are...
With this class I want to texture a 3d wall but when I start the programm...the window is totaly white Ya cant see anything it is just white! Why?!
what is wrong?!
Thx
bool MW_TextureManager::DisplayTexture(bool TextureData)
{
glBindTexture(GL_TEXTURE_2D, TextureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texEnv);
if(mipmap)
gluBuild2DMipmaps(GL_TEXTURE_2D, Internal, width, height, Format,
GL_UNSIGNED_BYTE, imageData);
else
glTexImage2D(GL_TEXTURE_2D, 0, Internal, width, height, 0, Format,
GL_UNSIGNED_BYTE, imageData);
if(TextureData)
ReleaseTex();
delete [] imageData;
imageData = 0;
return TRUE;
}
bool MW_TextureManager::LoadTGA(char *filename)
{
GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
GLubyte TGAcompare[12];
GLubyte header[6];
GLuint bytesPerPixel;
GLuint imageSize;
GLuint temp;
GLuint type=GL_RGBA;
FILE* file = fopen(filename, "rb");
if(file==NULL ||
fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||
memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 ||
fread(header,1,sizeof(header),file)!=sizeof(header))
{
if(file==NULL)
{
Log("%s does not exist.", filename);
return false;
}
else
{
fclose(file);
Log("Could not load %s correctly, general failure.", filename);
return false;
}
}
width = header[1] * 256 + header[0];
height = header[3] * 256 + header[2];
if(width <=0 ||
height<=0 ||
(header[4]!=24 && header[4]!=32))
{
fclose(file);
Log("%s''s height or width is less than zero, or the TGA is not 24 or 32 bits.", filename);
return false;
}
bpp = header[4];
bytesPerPixel = bpp/8;
imageSize = width * height*bytesPerPixel;
imageData=(byte *)malloc(imageSize);
if(imageData==NULL ||
fread(imageData, 1, imageSize, file)!=imageSize)
{
if(imageData!=NULL)
free(imageData);
Log("Storate memory for %s does not exist or is corrupted.", filename);
fclose(file);
return false;
}
for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel)
{
temp=imageData[i];
imageData[i] = imageData[i + 2];
imageData[i + 2] = temp;
}
fclose (file);
if(bpp==24)
type=GL_RGB;
if(bpp==8)
type=GL_ALPHA;
Log("Loaded %s correctly.", filename);
return true;
}
bool MW_TextureManager::ReleaseTex()
{
if(TextureID)
glDeleteTextures(1,&TextureID);
return TRUE;
}
|