Advertisement

masking

Started by February 15, 2002 08:57 AM
0 comments, last by penetrator 23 years ago
Hi, i''m using the following code (and it works fine) to draw a textured object with trasparency. However, it requires to draw 2 quads and use 2 textures, so here is my question: can i achieve the same only drawing 1 quad and using only one texture ? glBlendFunc(GL_DST_COLOR,GL_ZERO); glBindTexture(GL_TEXTURE_2D, bw_texture); glBegin(GL_QUADS); // draw the quad glEnd(); glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, color_texture); glBegin(GL_QUADS); // draw the quad stuff glEnd(); glHorizon_Project

www.web-discovery.net

Assuming that your quads exactly overlap, you can.

The easiest method is to assign an alpha channel to your coloured texture. Tha alpha channel has to be 1 wherever you want to draw your texture, and 0 wherever you don''t want to draw your texture (eg see what''s behind).
But this works essentially if your coloured texture doesn''t already has an alpha channel. If your texture already has an alpha channel, it''s still possible but it''s a bit more difficult.

Then you have (at least) two solutions for using this texture that has a brand new alpha chennel :

Blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, color_and_alpha_texture);
glBegin(GL_QUADS);
// draw the quad stuff
glEnd();

Alpha Testing
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL, 0.0f);
glBindTexture(GL_TEXTURE_2D, color_and_alpha_texture);
glBegin(GL_QUADS);
// draw the quad stuff
glEnd();

I think the second method is faster.

This topic is closed to new replies.

Advertisement