2D texture is not mapped; constantly getting black quadrangle

I use the code below (really standard one):

glGenTextures(1, &texname);
glBindTexture(GL_TEXTURE_2D, texname);
makeTexture(); // here pixel colors are calculated
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height,
0, GL_RGB, GL_UNSIGNED_BYTE,
&image[0][0][0]); //
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, texname);
drawPolygon(); // glTexCoord2 is used here in conjunction with glVertex

This code was inserted into a large visualization library. And it doesn’t work there. While it works well in a small standalone application. I checked the following possible problems:

  1. Incorrect texture dimensions
  2. Errors after texture-related GL function calls (glGetError says it’s OK).
  3. Incorrect texture coordinates

It seems that everything is OK except that texture is not mapped!!! OpenGL monsters, do you have any ideas why? I work on TNT2 Pro under Win2k+SP3.

1-Checked the UV coordinates for the textures ?
they are correctly placed into the vertex they should ?

2-Are you enabling the texture unit insida a glBegin(),glEnd() pair ? if yes , it won´t work , so take it from from there.

3-Check if any crazy bug is occuring while creating the texture.

Originally posted by raverbach:
1-Checked the UV coordinates for the textures ?
they are correctly placed into the vertex they should ?

I did. It’s OK.


2-Are you enabling the texture unit insida a glBegin(),glEnd() pair ? if yes , it won´t work , so take it from from there.

Enabling it outside glBegin/glEnd…

[b]
3-Check if any crazy bug is occuring while creating the texture.

[/b]

I use simple for-loop to create the test texture. Colors are properly computed and put into it.

Ohhh …i see , it´s working well alone …
check if you´re not gatting into conflict with another texture unit ,that it´s not disabled and is not beeing used …for example

if someone used a

 
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE-2D,GtEX[i]);
glEnable(GL_TEXTURE_2D);  

glActiveTextureARB(GL_TEXTURE1_ARB)
glBindTexture(GL_TEXTURE-2D,GtEX[i]);
glEnable(GL_TEXTURE_2D);  
.
.
.

and did not disable one of the texture units
then glTexCoord will not work properly

you must check all texture unit calls , disable them like that

glActiveTextureARB(GL_TEXTURE0_ARB)
glDisable(GL_TEXTURE_2D);

Or if they use arrays , just disable the texure array

glDisableClientState();

then use your code

Try using gluBuild2DMipmaps() instead of glTexImage2D() OR don’t use mip maps (If you are only specifying Lvl 0 of your mip maps and any other level is used when drawing your geometry will result in the texture not being drawn.

Other strange things that could affect it are lighting and blending.

Before calling drawPolygon() try,
glDisable( GL_LIGHTING )
glDisable( GL_BLEND )
and even
glDisable( GL_TEXTURE_2D )

See what happens. Maybe something strange, maybe nothing at all.