gl.lineWidth(15); gl.startLineLoop(); for (int i = 0; i < 360; i++) { float degInRad = (float)Math.toRadians(i); gl.vertex((float)Math.cos(degInRad)*r, (float)Math.sin(degInRad)*r); } gl.end();

**0**

# OpenGL circle problems

Started by Whackjack, May 01 2007 05:31 AM

3 replies to this topic

###
#1
Members - Reputation: **100**

Posted 01 May 2007 - 05:31 AM

I have found many examples of drawing circles with OpenGL. However, I have not seen one that attempts to drawn one with a line width > 1. In my very-alpha SVG implementation, I need to allow for a stroke-width of an arbitrary size. Unfortunately, when the width gets to be greater than 5, small notches start to appear in the circle. Specifically, they appear at 45 degree angles to the horizontal and vertical.
I'm actually doing this in Java/LWJGL for FengGUI, but the code should be clear enough to decipher what the equivalent OpenGL commands are:
Now, I do know that cos(45 degrees) == sin(45 degrees). So, it appears that there won't be a line drawn at these locations. Has anyone ever run into this problem and how did you work around it?
Also, I tried to render the circle with points instead of a line loop, but the circle starts to take on a square shape after it gets so large.

Sponsor:

###
#4
Members - Reputation: **100**

Posted 02 May 2007 - 03:42 AM

Quote:

Original post by zedz

use a quad strip

for (int i = 0; i < 360; i+=10)

{

glVertex2f( sin(i*DEG2RAD) * outer_dist, cos(i*DEG2RAD) * outer_dist );

glVertex2f( sin(i*DEG2RAD) * inner_dist, cos(i*DEG2RAD) * inner__dist );

}

Most excellent. This is by far the fastest and simplest implementation I've seen/tried so far. Thanks!