Question

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:

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

How I can change transparency for each texture?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top