Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,656 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,188 people online right now. Registration is fast and FREE... Join Now!




openGL transparent color

 
Reply to this topicStart new topic

openGL transparent color

FrozenSnake
post 20 Aug, 2008 - 05:14 PM
Post #1


D.I.C Head

**
Joined: 30 Jul, 2008
Posts: 55


My Contributions


I try to get the color #ff00ff transparent without much luck.
CODE
glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glColor4f(1, 1, 1, 0.8f);
        aSprite = 0;
        glBindTexture(GL_TEXTURE_2D, sprite[aSprite]);
        glBegin(GL_POLYGON);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(float(sxPos + sprx), float(syPos + spry), 0.0f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(float(sxPos + 1 + sprx), float(syPos + spry), 0.0f);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(float(sxPos + 1 + sprx), float(syPos + 1 + spry), 0.0f);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(float(sxPos + sprx), float(syPos + 1 + spry), 0.0f);
        glEnd();
        glDisable(GL_BLEND);

This makes the entire sprite transparent and thats really not what I want to do.

This is how it looks right now
Attached Image

This is how I want it to look
Attached Image

Best regards!
User is offlineProfile CardPM

Go to the top of the page

Tom9729
post 20 Aug, 2008 - 09:22 PM
Post #2


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,447



Thanked 10 times

Dream Kudos: 325
My Contributions


Unrelated to your problem but you should probably be using GL_QUAD instead of GL_POLYGON (since it seems you're just drawing a quad). smile.gif

I'm a little tired right now, but basically what it looks like you're doing is drawing a rectangle and putting a texture on it. Your texture is an RGB image with a purple background that you want to represent transparency.

Pretty sure that call to glColor* is setting the color to white with an alpha/opacity value of 0.8 [which is probably not what you intend].

Basically what you need to do is to put your image into a format that stores alpha [ie. opacity] values, f.ex. TGA. OpenGL doesn't know that #ff00ff means transparent, because #ff00ff is just another RGB color. Transparency in OpenGL is handled by playing with the alpha value [ie. RGBA = Red Green Blue Alpha].

You could try to do some kind of color masking to convert your RGB texture to a RGBA texture during runtime, but I think that would be a lot more work.

I wrote a TGA loader snippet I believe that supported loading uncompressed 24bit TGAs if you want to take a look. icon_up.gif

Hope all of that makes sense, I need sleep. tongue.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:34AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month