PDA

View Full Version : Problems with textures



Flogo
02-04-2007, 02:55 AM
Hi there,

Im having some problems with creating textures.
Im trying to load the textures with this procedure

void setTextureToObject(char* textureFilename, int obj)
{
Mesh::Texture texture;
// this one works fine
Mesh::loadTexture(textureFilename, texture);
// glGenTextures returns the same IDs on different calls
glGenTextures(1, &(Objects[obj].gTextureAccessor));
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, Objects[obj].gTextureAccessor);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, texture.pTextureData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture.width, texture.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture.pTextureData);
Mesh::unloadTexture(texture);
}(Objects is a Vector of a struct with the object data; Mesh::texture is a struct to hold the temporary texture on loading)

the funny thing is I call this procedure twice in my initialization and it works just fine there, but as soon as Im in the main loop glGenTextures start setting gTextureAccessor to 1 again.
I tried replacing this line with a global counter but although the texture-ids are correct now its not working.

Sometimes this results in the correct texture, sometimes the objects have no texture and sometimes they disapear completely

Komat
02-04-2007, 03:06 AM
Has the structure stored within the Objects vector a destructor that destroys the texture? When new elements are added to stl vector, the entire content is sometimes copied to new memory which will cause call of destructor on objects in the old memory.

Flogo
02-04-2007, 10:35 AM
Thanks for the hint but unfortunately the structure has no destructor and there is (until now) no line of code that says "glDeleteTextures"

Flogo
02-04-2007, 11:02 AM
ohh I think I just found the problem: forgot to initialize gTextureAccessor ... *stupid*
thanks agian