PDA

View Full Version : 2D texture is not mapped; constantly getting black quadrangle



sansan
04-07-2003, 11:31 PM
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.

raverbach
04-08-2003, 04:18 AM
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 http://www.opengl.org/discussion_boards/ubb/frown.gif, so take it from from there.

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

sansan
04-08-2003, 05:09 AM
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 http://www.opengl.org/discussion_boards/ubb/frown.gif, so take it from from there.


Enabling it outside glBegin/glEnd...



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



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

raverbach
04-08-2003, 05:27 AM
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 http://www.opengl.org/discussion_boards/ubb/frown.gif

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

rgpc
04-09-2003, 01:54 AM
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.

Proton
04-09-2003, 06:31 AM
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.