Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How 2 draw a circle

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2004
    Location
    Malaysia
    Posts
    3

    How 2 draw a circle

    Hello,
    I am doing my project now...wat i need 2 do now is wanna drawing a simple circle.....who can tell me how should i draw a circle with a GL_LINE_LOOP or GL_POLYGON...??

    Thank you.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: How 2 draw a circle

    Hi !

    With GL_LINE_LOOP you will get a circle, with GL_POLYGON you break down the "circle" into triangles, so if you just want a circle, use GL_LINE_LOOP if you intend to fill it with color or texture then use GL_POLYGON (a disk).

    Mikael

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    656

    Re: How 2 draw a circle

    play with this:

    Code :
    GLfloat r = 1.;
     
    glBegin(GL_LINE_LOOP);
     
    for(float phi = 0; phi <= 2*M_PI; phi += M_PI/10.)
      glVertex3f(r*cos(phi), r*sin(phi), 0.);
     
    glEnd();

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    china
    Posts
    3

    Re: How 2 draw a circle

    Originally posted by GreetingsFromMunich:
    play with this:

    Code :
    GLfloat r = 1.;
     
    glBegin(GL_LINE_LOOP);
     
    for(float phi = 0; phi <= 2*M_PI; phi += M_PI/10.)
      glVertex3f(r*cos(phi), r*sin(phi), 0.);
     
    glEnd();
    hello,I am also a beginner,I am thinking if do like that,would i gain a circle not filled?
    3Q
    I am only a VC beginner

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: How 2 draw a circle

    Yes, you will get lines, that's the idea with GL_LINE_LOOP, if you replace GL_LINE_LOOP with GL_POLYGON you will get a filled circle instead (if you have setup the correct polygon mode).

    Mikael

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    656

    Re: How 2 draw a circle

    for a filled circle i'd rather use a triangle fan than a polygon:

    Code :
    GLfloat r = 1.;
     
    glBegin(GL_TRIANGLE_FAN);
     
    glVertex3f(0., 0., 0.);
     
    for(float phi = 0; phi <= 2*M_PI; phi += M_PI/10.)
      glVertex3f(r*cos(phi), r*sin(phi), 0.);
     
    glEnd();
    the first vertex defines the center, the vertices in the for-loop lie on the perimeter

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    china
    Posts
    3

    Re: How 2 draw a circle

    Originally posted by mikael_aronsson:
    Yes, you will get lines, that's the idea with GL_LINE_LOOP, if you replace GL_LINE_LOOP with GL_POLYGON you will get a filled circle instead (if you have setup the correct polygon mode).

    Mikael
    Thank you very much
    I am only a VC beginner

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •