About textures and transparency...
Didn't know where to put this but anyways...
I want to load a texture, say a ball and the area around the ball should be transparent. I make an image in Photoshop with transparent background and save it as a 32 bit TGA.
Now i load it in my OpenGL program and it has always worked wonders.
Yesterday i was going to do this again in some project but i can't for the world get it to work.
I have tried using the Simple OpenGL Image Library (SOIL) but can't get it to work. I also tried GLFWs (the window lib thingie im using) own Tex loading function but can't get it to work either.
The only thing different from last time when i got it to work is that i was using SDL.
I figure GLFWs the problem, but how? I open the window with alpha blending and stuff enabled but it just doesn't want to work.
Any help on this would be very much appreciated. Thanks.
Take a look at GL_BLEND.
You need to background your images with a 'transparency colour' (I use 254, 0, 254), enable GL_BLEND then set the glColor to your transparency colour, then render. Any part of the image that is the blend colour, it won't be shown.
I use it for my font rendering.
You need to background your images with a 'transparency colour' (I use 254, 0, 254), enable GL_BLEND then set the glColor to your transparency colour, then render. Any part of the image that is the blend colour, it won't be shown.
I use it for my font rendering.
Do you mean like enabling Blending in OpenGL and then using something like
glColor4f(r, g, b, a); ?
EDIT: Oh nevermind, thanks for your help ^^
glColor4f(r, g, b, a); ?
EDIT: Oh nevermind, thanks for your help ^^
Hmm.. I can't get this to work.
I make a picture and set the background color to (254, 254, 254) and then draw something and save it as a jpeg (does filetype matter in this case?).
I load it in my program and:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
glColor3ub(254, 254, 254);
//I tried 4ub with 255 and 0 as the alpha channel with no luck.
glBegin(GL_QUADS);
...
glEnd();
glDisable(GL_TEXTURE_2D);
Now... what am i doing wrong? I have tried changing the blendfunc but i still can't get it to work.
I make a picture and set the background color to (254, 254, 254) and then draw something and save it as a jpeg (does filetype matter in this case?).
I load it in my program and:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
glColor3ub(254, 254, 254);
//I tried 4ub with 255 and 0 as the alpha channel with no luck.
glBegin(GL_QUADS);
...
glEnd();
glDisable(GL_TEXTURE_2D);
Now... what am i doing wrong? I have tried changing the blendfunc but i still can't get it to work.
Jpegs do not have an alpha channel, so you need a fileformat that supports alpha channel like png. Or you can set each pixel of a certain color to be transparent. The first option is probably simpler.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement