PDA

View Full Version : drawing a smooth circle



swatkdw
07-03-2009, 10:20 AM
hi. I am new to openGL and would like to draw a smooth circle..
Can anyone hint me ?

Should I use gl.glBegin(GL.GL_LINE_STRIP) and some sine, cosin in it??

thanks

scratt
07-03-2009, 10:00 PM
Something like this..


const float DEG2RAD = 3.14159/180;

void drawCircle(float radius)
{
glBegin(GL_LINE_LOOP);

for (int i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f(cos(degInRad)*radius,sin(degInRad)*radi us);
}

glEnd();
}

Do remember that Google is your friend.. You could have found this with less typing and got a quicker answer with a Google search. :)

awhig
07-04-2009, 01:18 AM
Other solution can be to fake a circle by using gluDisk() and set parameters accordingly. i.e set inner radius equal to outer radius.

Another method can be to go for subdivision curves , midpoint , catmull clark if you want to go for higher precision.

Or you can draw it using NURBS.

You can not get a perfect circle though.

remdul
07-04-2009, 04:18 AM
And if you want it to be really really smooth, check out GL_LINE_SMOOTH (hint: enable blending).

swatkdw
07-05-2009, 02:39 PM
thank you very much .
I have done it.

gl.glBegin(GL.GL_LINE_LOOP);
for(int i =0; i <= 300; i++){
double angle = 2 * Math.PI * i / 300;
double x = Math.cos(angle);
double y = Math.sin(angle);
gl.glVertex2d(x,y);
}
gl.glEnd();

MarkS
07-05-2009, 05:03 PM
Check out this site: http://slabode.exofire.net/circle_draw.shtml

The code there draws circles and arcs without using sine or cosine and is very fast.