Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Miglu

macrumors member
Original poster
Jan 22, 2010
74
0
There are two problems with this code to draw a circle.

Code:
glBegin(GL_POLYGON);
	{
	for(i=0;i<100;i++)
	{
		cosine=cos(i*2*PI/100.0);
		sine=sin(i*2*PI/100.0);
		glVertex2f(cosine,sine);
	}
	}
		glEnd();
One is that it is rendered in the center of the view even though I have glViewport(0, 0, size.width, size.height); earlier, so the origin should be in 0, 0. The second is how to control the diameter of the circle, as it is is automatically the view's width (and height, if the view's aspect ratio is not 1/1, so that it is an oval). I am not sure if this is a good way to draw a circle in OpenGL. How to solve these problems?
 

ncl

macrumors member
Aug 16, 2008
58
0
Use glOrtho, e.g.:
Code:
glOrtho(0, width, 0, height, -1, 1);
As for the best way to draw a circle, that depends on the type of application.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.