Archived

This topic is now archived and is closed to further replies.

borfast

glTexEnvi using GL_REPLACE?

Recommended Posts

From the OpenGL Blue Book, the glTexEnvi() function definition is the following: void glTexEnvi(GLenum target, GLenum pname, GLint param) PARAMETERS . . . param - Specifies a single symbolic constant, one of GL_MODULATE, GL_DECAL, or GL_BLEND. but in the book "OpenGL Game Programming, I see glTexEnvi() used with GL_REPLACE in the "param" parameter lots of times. The first time I noticed it, I thought "that''s probably an error, if I check the source it should be corrected" and so I did... but it was just the same as in the book. And when I tried to compile it, I expected an error but it runs just fine! Can someone explain me why and what does that parameter do? Thanks Raúl

Share this post


Link to post
Share on other sites
GL_REPLACE basically tells the renderer to skip the current color and just use the texel colors--if you use GL_MODULATE then if you make a call to glColorx() your textures will be filtered to that color too.

i.e. if you call glColor3f(0.0, 0.0, 1.0) and then draw a texture triangle, the texture will only contain it''s blue elements. The same triangle drawn after you engage GL_REPLACE will appear in it''s "true" colors regardless of the current color.

At least that''s my understanding.

Share this post


Link to post
Share on other sites
So for every fragment of a polygon needs a color.
The polygon starts with a colour C.
The texture has a colour T.
And F is what the color ends up as.

GL_REPLACE:
The polygon ends up the colour T.
F = T

GL_MODULATE:
The polygon''s original colour and the texture colour are multiplied together.
F = CT

GL_DECAL:
This is just like GL_REPLACE, unless you specify an alpha for your texture. Then part of the original polygon colour is made to shine through the texture. Kind of like a bad wallpaper job where you can see the paint behind it.

GL_BLEND:
This is a bad wallpaper job all the time.

Hope this explains it. This is kind of a simplified explanation, but check this link for the exact mathematical equations:
http://www.pik-net.pl/marekm/glspec1.1/node88.html#4591

And you may be look in version 1.1 of the bluebook and version 1.2 of the redbook.

Somebody correct me if I''m wrong, but GL_REPLACE may have been added in the 1.2 spec.

SL

Share this post


Link to post
Share on other sites
Thanks for your explanations.

Screaming Lunatic, I thought about that (GL_REPLACE being added in the 1.2 spec) but since I don''t have access to the more recent versions of the book...

Well, thanks again, everybody!

Share this post


Link to post
Share on other sites