This topic is now archived and is closed to further replies.


Problem with Alpha channels in TGA files

Recommended Posts

Hey guys, i have made my own custom font (TGA with alpha channel) on white background, but it does not show up correct (that is, the alpha channel is taken, but with a little bit of background round the alpha channel). My guess is because the texture is resized, and i don''t have a correct initialization. This is my init routine:
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);						// Black Background

	glClearDepth(1.0f);											// Depth Buffer Setup

	glDepthFunc(GL_LEQUAL);										// Type Of Depth Testing

	glEnable(GL_DEPTH_TEST);									// Enable Depth Testing

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);			// Enable Alpha Blending (disable alpha testing)

	glEnable(GL_BLEND);											// Enable Blending       (disable alpha testing)

	//glAlphaFunc(GL_GREATER,0.1f);								// Set Alpha Testing     (disable blending)

	//glEnable(GL_ALPHA_TEST);									// Enable Alpha Testing  (disable blending)

	glEnable(GL_TEXTURE_2D);									// Enable Texture Mapping

	glEnable(GL_CULL_FACE);										// Remove Back Face


Share this post

Link to post
Share on other sites
Assuming that your font is to be solid-color, your color channels should amount to all white (everywhere, if I didn''t make that clear). The alpha channel should be the only channel to contain any value variance--to define the font.

Share this post

Link to post
Share on other sites
The trick is that OpenGL interpolates the colors between the pixels on your font texture. This also means the alpha value. That''s why blending doesn''t work very well and you get edges around your font.

What you could do is draw the font without blending but with alpha testing enabled using glAlphaFunc(GL_EQUAL, 1.0f);

Now, only stuff with an alpha of 1.0f (meaning your font) gets drawn. All other stuff is dropped by the GPU.

- An eye for an eye will make the world go blind -

Share this post

Link to post
Share on other sites