• Create Account

# drawing a 2D torus (basically a circle with a hole in it).

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Enerjak  Members   -  Reputation: 277

Like
0Likes
Like

Posted 17 March 2013 - 12:15 AM

I've been trying to render a torus (in 2D) in OpenGL and Well, I think I'm on the right track but I thought I'd ask you how to go about getting it to work. here's the code:

// attempting to create a torus (in 2D)
int numSegments,
double x,
double y)
{
double mAngle = 0.0;
double mAngle2 = 0.0;
glBegin(GL_POLYGON);
for(int i = 0; i < numSegments; i++)
{
mAngle = i * (2 * 3.14/numSegments);
mAngle2 = i * (2 * 3.14/numSegments);
}

glEnd();
}


now here's the polygon this produces:

http://puu.sh/2j6uh

please let me know if there's anything I need to do to fix this.

### #2Dragonsoulj  Crossbones+   -  Reputation: 3165

Like
1Likes
Like

Posted 17 March 2013 - 05:55 AM

Looks like you are on the right track for the ring. Does increasing your number of segments give you a smoother looking ring?

### #3C0lumbo  Crossbones+   -  Reputation: 3960

Like
3Likes
Like

Posted 17 March 2013 - 06:49 AM

The shape you're trying to draw is not a convex polygon, so using GL_POLYGON is wrong. I think GL_TRIANGLE_STRIP is a better fit. In switching to a triangle strip you should change the 'for' condition to <=.

### #4Enerjak  Members   -  Reputation: 277

Like
1Likes
Like

Posted 17 March 2013 - 09:40 AM

thanks, I can always count on the fine people on this forum!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS