PDA

View Full Version : [glClearColor]: fourth parameter ... what is alpha?



11-27-2003, 09:08 AM
Hello to all!
Forgive my bad english, but i'm italian (are there any italian?) and don't speak very well this language.

I'm try to learn opengl programming, trought the RedBook.
This is the first example of the book:



#include <whateverYouNeed.h>

main() {

OpenAWindowPlease();

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();

KeepTheWindowOnTheScreenForAWhile();
}

These two lines:

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);

set the background to black (so i've intended).

This:

glClearColor(0.0, 0.0, 0.0, 0.0);

set the color to black.

glClearColor take 4 parameters; but Rgb colors need only 3 paramters (red, green, blue). Why?

On the blue book there is written:


C SPECIFICATION

void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )

So what is Alpha?

11-27-2003, 10:10 AM
ok, i've solved in irc (channel opengl). The fourth parameter indicates the trasparency.

11-27-2003, 10:36 AM
The alpha is opacity, not transparency. This means that when it is 0, you can't see it at all. When it is 1, you can see it completely. When it is 0.5f, you can see it at half intensity.

Bob
11-27-2003, 11:18 AM
Originally posted by while(fork()):
The alpha is opacity, not transparency. This means that when it is 0, you can't see it at all. When it is 1, you can see it completely. When it is 0.5f, you can see it at half intensity.
That is just a matter of choosing a suitable blending function. You can make it act as transparency as easy as opacity.

The alpha channel is just a fourth color component that can be used for different things. Opacity and transparency are just two things. You can use it for light maps too, for example.

john
11-27-2003, 04:06 PM
My 5c worth:

alpha represents (/indicates) how much light a fragment contributes to a pixel. It's not just a matter of transparency because even pixels belonging to completely opaque objects can have fractional alpha along the edges for anti-aliasing purposes.

A pixel represents an area sample of a continuous 2D light-field. The RGB component indicates the average colour of sampling over that area, and the alpha represents how much of that area actually had colour that contributed to that sample. Sure, it can be used to mimmick transparency but... alpha is more subtle than that, I think.