Skip to main content
gamedev.net
🔒 Locked

Image Transparency

Started by Mr_Ridd 1 reply 300+ views
Original Post
Mr_Ridd
Mr_Ridd
It''s not what you think it is. I don''t want to make the image see-through. I want to set a cursor according to the mouse position. Say I have a cursor with a bright green background. I want to import the image but I don''t want the bright green background. Is there something in OpenGL that allows me to tell it what colours it must make invisible. It''s a cursor, I don''t want the cursor to be a box.
The ability to succeed is the ability to adapt
Mezz
Mezz
If you''re using OpenGL I''m going to assume you are drawing your cursor as something like a textured quad/tri?
All the following is based on that assumption.

What you''re talking about is colour keying I believe, and there isn''t any specific support for it in OpenGL AFAIK. You have to use blending of some kind.

There are several workarounds you can do depending on what level of pervesity you want to go to.

Method 1:
Make your cursor image RGBA, in a paint program, and put alpha of zero where you dont want it to be displayed (i.e. where you have bright green at the minute) and an alpha of 255 where you want it to be displayed (on the actual cursor itself) then either enable alpha blending (src_alpha, inv_src_alpha) or the alpha test during rendering and you should only see the image where the alpha is full (i.e. on the cursor).

Method 2:
When you load in the image manually convert it to RGBA in code, putting an alpha of zero where the bright green is (you are doing this programmatically by checking the pixel value against your bright green and then adding an alpha of zero if so, or an alpha of 255 otherwise). Then you can use alpha blend/test as in Method 1.

Method 3:
Use fragment programs to do any number of tricks (like killing the fragment based on it''s colour), but I suspect this really is overkill.

Conclusion:
Method 1 is the easiest, just learn to work with images that instead of being ''bright green'' where you dont want displayed, have an alpha value of zero, it''s pretty simple when you get the hang of it. I think NeHe probably has tutorials related to this kind of thing so you can look there for more information.

Hope some of that helped.

-Mezz
Mr_Ridd
Mr_Ridd
I couldn''t get it to work. I''m not sure if it is my code or the picture. Is there a picture I can get from somewhere to test, so I know which of the two is wrong?
The ability to succeed is the ability to adapt

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.