Hello to all,
i am usign display list in order to draw my scene. Some textures are attached to some object and so i generate and bind the texture inside the Dispaly List as following:
if ( IsTextured() )
{
glEnable( GL_TEXTURE_2D );
osg::ImagePtr img = m_textures->getImage();
GLuint textureID = 0;
glGenTextures(1, &textureID); // Create The Texture
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, img->getPixelFormat() , img->getWidth(), img->getHeight(), 0, img->getPixelFormat(), img->getDataType(), img->getData());
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,4);
SetTextureObject(textureID); //store the current textureId for a future use
}
After drawing correctly the scene i need to do some shading operation using glsl and the loaded texture. So i need to pass to the shaders the correct textureID but when i try to read that value:
unsigned int textureID = vrobject->GetTextureID();
the returned value is always equal to the last texture id generated.
Any idea about?
thank you very much.
ps. i think i could try using texture object insted, generate them outiside display list generation and call them inside but i would like to understand why it is not working the proposed solution.