PDA

View Full Version : Multitexture - Environment plus stencil texture



Andrew Jameson
03-15-2006, 03:36 AM
I need to apply a spherical mapped environment texture to an object followed by another texture that uses alpha blended texture. The result is an a shiny object apart from areas that were excluded by the second texture.

Now the problem is down to the fact that I can't afford the performance hit caused by the multipass rendering and wondered how / whether I could use achieve the same result in a singlepass ?

I need to avoid many of the more advanced features now supported by cards - let's say that it's got to work on something like an NVidia Geforce 2.

Many thanks,

Andrew

ZbuffeR
03-15-2006, 05:40 AM
Why not multitexture instead of multipass ?
search "Official Multitexture Extension" in following page :
http://www.opengl.org/resources/features/OGLextensions/

Andrew Jameson
03-15-2006, 07:01 AM
Thanks for the reply ... I think that I am on my way now ... lots to learn again, as I've no idea what half of this does yet ! Some good pointers to some docs would be good.

OK ... I've found some code that I've modified and it works ... but ... issues of card compatibility are of concern ... for example is GL_COMBINE4_NV which obviously originates from NVidia - is it available on most cards - ATI ?

Thanks


// Initialization
// Already tested for extensions ...
glGenTextures(1, fTextureName1);
glActiveTextureARB(GL_TEXTURE0_ARB);
LoadBitmapFile('LogoMetal.bmp', fTextureName1, GL_FALSE);

// The 'true' flag creates a texture with an alpha channel.
glGenTextures(1, fTextureName2);
glActiveTextureARB(GL_TEXTURE1_ARB);
LoadBitmapFile('Tile.bmp', fTextureName2, GL_TRUE);

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);

// Draw routine ...
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, fTextureName2);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, fTextureName1);

glPushAttrib(GL_ENABLE_BIT);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glCallList(fGLList);
glPopAttrib;

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D)

ZbuffeR
03-15-2006, 07:36 AM
Yes it is NV only, i think the following extension looks more suitable :
http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt
and is widely supported from geforce2/radeon7000 hardware :
http://delphi3d.net/hardware/extsupport.php?extension=GL_ARB_texture_env_combin e

Andrew Jameson
03-15-2006, 11:26 AM
Many thanks for your help ...

Andrew