PDA

View Full Version : Alpha value in ClearColor



fweth
10-29-2011, 05:32 PM
Hi!

Somehow I am not able to use ClearColor with transparency while primitives make no problems in this context so far. Here is some example:


void display()
{
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0,1,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(20);
glColor4d(1,1,1,0.5);
glBegin(GL_POINTS);
glVertex2d(0,0);
glEnd();
glFlush();
}

In the main function I used


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

to enable transparency. Now this code yields a green window with an opaque white square. But the alpha value of the green ClearColor call is 0, so the window should stay red.

Thanks for help!

V-man
10-29-2011, 06:40 PM
No it shouldnt stay red. The function glClear sets the surface of GL to whatever you asked for. GL_BLEND has no effect on it.

fweth
10-30-2011, 03:41 AM
Thanks! But I am still a bit confused, in which situation can the alpha value of ClearColor be used then?

kyle_
10-30-2011, 07:28 AM
Its used. glClear *sets* all the contents of scissored area to specified color (lets ignore color masks for now). If you want to blend, draw a quad.

Something like this should be ok for you (assuming identity matrices & no depth test):


glClearColor(0,1,0,0);
glRectf(-1,-1,+1,+1);


Clear (at least logically) is something entirely different then drawing a quad.