GL_TRIANGLE_FAN bug?

Started by SgtSparky, July 27, 2009, 18:32:16

Previous topic - Next topic

SgtSparky

Hello. This may be just not be the way OpenGL works, but I was trying to make each vertex I was drawing of a triangle fan a different color. It only seems to be able to let me change the color of the first vertex, then all the other vertices follow the color of the last vertex
Is this supposed to happen?

Ciardhubh

That's not supposed to happen. How are your drawing your triangle fan? When you call glColor, it sets the colour state in OpenGL to this colour. So everything you draw afterwards will be in this colour. To make every vertex another colour you have to call glColor before each vertex with the new colour.

For example, this works:
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
        {
            GL11.glColor3f(1.0f, 1.0f, 1.0f);
            GL11.glVertex2i(0, 0);
            GL11.glColor3f(1.0f, 0.0f, 1.0f);
            GL11.glVertex2i(200, 0);
            GL11.glVertex2i(200, 200); // same colour as last
            GL11.glColor3f(1.0f, 0.0f, 0.0f);
            GL11.glVertex2i(-200, 1000);
            GL11.glColor3f(0.0f, 0.0f, 1.0f);
            GL11.glVertex2i(-300, 50);
            GL11.glColor3f(0.0f, 1.0f, 0.0f);
            GL11.glVertex2i(-200, -100);
        }
GL11.glEnd();