views:

39

answers:

1

I am looking at some sample code in a book that creates a jittered antialiasing effect by repeatedly rendering a scene (at different offsets) onto a offscreen texture, then using that texture to repeatedly draw a quad in the main view with some blend stuff set up.

To accumulate the color "correctly", the code is setting the color like so:

glColor4f(f, f, f, 1);

where f is 1.0/number_of_samples, and then binding the offscreen texture and rendering it.

Since textures come with their own color and alpha data, what is the effect (mathematically and intuitively) that setting the overall "color" in advance achieves?

Thanks.

+4  A: 

The default texture environment is GL_MODULATE, this means that the vertex color (set with glColor) is multiplied with the texture color.

So, mathematically, it does:

fragmentColor = texColor / numberOfSamples (alpha = 1.0)

Hope that explains it.

Matias Valdenegro
Thank you! That helps. So the followup question to make sure I get it is: If I want to map a texture to a quad, and preserve exactly the RGBA that is on the texture, I can do one of two things: 1. Change the texture environment to GL_REPLACE or 2. Set the color to (1, 1, 1, 1). Is this correct?
quixoto
Yes, that's correct.
Matias Valdenegro
Awesome, thanks.
quixoto