bledning a specific colour from texture...

Started by
6 comments, last by ov3r_dr1v3 16 years, 4 months ago
Hey... I'm wondering if someone can help me with this problem. I've got a 2D layer which is rendered over a 3d scene. I've created a simple 2D square and applied a .tga texture to it. The texture is of a circle. What i want to do is kind of filter out the white color of the texture so it appear there a circle displayed. if anyone could help with this problem I'd appreciate it alot Thanks
Advertisement

Hey ^^;,

this process called ColorKey where u dicard a certain color of ur texture based on ur alpha map .

goolgle for it on this forums many ppl asked about it long time ago,

take care.
thanks for the reply, that helped me out alot. I've managed to identify the specific color( in this case white) and essentially blend it, but the problem I'm having now is blending it with the 3d scene, or whatever is stored in the frame buffer maybe.

what's happening at the moment is I've identified the white area, but because its not blending with the 3D scene behind it, the white areas just change to black.

I'm not sure if its how I'm blending or if I have to do something else as well...heres what im using in the blendfunc at the moment

glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);

I'd be grateful again of any help

Thanks!
A more common blending function is GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA; I suspect you'll have more success with it. Also, be sure to draw the opaque geometry before drawing anything with transparency, or else it won't have anything to blend with.

If that doesn't take care of things, toss up some code so we can take a look at exactly what's going on.
	glEnable(GL_BLEND);	        health_bar_texture.loadBMP("health_bar_full.bmp", 24);	health_bar_texture.convertToRGBA();	health_bar_texture.setAlphaForColour(0, 255, 255, 255);	glGenTextures(1, &health_bar_texture_space[0]);		glBindTexture(GL_TEXTURE_2D, health_bar_texture_space[0]);	glTexImage2D(GL_TEXTURE_2D, 0, 4, health_bar_texture.getWidth(),   health_bar_texture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, health_bar_texture.getData());	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D, health_bar_texture_space[0]);	glColor4f(1.0,1.0,1.0,1.0);	glBegin(GL_POLYGON);		glTexCoord2f(1.0f, 0.0f);glVertex2f(0.98,-0.98);		glTexCoord2f(1.0f, 1.0f); glVertex2f(0.98,-0.88);		glTexCoord2f(0.0f, 1.0f); glVertex2f(0.5,-0.88);		glTexCoord2f(0.0f, 0.0f); glVertex2f(0.5,-0.98);	glEnd();		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	glDisable(GL_TEXTURE_2D);	glDisable(GL_BLEND);



health_bar_texture is a bitmap object, which i then convert from RGB to RGBA, and set all values of white(255, 255, 255) to a transarency of 0.

here's what I'm getting at the moment...

description of your image



http://img412.imageshack.us/img412/2682/transarencyproblemzm4.png
You'll want to set the blend function before rendering anything with blending.

There's no need to generate the texture every frame, you can do it once and store the result in a texture object, binding it as needed. Also, does the debugger agree that the texture has been converted correctly? Checking the first four elements of the texture should be enough, since the edges should all be transparent.
I'm losing my mind, sorry. You'll want to look into alpha testing.
thanks buddy, was exactly what I was looking for works a treat.

thanks!

This topic is closed to new replies.

Advertisement