Sign in to follow this  

Transparency With a Specific Colour?

This topic is 3641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know that I can get blending with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); but that only works with the sources alpha colour. How can I define my own alpha colour for the source? Like say (0,0,255)?

Share this post


Link to post
Share on other sites
The technique you describe is called "color-key transparency" and it isn't actually directly supported by your graphics card (AFAIK). To achieve this technique, you'll have to use regular GL blending functionality that you describe, and algorithmically create the appropriate alpha channel in your texture.

If you want to use this technique in your OpenGL application, you will have to modify your texture loading code to look for that colour and fill in the alpha channel appropriately:

for each pixel in bitmap
if pixel.rgb == (0,0,255) then
pixel.rgb = (0,0,0)
pixel.a = 0;
else
pixel.a = 1;
endif
endfor

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
The technique you describe is called "color-key transparency" and it isn't actually directly supported by your graphics card (AFAIK). To achieve this technique, you'll have to use regular GL blending functionality that you describe, and algorithmically create the appropriate alpha channel in your texture.

If you want to use this technique in your OpenGL application, you will have to modify your texture loading code to look for that colour and fill in the alpha channel appropriately:

for each pixel in bitmap
if pixel.rgb == (0,0,255) then
pixel.rgb = (0,0,0)
pixel.a = 0;
else
pixel.a = 1;
endif
endfor


oh righty then, it's a lot easier in directx but ok.

Share this post


Link to post
Share on other sites
Quote:
Original post by chillypacman
oh righty then, it's a lot easier in directx but ok.


Incidently enough, DirectX does pretty much the same thing under the hood of the D3DX functions. But yes, it is easier in the sense it's done for you.

Share this post


Link to post
Share on other sites
Sign in to follow this