Jump to content
  • Advertisement
Sign in to follow this  
cresty

About textures and transparency...

This topic is 3847 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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 ^^

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!