PDA

View Full Version : Make one spec. color appear as Transparent



Dingo
04-01-2001, 01:54 AM
First of all I just want to say: I'm not sure this topic belongs here on the adv. section, if It doesn't, forgive me, but plz answer my question anyway.

Well, this is what I want!
When loading a bitmap, and just blitting it to the screen, using standard Windows API, there's a command called TransparentBlit() "or something like that" That allows the programmer to set one specific color which will be interpreted as transparent. Is it possible to do someting similar in opengl programming and if it is, how is it done?

One guy told me I should use blending, but I can't figure out how to accomplish my goal with that.

And do not tell me to read the RedBook.. I'm not in the mood for that rigth now.

/Thx Dingo

Lars
04-01-2001, 02:16 AM
Hi

In 3D APIs you normaly have BItmaps with an Alpha channel. That means you don't have an image where each pixel consists of Red Green and Blue, you have an pixel with Red Green Blue and Alpha.
With this alpha channel you can say how transparent a pixel should be. The simplest of using the alpha channel is with alpha test. This tests, if your actual pixel has an specific alpha value (or is less then or greater or...) and then discards that when drawing.

So you need to extend your texture with an alpha channel and enable the alpha testing (glEnable(GL_TEST_ALPHA)). To set the alpha test function there is a method i think it is called glAlphaFunc(...), you might have to look this up somewhere http://www.opengl.org/discussion_boards/ubb/smile.gif.

Lars

Dodger
04-02-2001, 03:30 AM
(glEnable(GL_TEST_ALPHA)).


Almost right http://www.opengl.org/discussion_boards/ubb/wink.gif
glEnable(GL_ALPHA_TEST);
And, for blending with alpha (e.g. blending 2 textures together) I usually use glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

Try that, it should work.

Deiussum
04-02-2001, 08:48 AM
Not in the mood to read the Red Book? That's blasphemy!! You should be banned from the board for saying that! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Seriously, though. There's a chapter in the Red Book that goes over blending pretty well.