PDA

View Full Version : What wrong with my texture loading code?



Jnz86
02-22-2004, 09:14 AM
What wrong with my texture loading code? Sometimes when i load with mipmaping disabled textures doesn't load (shapes binded with that texture apear white)
=============================================
AUX_RGBImageRec *LoadBMP(char *Filename)
{
if (!Filename) return NULL;

FILE *File = NULL;

File = fopen(Filename, "r");

if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}

return NULL;
}

void Load(char *file2, bool mipmap)
{
AUX_RGBImageRec *TexImage ;

memset(&TexImage, 0, sizeof (void *));

char file[256];

strcpy(file, "Textures\\");
strcat(file, file2);

TexImage = LoadBMP(file);

if (!TexImage)
{
Log("ERROR: Cannot load texture: %s", file);

if (TexImage)
{
if (TexImage->data)
free(TexImage->data);
free (TexImage);
}

return;
}

glGenTextures(1, &Tex);
glBindTexture(GL_TEXTURE_2D, Tex);

if (!mipmap)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3, TexImage->sizeX, TexImage->sizeY, 0,GL_RGB, GL_UNSIGNED_BYTE, TexImage->data);
}

//jeigu reikia mipmapo
if(mipmap)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TexImage->sizeX, TexImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TexImage->data);
}

if (TexImage)
{
if (TexImage->data)
free(TexImage->data);
free (TexImage);
}

Log("Texture %s loaded", file2);
}

chowe6685
02-22-2004, 09:51 AM
remember that texture dimensions must be powers of 2

Jnz86
02-22-2004, 09:56 AM
Yes, i know that...