Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture problem...

Started by Strylinys Nov 18, 2000 at 11:13 AM 2 replies 500+ views
Original Post
Strylinys
Strylinys
Well, I have done lots of bmp textures and things, but I got bored of them, so I decided to try TGA. I have all my code set up exactly like NeHe''s tut, but I''m getting this crazy thing happening and I want it to go away. The texture is NOT moving with the object, it''s staying in one place when my object moves so it''s still kinda textured, but it''s not properly done... Hope you know what I''m talking about... It''s like the quad I have set up is acting as a window that looks onto the wall of the texture and when I move the texture, the wall stays where it is... Get it? Any help''s great. Thanks. S.
oglman
oglman
I have no idea if this is the problem but try putting this in your init code:

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

and this at the beginning of your draw code:

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

It sounds like somehow you have GL_EYE_LINEAR enabled but the problem could be something different. If that doesn''t work post the code here so people can see what the problem might be.




Open mouth, insert foot
Strylinys
Strylinys
Ya, that''s what I thought too... I have those lines in there tho, and nowhere in my code does it say anything that remotely specifies the coords off of the quad... It''s annoying...

Here''s the LoadTGA source, anywho.

  
bool LoadTGA(TGAImage *CurrentTexture, char *FileName)
{
unsigned char TGAHeader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned char TGACompare[12];
unsigned char Header[6];
unsigned int BytesPerPixel;
unsigned int ImageSize;
unsigned int Temp;
unsigned int type = GL_RGBA;

FILE *file = fopen(FileName, "rb");

if (file == NULL ||
// does the file exist

fread(TGACompare, 1, sizeof(TGACompare), file) != sizeof(TGACompare) ||
// are there 12 bytes to read?

memcmp(TGAHeader, TGACompare, sizeof(TGAHeader)) != 0 ||
// does the header match what we want?

fread(Header, 1, sizeof(Header), file) != sizeof(Header))
// if so, read the next 6 header bytes

{
if (file == NULL)
return false;
else
{
fclose(file);
return false;
}
}

CurrentTexture->width = Header[1] * 256 + Header[0];
CurrentTexture->height = Header[3] * 256 + Header[2];

if (CurrentTexture->width <= 0 || CurrentTexture->height <= 0 || (Header[4] != 24 && Header[4] != 32))
{
fclose(file);
return false;
}

CurrentTexture->bpp = Header[4];
BytesPerPixel = CurrentTexture->bpp/8;
ImageSize = CurrentTexture->width * CurrentTexture->height * BytesPerPixel;

CurrentTexture->ImageData = (unsigned char*)malloc(ImageSize);

if (CurrentTexture->ImageData == NULL || fread(CurrentTexture->ImageData, 1, ImageSize, file) != ImageSize)
{
if (CurrentTexture->ImageData != NULL)
free(CurrentTexture->ImageData);

fclose(file);
return false;
}

for (int count = 0; count < int(ImageSize); count += BytesPerPixel)
{
Temp = CurrentTexture->ImageData[count];
CurrentTexture->ImageData[count] = CurrentTexture->ImageData[count + 2];
CurrentTexture->ImageData[count + 2] = Temp;
}

fclose(file);

glGenTextures(1, &CurrentTexture->TexID);

glBindTexture(GL_TEXTURE_2D, CurrentTexture->TexID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

if (CurrentTexture->bpp == 24)
{
type = GL_RGB;
}

//glTexImage2D(GL_TEXTURE_2D, 0, type, CurrentTexture->width, CurrentTexture->height, 0, type, GL_UNSIGNED_BYTE, CurrentTexture->ImageData);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, CurrentTexture->width, CurrentTexture->height, type, GL_UNSIGNED_BYTE, CurrentTexture->ImageData);

return true;
}


Thanks for your help...

S.
Strylinys
Strylinys
I''m sure SOMEONE''s gotta have an idea of how to fix this...

S.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.