Vertex Colours
I new to opengl programming and attempting to write a simple asteroids game (yes I know!.. another one, but its a nice place to start).
Putting the problem as simply as possible. I have asteroids flying around the screen which can be shot by the player. They then break up into several fragments with each vertex being red, green or blue and a life_counter set to zero.
On each loop of the programme, I increment the life_count by 1.
When the life_count is over 1000 I begin reducing the vertex colours to fade the individual fragments to black. see the code below.
objects* fragment_link = first;
while (fragment_link != NULL)
{
fragment_link->life_count++;
if (fragment_link->life_count > 1000)
{
/* change colour for every vertex here */
for (count = 0; count < fragment_link->data.num_triangles; count++)
{
for (vert = 0; vert < 3; vert++)
{
r = fragment_link->data.triangles[count].vertex[vert].r;
if (r > 0.0f)
{
r = r - 0.001f;
fragment_link->data.triangles[count].vertex[vert].r = r;
}
g = fragment_link->data.triangles[count].vertex[vert].g;
if (g > 0.0f)
{
g = g - 0.001f;
fragment_link->data.triangles[count].vertex[vert].g = g;
}
b = fragment_link->data.triangles[count].vertex[vert].b;
if (b > 0.0f)
{
b = b - 0.001f;
fragment_link->data.triangles[count].vertex[vert].b = b;
}
}
}
}
if (fragment_link->life_count > 1400)
/* at the end of each loop all objects where bAlive = false are destroyed */
fragment_link->bAlive = false;
fragment_link = fragment_link->next;
}
However, when fragments currently are on the screen and fading (life_count > 1000) the vertex colours get reset to red, green and blue when I shoot another asteroid and new fragments are added to the list?
Not yet using any lighting or blending functions, just glColor3f(...) and glVertex3f(...)
Any ideas would be appreciated..
C_Z..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement