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 3 of 3

Thread: Drawing a circle

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    2

    Drawing a circle

    I am attempting to draw a circle using the gl_Triangle_Fan. Here is what I have thus far:

    Code :
    int i;
    	int triangles = 20; // number of triangles
     
    	float twoPi = 2.0f * 3.14159f;
     
    	glBegin(GL_TRIANGLE_FAN);
     
    	glVertex2f(my_x,my_y); // origin
     
    	for(i = 0; i <= triangles; i++) { 
     
    		glVertex2f((radius * cos(i *  twoPi / triangles)), 
    				   (radius * sin(i * twoPi / triangles)));
    	}
     
    	glEnd();

    my_x and my_y are the positions of the mouse.

    When the program begins, there is a semicircle in the bottom left-hand corner of the screen, but when I click a new location, the circle becomes a massive line that enfulges the screen. Any help would be greatly appreciated

  2. #2
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    556

    Re: Drawing a circle

    The whys and wherefores of what happens when you click your mouse can't really be determined from the code you've posted. I suspect it's something to do with the GLUT screen refresh as it sounds like that kind of problem.

    Try this web page for what you want :
    http://en.wikibooks.org/wiki/OpenGL_...sics/2DObjects

  3. #3
    Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    352

    Re: Drawing a circle

    Quote Originally Posted by onorinbejasus
    Code :
    const unsigned int triangles = 20; // number of triangles
    const float twoPi = 2.0f * 3.14159f;
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(my_x,my_y); // origin
    float delta = twoPi / triangles;
    for(unsigned int i = 0; i <= triangles; i++)
      glVertex2f(my_x+(radius * cos(i *  delta)),
         my_y+(radius * sin(i * delta)));
    glEnd();
    you move the center but you are not moving the other points.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

Posting Permissions

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