I have scar textures and I want to get rid of the background skin colour by using alpha blending. However, I have problems with changing the opacity of individual pixels of specific textures. What is the easiest way to have textures with transparent background? I am using C++ and openGL.

I am using a BMP picture format and I am trying to map that scar texture onto the face but background colour of scar texture seems ugly on the face, so I want to remove that part and have only scar texture mapped onto the face. I also need to do this by using alpha blending. I know that I need to use blend function:


How I can change transparency for each texture?

  • 2
    You are going to have to be more specific if you want help. If you cannot describe your problems with words, you could always include a diagram of your results and a description of your expected results. But as it stands right now, this is mostly guess work. – Andon M. Coleman Mar 1 '14 at 22:12

It sounds like you want to remove backgrounds from sprites. If that's the case then use a program called gimp and then fuzzy select the background and delete then export it and close it but when it asks to save during export say no. Google gimp and background edit and you'll see the info and tools needed.

glBlendFunc (GL_ONE, GL_ONE); 

You might want to use the alpha values that result from texture mapping in the blend function. If so, (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) is always a good function to start with.

However, if you want blending to occur when the primitive is texture mapped (i.e., you want parts of the texture map to allow the underlying color of the primitive to show through), then don't use OpenGL blending. Instead, you'd use glTexEnv(), and set the texture environment mode to GL_BLEND. In this case, you'd want to leave the texture environment color to its default value of (0,0,0,0).

It would be easier to set the Color to (1,1,1,1) and use the default GL_MODULATE. Also You are only allowed to use certain commands between glBegin() and glEnd, so use only glTexCoord glColor glVertex and other similar commands. So use one glBegin()/glEnd() combo for the background, then change the settings and then use another glBegin()/glEnd() to draw the sprite.

  • Hey thanks for your answer. This is what I want but I am using BMP picture format and this format does not allow transparent background, so photo editing tools does not work in my case. Is there anyway to achieve this with alpha blending in openGL? – user3369407 Mar 2 '14 at 18:24

Your Answer

