Sign in to follow this  
zengq

multitexturing the old way

Recommended Posts

[img]https://lh4.googleusercontent.com/_ZTV6QZ1OKUI/TV6SKRxsluI/AAAAAAAABf4/nT-pSm-cIMs/Capture.JPG[/img]

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.


[code]
//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);
[/code]

here I use both texture for the surface.
[code]
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);
...
[/code]


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


What could be wrong?

Share this post


Link to post
Share on other sites
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:

[code]
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
[/code]

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:
[code]
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.
[/code]

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
[quote name='karwosts' timestamp='1298187093' post='4776599']
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:

[code]
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
[/code]

...
[/quote]



[size="2"]Thank you very much karwosts!! You save my life![/size]
[size="2"]I think I really overlooked those functions. [/size]
[size="2"]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.[/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this