|
-
Jul 2nd, 2006, 01:17 AM
#1
Thread Starter
Lively Member
How to draw an approximate circle in OpenGL?
Hi,
I am doing an exercise from the book "Beginning OpenGL Game Programming" by Dave Astle and Kevin Hawkins.
The question asked to write a function to draw a 2D circle approximation. The origin starts at 0,0,0. The function has to accept the radius and the number of edges.
Below is how I wrote the function. But when I ran it, there's only a straight white line appearing across the window, instead of an approximate circle.
void DrawCircleApproximation(float radius, int numberOfSides, bool edgeOnly)
{
int i;
double angle;
if(edgeOnly)
glBegin(GL_LINE_STRIP);
else
glBegin(GL_POLYGON);
for(i = 0;i < numberOfSides;i++)
{
angle = (i * 2 * 3.142) / numberOfSides;
glVertex3f(cosf(angle)*radius,0.0, sinf(angle)*radius);
}
if(edgeOnly)
glVertex3f(radius,0.0,0.0);
glEnd();
}
What is wrong with the code above? I've checked with the book's answer and they are similar.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|