Results 1 to 2 of 2

Thread: Drawing circle with c++

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    1

    Drawing circle with c++

    Hello,

    I want to try draw a circle with 2 mouse clicks, with first click on centre and the other click on anywhere on radius...how shld i go about it?

    i tried this..but doesnt reali work

    void drawCircle( float Radius, int numPoints )
    {
    glBegin( GL_LINE_STRIP );
    for( int i=0; i<numPoints; i++ )
    {
    float Angle = i * (2.0*PI/numPoints); // use 360 instead of 2.0*PI if
    float X = cos( Angle )*Radius; // you use d_cos and d_sin
    float Y = sin( Angle )*Radius;
    glVertex2f( X, Y );
    }
    glEnd();
    }

    anyone can guide me on how shld i do it

  2. #2
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: Drawing circle with c++

    The code for drawing the circle look correct (maybe you should use GL_LINE_LOOP), the problem must be somewhere else.
    How do you specify the projection?
    Are you using an orthographic projection or you need perspective?
    How do you specify the radius? and numPoints?

    Try this:
    Code :
    void render(){
      GLint viewport[4];
    //glGets are evil, use a variable to store the viewport when you resize the window
      glGetIntegerv(GL_VIEWPORT, static_cast<void*>(viewport));
      glMatrixMode(GL_PROJECTION);
      glOrtho(-viewport[1]*0.5, viewport[1]*0.5, -viewport[3]*0.5, viewport[3]*0.5, -1, 1);
      drawCircle(100.0f, 32);
      swapBuffers();
    }
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

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 a circle
    By openglNewbie in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-05-2005, 07:51 AM
  3. drawing a circle
    By fox in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-08-2001, 07:05 PM
  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