Transparency With a Specific Colour?

Started by
2 comments, last by Flimflam 16 years, 2 months ago
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)?
Advertisement
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;  endifendfor
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;  endifendfor


oh righty then, it's a lot easier in directx but ok.
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.

This topic is closed to new replies.

Advertisement