I've tried to write a proper function for drawing a 2D disk on the screen with OpenGL for a few days now, and I simply can't seem to get it right :(
This is my current code:
void Disk( Float x, Float y, Float r, const Color& vColor )
{
glBegin( GL_TRIANGLE_FAN );
glVertex2f( x, y );
for( Float i = 0; i <= 2 * PI + 0.1; i += 0.1 )
{
glVertex2f( x + sin( i ) * r, y + cos( i ) * r );
}
glEnd();
}
When zooming in, the resulting disk shows spikes, not as in edges but really spikes pointing out.
Also the function doesn't draw one disk only, but always a bit more than one - which means that if alpha is enabled, the results look wrong.
void circle(float x, float y, float r, int segments)
{
glBegin( GL_TRIANGLE_FAN );
glVertex2f(x, y);
for( int n = 0; n <= segments; ++n ) {
float const t = 2 * M_PI * (float)n / (float)segments;
glVertex2f(x + sin(t) * r, y + cos(t) * r);
}
glEnd();
}
that should get you rid of the overdraw. About the spikes... a picture could tell a thousand words.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With