Jump to content
  • Advertisement
Sign in to follow this  
zengq

multitexturing the old way

This topic is 2738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Capture.JPG

I managed to render the reflection using glCopyTexImage2D but when I blend it with the original texture of the surface, the color appear strange.
Here is the code for taking the snapshot under the surface.



//take a snapshot
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex[1]);
//glEnable(GL_TEXTURE_2D);
glReadBuffer(GL_BACK);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,0,0 ,TABLE_WIDTH, TABLE_WIDTH, 0);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);


here I use both texture for the surface.

glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, 0.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE1, 0.0, 0.0);
glVertex3f(-TABLE_WIDTH/2, -TABLE_WIDTH/2, 0);
...



I used GL_REPLACE for the texture 0. It's a image read from computer.
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


What could be wrong?

Share this post


Link to post
Share on other sites
Advertisement
Can anyone just take a look at this thread? I think this should be just a newbie question. If you can just point me to the correct direction, i will appreciate it.

Share this post


Link to post
Share on other sites
It looks like the red and blue channels are flipped. Are you sure your texture was created as a GL_RGB texture?

Share this post


Link to post
Share on other sites
I must admit I don't study this old fixed function stuff anymore (you should really try to move off of it and into shaders eventually).

Anyway, looking at the man page for glTexEnv, this is the equation it gives for GL_BLEND:


Cv = Cp*(1-Cs) + Cc*Cs

Cv: output color of texture stage
Cp: color output from previous texture stage
Cs: color from current texture stage
Cc: texture environment color


Since you haven't claimed to set the environment color, I will assume it is (0,0,0,0) (default).

Thus in your case, lets look at a sample from the blue teapot. Assume that the ground texture color is (0.5,0.5,0.5), and the teapot color is (0,0,1).

Plugging these into the blend equation, you get:

Cv = Cp * (1-Cs ) + Cc * Cs
Cv = (0.5,0.5,0.5) * (1-(0,0,1)) + (0,0,0)* (0,0,1);
Cv = (0.5,0.5,0.5) * (1,1,0) + 0;
Cv = (0.5,0.5,0 ) //red-green, or a brown color, which you see in the reflection.


So given what you've shown, you're getting the exact output that the equations say you should.

What you probably want to do is to set the texture environment color to (1,1,1), which would then give you the output color (0.5,0.5,1), which is probably more like what you're expecting to see.

You can set this with glTexEnvfv.

http://www.opengl.org/sdk/docs/man/xhtml/glTexEnv.xml

Share this post


Link to post
Share on other sites

I must admit I don't study this old fixed function stuff anymore (you should really try to move off of it and into shaders eventually).

Anyway, looking at the man page for glTexEnv, this is the equation it gives for GL_BLEND:


Cv = Cp*(1-Cs) + Cc*Cs

Cv: output color of texture stage
Cp: color output from previous texture stage
Cs: color from current texture stage
Cc: texture environment color


...




Thank you very much karwosts!! You save my life!
I think I really overlooked those functions.
In fact, this is an assignment from graphic rendering course. We are supposed to get used to the view transformation and texture mapping stuff. I also learnt glsl method in another course.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!