GL/GLUT texture alpha problem

Nibbie
Posts: 1
Joined: 2010.11
Post: #1
I am having a problem with my alpha in my textures. It was a bit more screwey than this, but I messed around a bit and this is what my textures look like where they should be transparent:
[Image: problem2.gif]
I know that the alpha in the textures works because earlier when I had a different problem (http://www.staronesw.com/temp/problem.gif) the stars in the background came through. My GL stuff is set up like this:
Code:
glEnable (GL_LINE_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.0f);
    glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
    glEnable(GL_DEPTH_TEST);
and my reshape function is:
Code:
void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1024, 0, 768, -1024, 1024);
    gluPerspective(45, width/height, 1024, 1024);
    glMatrixMode(GL_MODELVIEW);
    
}

Has anyone had a problem with semi non-functional alpha before? This is strange because although the alpha works(the cutout around the shapes), it doesn't blend at all.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Judging by the screenshot, it looks like you're drawing things in the wrong order. In order for alpha blending to work correctly, you have to draw the objects in the scene in order of backmost to frontmost, relative to the viewer.

Alex Diener
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
I'm pretty sure you don't want to enable the alpha test. I've never actually used it. But I think that it's used as a threshold for the alpha. Try disabling that.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #4
Alpha test basically says: if this condition is met, don't draw a pixel. The reason why you can see thru fully transparent areas but without blending on the edges is that the edges (and the inside) are drawn before the background, and the depth buffer too, so when you want to draw something behind it, the depth buffer will filter it because it is behind!

So, yes, leave alpha test enabled (for performance reasons), leave blending enabled AND draw using the painter's algorithm (far to nearest).
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Alpha Channel Problem Moganza 1 3,067 Jan 19, 2013 08:25 AM
Last Post: sealfin
  Texture coordinate problem Oddity007 0 2,016 Jan 21, 2009 06:20 PM
Last Post: Oddity007
  Alpha Masking Problem bonanza 5 3,775 Jun 29, 2008 11:58 AM
Last Post: maximile
  Pasting an image with alpha mask on a texture Najdorf 10 5,870 Jun 24, 2008 03:23 PM
Last Post: Najdorf
  Porting SDL to Cocoa OpenGL view--texture problem smittyz 7 5,141 Jul 21, 2007 07:53 PM
Last Post: smittyz