PDA

View Full Version : Drawing a circle



onorinbejasus
01-19-2010, 09:14 PM
I am attempting to draw a circle using the gl_Triangle_Fan. Here is what I have thus far:



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

scratt
01-20-2010, 01:04 AM
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_Programming/Basics/2DObjects

Rosario Leonardi
01-20-2010, 04:01 AM
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.