I want to draw using OpenGL library a Ring with sectors, each one with a different color.
To draw a ring i know i can use gluDisk(gluNewQuadric(), 0, 1.5, 32, 100);
But to draw the sectors or zones in different colors i think i need to use a manual way using GL_TRIANGLE_FAN or something similar.
I try it in that way, but the output is not so accurate to a ring.
const float DEG2RAD = 3.14159/180;
glBegin( GL_TRIANGLE_FAN );
for( int i = 0; i <= 90; i++ )
{
float degInRad = i*DEG2RAD;
glVertex2f(x, y); // point of the inner circle of the ring
for( int n = 0; n <= 4; n++ )
{
float const t = = i*DEG2RAD*(n/4);
glVertex2f(x + sin(t)*r, y + cos(t)*r); // points of the outer circle.
}
}
glEnd();
The idea was following this diagram of how GL_TRIANGLE_FAN works, take 4 points in the outer circle for each point calculated in the inner circle. Because the outer circle is longer than the inner circle. That’s the reason of a loop into another loop.

Your code references “inner circle” and “outer circle”, but all you have is a single center point (x,y), and your outer circle points will be all over the place as your angle calculation doesn’t make a lot of sense (you calculate one value in the outer loop, which isn’t used anywhere, and then just kind of multiply everything together in the inner loop, with a divide-by-4 for good measure… that’s not going to give you nice points in a circle).
In any event, you can’t use a single triangle fan to draw a ring, because all the triangles in the fan must connect to a single point. There’s no magic way to restart the fan at a different point, you just have to glEnd() and start a new one. This won’t work well for proceeding around a ring, as you’ll leave gaps. Triangle-fans are generally one of the least useful of the classic GL primitives.
I understand you’re trying to use less points in the smaller circle, but honestly I can’t see that it’s worthwhile.
Your best bet would be to use a triangle-strip instead, with a single loop around your circle, putting in both an inside and an outside vertex every time.
Pseudo-code for a segment: