I have a problem with textures of different numbers of dimensions and which one OpenGL is choosing to apply. At the start of my program 2 textures are loaded, one 1D and one 2D. The relevant OpenGL calls I make before rendering my objects are glEnable(GL_TEXTURE_1D), glEnable(GL_TEXTURE_2D), glTexCoordPointer(1, GL_FLOAT, ...), and glBindTexture(GL_TEXTURE_1D, ...). So, pseduo code for the whole thing is
LoadTexture1D();
LoadTexture2D();
...
glEnable(GL_TEXTURE_1D);
glEnable(GL_TEXTURE_2D);
...
glBindTexture(GL_TEXTURE_1D, 1Dtexture);
glTexCoordPointer(1, GL_FLOAT, vsize, offset);
...
RenderMesh();
Here is part of the code in LoadTextureND();
...
glGenTextures(1, (unsigned int *)(&(p_clsTexture.m_ptrObject)));
if ( uintHeight > 1 )
{
p_clsTexture.m_uchrDimensions = 2;
glBindTexture(GL_TEXTURE_2D, (unsigned int)(p_clsTexture.m_ptrObject));
if ( glIsTexture((unsigned int)(p_clsTexture.m_ptrObject)) != GL_TRUE )
{
glDeleteTextures(1, (unsigned int *)(&(p_clsTexture.m_ptrObject)));
delete [] ptrTextureData;
return false;
}
GLenum enmFormats[] = {0, GL_ALPHA, 0, GL_BGR_EXT, GL_BGRA_EXT};
glTexImage2D(GL_TEXTURE_2D,
0,
(int)(ushtChannels),
uintWidth,
uintHeight,
0,
enmFormats[ushtChannels],
GL_UNSIGNED_BYTE,
ptrTextureData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
p_clsTexture.m_uchrDimensions = 1;
glBindTexture(GL_TEXTURE_1D, (unsigned int)(p_clsTexture.m_ptrObject));
if ( glIsTexture((unsigned int)(p_clsTexture.m_ptrObject)) != GL_TRUE )
{
glDeleteTextures(1, (unsigned int *)(&(p_clsTexture.m_ptrObject)));
delete [] ptrTextureData;
return false;
}
GLenum enmFormats[] = {0, GL_ALPHA, 0, GL_BGR_EXT, GL_BGRA_EXT};
glTexImage1D(GL_TEXTURE_1D,
0,
(int)(ushtChannels),
uintWidth,
0,
enmFormats[ushtChannels],
GL_UNSIGNED_BYTE,
ptrTextureData);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
...
My question is, how come the 2D texture is applied to the mesh even though I have the 1D texture bound (which implies the 2D texture is NOT bound), and the VBO has 1 texture coordinate? The only way I can get it to apply the correct texture is if I explicitly disable 2D with glDisable(GL_TEXTURE_2D). But why should I have to do that?