about glTexEnv().

Started by
2 comments, last by Tonhom 20 years, 1 month ago
i want to know what these functions do. please, explain each line. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); glActiveTextureARB(GL_TEXTURE1_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); Thanks
Advertisement
second question.

from paul''s bump map tutorial (http://www.paulsprojects.net/tutorials/simplebump/simplebump.html)

if i want to add another light source at (0,-5,10), how can i do?

i''m so confuse about that. i don''t know where i can put the code for another dot product (of second light source).

sorry for my english.
quote:Original post by Tonhom
i want to know what these functions do. please, explain each line.

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

Thanks


Look up the specs for the ARB_texture_env_combine extension.

Basically, this extension allows you to determine how the various multi-texture stages are combined. The first instruction glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB) sets up the texture environment to use these combine extensions. The other commands specify how the combination equation is specified.

Each texture stage can have a combination of sources (GL_SOURCEN_RGB_ARB, GL_SOURCEN_ALPHA_ARB, etc...) and operators (GL_OPERANDN_RGB_ARB, GL_OPERANDN_ALPHA_ARB) which describe how that texture stage accepts incoming color/fragment data and combines it with the current stage to create an output from that stage. This output can (with the GL_PREVIOUS operator) be used by the next stage as a source.

Sources are generally one of these choices:
TEXTURE-- fragment source (color or alpha) is extracted from the texture of the current stage
CONSTANT_ARB-- fragment source is a specified constant
PRIMARY_COLOR_ARB-- fragment source is drawn from the primary color (glColor() type color specification) of the incoming fragment
PREVIOUS_ARB-- fragment source is extracted as the output from the previous texture stage.

Different modifiers are used to combine the sources in various ways. For instance, the GL_REPLACE operand will replace the outgoing fragment value with the incoming fragment source. That is, in the first part of your example block, the incoming source comes from the current stage's texture, and the output of the texture stage is a straight replacement. So, the output of that texture stage is simply the texels of that stage's texture.

In the second part of the example block you gave, the combines the PREVIOUS fragment (from stage 0, the straight replacement) with the current stage data using the DOT3_RGB_ARB operand (specified by the ARB_texture_env_dot3 extension) to output the fragment.

So, all together, the given code will basically take 2 textures (on stage 0 and stage 1), and combine their RGB data using the DOT3 operator to get the output texture.

It's a little complicated, and it is difficult to explain each individual line without explaining how the ARB_texture_env_combine extension works in the first place. The spec sheets can help you there, though they are a little obscure sometimes.

Golem
Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller

[edited by - VertexNormal on March 18, 2004 2:17:09 PM]
please, give me an example for combine 3 stage such as :
stage0 dot3 stage1 result in stage1, then
stage0 dot3 stage2 result in stage2, then
stage1 dot3 stage2 result in stage1.

This topic is closed to new replies.

Advertisement