• Create Account

# jgg

Member Since 03 Sep 2011
Offline Last Active Sep 10 2011 07:34 AM

### Color transparency misunderstanding

03 September 2011 - 03:44 AM

Hi there,

I'm new to OpenGL and I'm reading the NeHe's OpenGL tutorials which seem pretty easy to follow and very instructive. I have just read lesson 9, "Moving bitmaps in 3D space", and there is one thing I don't understand.

The program draws some stars which are defined with a specific color. Additionally, you can make them twinkle by pressing the 'T' key. Then, the colors of two different stars are mixed. What I don't understand is how these two colors can be mixed as they are defined for the star texture. I mean, when applied the colors for the two stars to be drawn, the two of them are defined with an alpha value of 255 (1.0f) (check the code below), which means the color should be opaque. So, if they are meant to be opaque, how can they be mixed? Should not the last star to be drawn overlapping the previous one?

Any help would be really appreciated.

Thank you.

```...

if (twinkle)
{
glColor4ub(star[(num-loop)-1].r,star[(num-loop)-1].g,star[(num-loop)-1].b,255);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
}

glRotatef(spin,0.0f,0.0f,1.0f);
glColor4ub(star[loop].r,star[loop].g,star[loop].b,255);