PDA

View Full Version : Loading an RGB bitmap with alpha?



PrestoChung
03-19-2011, 06:25 PM
If I have a texture in 24-bit RGB format and I want to treat a color as 'transparent alpha', say magenta (ff00ff), is there a way to load into GL as an RGBA texture with an alpha channel? Or must I pre-convert the image into an RGBA format and then load the texture?

McLeary
03-19-2011, 07:34 PM
I guess you need to "pre-convert". I don't know anything about using an arbitrary color as transparency.

PrestoChung
03-19-2011, 08:02 PM
Hmm I still get solid black pixels. I wonder do I need to handle this in the fragment shader?

If the color picked by the sampler2D() has an alpha value of 0.0, I suppose I must somehow blend with what is already there in the front buffer?

Right now my basic fragment shader looks like:

#version 330

uniform sampler2D tex;

in vec2 texPos;
in vec3 fragPos;

out vec4 outFragColor;

void main()
{
vec4 tex_color;
tex_color = texture2D(tex, texPos);

outFragColor = tex_color;
}

Do I A) need to create my own framebuffer to do so?
or B) can somehow blend with the default buffer?

Right now it is very simple I am trying to draw bitmap font glyphs on the screen, obviously with transparency around the actual glyph itself.

Alfonse Reinheart
03-19-2011, 08:17 PM
Try this. (http://www.opengl.org/wiki/Blending)

PrestoChung
03-19-2011, 08:33 PM
Oh goodie :) I thought it might have been deprecated for some reason.

I added two lines to my GL init function and it works fine now.

glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );