There are two

Discussion in 'Mac Programming' started by Miglu, Aug 9, 2010.

  1. Miglu macrumors member

    Joined:
    Jan 22, 2010
    #1
    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?
     
  2. ncl macrumors member

    Joined:
    Aug 16, 2008
    #2
    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.
     
  3. Miglu thread starter macrumors member

    Joined:
    Jan 22, 2010
    #3
    Thanks. How to control the diameter of a circle?
     

Share This Page