View Full Version : glGenTextures() very very strange.....

Allan Walton
10-21-2002, 05:57 AM
Afternoon all,

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....




10-21-2002, 06:44 AM
Heh, weird.

Code please http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Allan Walton
10-21-2002, 07:15 AM
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)

head off table weird... http://www.opengl.org/discussion_boards/ubb/wink.gif

Allan Walton
10-23-2002, 01:06 AM
Here's the code function i've been using - can anyone see what's up?

BOOL CGLTexture::GenerateTextures(CRendererMeshFormat *pMesh, CTGAFile *pTGAFile)

glGenTextures(1, &g_uiTextureID[g_TexCount]);

TRACE("pMesh->uiTexID = %d\n", g_uiTextureID[g_TexCount]);

if(glIsTexture(g_uiTextureID[g_TexCount]) == GL_TRUE)
TRACE("ERROR : Texture Name Already Taken!\n");
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);




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)


10-23-2002, 02:11 AM
if it were C I would say memory error somewhere in your code