views:

782

answers:

2

Hey everyone,

I am starting to use opengl and I wanted to try alpha transparency. Here's my code:

void display(void);

int main(int argc, char** argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable( GL_BLEND );
    glutInitWindowSize(600,600);
    glutInitWindowPosition(200,50);
    glutCreateWindow("glut test");
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

void display()
{

    glClear(GL_COLOR_BUFFER_BIT);
    glPointSize(8);
    glBegin(GL_POINTS);
    glColor4f(.23,.78,.32,1.0);
    glVertex2f(0,0);
    glColor4f(.23,.78,.32,0.1);
    glVertex2f(0.1,0);
    glEnd();
    glFlush();
}

The problem is that these two points appear identical (even when I set the alpha to 0). Is there something I missed to enable alpha transparency? Thank you

+4  A: 

have you glEnable'd alpha blending? And have you set up your blend parameters? You can't just set the alpha you need to setup various other parameters in OpenGL.

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
Goz
OpenGL requires most everything to be enabled. A good place to start looking. (Disabling and enabling different operations at different times can lead to the most interesting effects.)
pst
Thanks, I added them, but I forgot to set the background color
HH
+1  A: 

Just a guess, but could it be that you dont have a background color ? So, when your rendering the second vertex which has alpha 0.1, there is no background to compute the proper color ? Just a guess, been years since i used opengl.

Andrew Keith
Yep, this was it. I should've added: `glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);glEnable( GL_BLEND ); glClearColor(0.0,0.0,0.0,0.0);` but only after glutCreateWindow()
HH