Click to See Complete Forum and Search --> : opengl texture mapping problem


chicken8
May 17th, 2004, 10:02 PM
Hello, recently, i got problem about the opengl texture mapping,
i use the MODUATE mode to map the texture,
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, m_texName);

glBegin(GL_QUADS);

for(int i=0; i<10; i++)
{
glColor4f(0.5, 0, 0, 0.1);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, i);
glTexCoord2f(0.0, 2.0); glVertex3f(-2.0, 1.0, i);
glTexCoord2f(2, 2); glVertex3f(0.0, 1.0, i);
glTexCoord2f(2, 0); glVertex3f(0.0, -1.0, i);
}
glEnd();
glFlush();
but i can see nothing, then i changed the paramenter of glColor4f
into glColor4f(0.8, 0, 0, 0.3) and i see the alpha blended textures.
I wonder if it is my hardware that do not support precise rendering or i need extra configration to opengl.
my pc is ibm r40 with mobile radoen.
Please Help!!

Bornish
August 11th, 2004, 08:22 AM
GL_MODULATE does the following: Cv = Lt*Cf and Av = Af, where C=(RGB) component and A is the alfa value.
There are a few details missing in your post:
Your sample code doesn't show if you enabled blending when mapping the textures, which means each texture will be combined not only with the drawing color, but with the destination buffer, too.
You forgot to mention how you loaded your texture object, as GL_RGB, GL_RGBA, GL_RED (one channel only), etc...
Are you using depth testing or else why do you pass "i" as z coordinate to glVertex3f?
Anyway, your call glColor4f(0.5, 0, 0, 0.1) is not required inside the for loop, since doesn't depend on "i" counter and you're not changing the drawing color anywhere else.
What I don't understand is why you multiply the green & blue channels with 0, when you can just disable drawing those channels with
glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_TRUE);
The last thing I find weird is that red channel gets multiplied with 0.5 and/or 0.8 up to 10 times, which means if a pixel in your texture has the red value 100, lets say, your final image will have a red value of... 100*0.5*10=500 which is clamped by OpenGL to the maximum value 255. In fact, things are a bit more complicated since ogl works with values in [0,1] when talking about color channels, but still... you'll get most probably RED.

chicken8
August 20th, 2004, 08:10 AM
thanks!
actually, the key point is that i didn't disable the depth test.
If I disable depth test, everything is ok.

By the way, i am doing the 3d reconstruction of CT slices which needs texture blending. does anyone has some suggestion?