Multitexture - Texture with alpha plus environment map

I need to apply a texture (actually a letter) onto the face of an object and then apply an spherical environment map to the object. I have arranged the alpha to be zero on the first texture over the area covered by the letter and need this area to be excluded from the environment map.

I can achieve this in a multipass render but I can’t afford the performance hit. I have eventually found the following code works but it uses GL_COMBINE4_NV and I believe that this is specific and only supported by NVidia cards.

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_ZERO);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_ONE_MINUS_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_RGB_EXT, GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_RGB_EXT, GL_SRC_ALPHA);

I’m working to a very tight deadline and wondered if what I want can be achieved and if so how ?

Whilst not exactly new to OpenGL, my experience with multitexturing is new and I would appreciate any links that might help me in my understanding of this subject.

Many thanks,

Andrew

This is core OpenGL and should be kinda what you are looking for:

glActiveTextureARB(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
//Bind diffuse with alpha here
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOUS)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_COLOR)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_COLOR)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA,GL_MODULATE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA,GL_PREVIOUS)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA,GL_SRC_ALPHA)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA,GL_TEXTURE)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA,GL_SRC_ALPHA)

glActiveTextureARB(GL_TEXTURE1)
glEnable(GL_TEXTURE_2D)
//Bind sphere map here
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_INTERPOLATE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_TEXTURE)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_COLOR)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_PREVIOUS)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_COLOR)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB,GL_PREVIOUS)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB,GL_SRC_ALPHA)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA,GL_REPLACE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA,GL_PRIMARY_COLOR)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA,GL_SRC_ALPHA)

Don’t forget to reset you OpenGL texture states when done!

(eg:
//Reset texture stage 1
glActiveTextureARB(GL_TEXTURE1)
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glDisable(GL_TEXTURE_2D)

//Reset texture stage 0
glActiveTextureARB(GL_TEXTURE0)
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

)

Wow ! … that works very well but for the fact that the original diffuse texture color is lost by the predominance of that of the spherical map.

(can you recommend any reading on the subject … at the moment it’s more akin to cracking a combination lock rather than programming !)

Andrew

I am not sure what you mean by “original diffuse texture color is lost”. Is there some part of the origional scene you want this blended over? (in which case just use some alpha blending mode)

The red book(OpenGL Programming Guide) (4th edition or higher) has some nice descriptions on how texture combiners work.
http://www.amazon.com/gp/product/0321335…5Fencoding=UTF8

I might do some descriptions in the new OpenGL wiki if you want to be my “beginner” test case and do some proof-reading.