PDA

View Full Version : Drawing circle with c++



satekazumi
04-30-2009, 10:56 PM
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

Rosario Leonardi
05-01-2009, 05:37 AM
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:


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