PDA

View Full Version : Texture and blending question



Radish
10-27-2003, 06:48 AM
I am attempting to create 2D sprites using textures on polygons in orthographic projection mode. Obviously this would require blending to make most of the texture and polygon invisible, leaving just the sprite to be drawn over whatever background.

So, I used glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and decal texturing mode. My texture wass a 32-bit TGA with an alpha channel painted on it randomly, just for testing purposes. When I tried it all out, the transparent parts of my texture had the color of the polygon they're drawn on showing through, rather than what's behind the polygon. I tried calling glColor4f(0.0,0.0,0.0,0.0) before drawing the textured polygon, but that just made the whole polygon invisible, texture and all. What's the problem, and how can I get what I want?

zeckensack
10-27-2003, 08:00 AM
Try

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

This will eliminate vertex colors. If you want to be able to still colorize textured objects, use

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);But then you'll have to watch the alpha channel when specifying colors. Ie instead of
glColor4ub(255,0,0,0);
use
glColor4ub(255,0,0,255);

[This message has been edited by zeckensack (edited 10-27-2003).]

Radish
10-27-2003, 08:30 AM
Thank you, sir. May you live long and have many cubs.