Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Need help with circles in OpenGL

This topic is 6210 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone help show me how to create 2D circles with either quads or triangles in 3D space with C++? If you can, I''d appreciate it.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
What you mean? Just get a texture of a circle, slap it on a quad, and done.

Share this post

Link to post
Share on other sites
I don''t mean creating a circle on a square surface.
I''m trying to make a circular lid to put on a 3D cylinder, and I''m to build a circle out of triangles or quad polygons.

Share this post

Link to post
Share on other sites
If you can make the sides, why can''t you make the cap?

You could use a triangle fan and do something like:

HEIGHT = cap height in Z
RADIUS = cylinder radius
SLICES = number of sections to divide cap into

float angle, section;

glVertex3f(0.0, 0.0, HEIGHT);

for (section=0;section{
angle = 2*M_PI*((SLICES-1)/section);
glVertex3f(cos(angle)*RADIUS, sin(angle)*RADIUS, HEIGHT);

Be advised: I just typed this in off the top of my head, so it may be anywhere for perfect to totally wrong.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
You can do it with simple high school trig. As you increment some angle theta from 0 to 360 degrees (or 0 to 2PI if radians) calculate X, Y coordinates as...

X = radius * cosine (theta)
Y = radius * sine (theta)

That gives you the values you are looking for. You can apply the coordinates to triangles or quads in a way that makes sense for your program.

Share this post

Link to post
Share on other sites
the easiest way (I think) would be to use GLUT.
*Reaches for OpenGL Game Programming Book*
you could do something like this:

[edit: source instead of code]

GLUquadricObj* myCircle;

myCircle = gluNewQuadric();

gluQuadricDrawStyle(myCircle, GLU_FILL);

gluQuadricNormals(myCircle, GLU_FLAT);
// or

gluQuadricNormals(myCircle, GLU_SMOOTH);

gluQuadricOrientation(myCircle, GLU_OUTSIDE);
// or

gluQuadricOrientation(myCircle, GLU_OUTSIDE);

gluQuadricTexture(myCircle, GL_TRUE);

gluDisk(myCircle, innerRadius, outerRadius, slices, loops);

Basically you create a GLUquadricObj and initialise it with gluNewQuadric(). Then set the draw style to flat (other options are GLU_LINES and GLU_POINT). Next you set the kind of shading, only use one of the above. Set the orientation, now that is basically the way it faces so try both to see which works best. finally gluQuadricTexture enables or disables texture co-ordinate generation and gluDisk creates the disk with these parameters:

myCircle:- the GLUquadricObj you spent ages setting up
innerRadius:- the disk has a hole, this is it's radius. Set 0 for no hole
outerRadius:- the disk's radius
slices:- the number of "slices", like a cake, it is divided into.
loops:- the number of rings that the disk is divided into

There you go. I hope that u don't mind using GLUT because I spent ages typing this reply!

Baldur K

"It will be happened; it shall be going to be happening; it will be was an event that could will have been taken place in the future."
--time travel explained by Rimmer (Red Dwarf)

"If you don't gosub a program loop, you'll never get a subroutine."
-- Kryten (Red Dwarf)

Edited by - baldurk on December 16, 2001 4:42:35 AM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!