Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glColor4f() - effect of alpha value

I am using glColor4f(). Surprisingly, changing the alpha, i.e., the fourth argument doesn't cause any change in transparency. The code segment is:

const GLfloat squareVertices[] = { 
0.5, 0.5, 0.0, 
-0.5, 0.5, 0.0, 
0.5, -0.5, 0.0,
-0.5, -0.5, 0.0}; 

glEnableClientState (GL_VERTEX_ARRAY);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor4f (1.0, 0.0, 0.0, 0.5);
glLoadIdentity ();       
glTranslatef(0, 0, -5);
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Any pointers to where I could be going wrong?

like image 378
Iceman Avatar asked Apr 16 '12 21:04

Iceman


1 Answers

You need to enable blending if you want to use transparency:

glEnable(GL_BLEND);

See also glBlendFunc to setup the blending function.

like image 78
Tim Avatar answered Oct 06 '22 21:10

Tim