I’ve got a function that generates a texture - enables GL_TEXTURE_2D generates a texture id (into a global UINT array) , checks it’s valid, binds it , disables GL_TEXTURE_2D (roughly)
anyway if the function returns void or a bool it’s fine BUT if i return the texture id generated or do anything with the id (set another variable equal to it, return it or anything) glGenTextures fails next time around.
i currently have three textures - the id’s if i dont do anything are 1,2,3.
if i do something like return it they are 1,1,1 (i have a glIsTexture() call below glGenTextures but it doesnt seem to do anything)
any ideas as this is incredibly weird and it’s stopping me proceeding…
i’ll bring / post the code tomorrow (it’s at home) but the function is very simple (“does exactly what it says on the tin”) so this is something very odd.
A bit more info - i have my global texture id array and a global counter which i increment after generating a texture (so the next texture ID goes into the next array space) and if i return g_TextureID[g_TexCount] it works fine (returns the wrong id as we want g_TextureID[g_TexCount-1]
(which causes the headache described above)
if(glIsTexture(g_uiTextureID[g_TexCount]) == GL_TRUE)
{
TRACE("ERROR : Texture Name Already Taken!
");
return FALSE;
}
glBindTexture(GL_TEXTURE_2D, g_uiTextureID[g_TexCount]);
// TGA's use BGR so the data needs to be read in and converted or you can use GL_BGR_EXT
UINT uiWidth = pTGAFile->GetImageWidth();
UINT uiHeight = pTGAFile->GetImageHeight();
BYTE *pImageData = pTGAFile->m_pImageData;
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, uiWidth, uiHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pImageData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glDisable(GL_TEXTURE_2D);
g_TexCount++;
return TRUE;
}
if i try to do ANYTHING with g_uiTextureID[g_TexCount]); (or g_uiTextureID[g_TexCount-1]) after incrementing g_TexCount; the tex id’s returned are all wrong (1 for every
single one)