Results 1 to 6 of 6

Thread: drawing a smooth circle

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    9

    drawing a smooth circle

    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

  2. #2
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: drawing a smooth circle

    Something like this..

    Code :
    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)*radius);
       }
     
       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.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: drawing a smooth circle

    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.

  4. #4
    Senior Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    346

    Re: drawing a smooth circle

    And if you want it to be really really smooth, check out GL_LINE_SMOOTH (hint: enable blending).

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    9

    Re: drawing a smooth circle

    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();

  6. #6
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: drawing a smooth circle

    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.

Similar Threads

  1. Drawing a circle
    By imported_onorinbejasus in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-20-2010, 04:01 AM
  2. Drawing circle with c++
    By satekazumi in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-01-2009, 06:37 AM
  3. drawing a circle
    By openglNewbie in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-05-2005, 07:51 AM
  4. drawing circle
    By prabhat in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-25-2000, 09:36 AM
  5. drawing a circle
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-21-2000, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean