SomethingSomething
SomethingSomething

Reputation: 12178

OpenGL / GLU : Is there a built-in function for drawing circles?

I know that there are built-in functions for drawing rectangles (glRecti() for instance), and thought that a circle is also a pretty basic usage.

Is there such a built-in function for drawing circles? Or should I always implement it myself?

Upvotes: 5

Views: 5934

Answers (3)

Ola
Ola

Reputation: 68

No, there isn't a built-in openGL function...Read this to get you started in writing your own drawCircle function:

http://www.openglprojects.in/2014/03/draw-circle-opengl.html

===Edit====

GLU is deprecated and completely unsupported. So I won't even suggest a built-in function for such library.

Upvotes: 0

Reto Koradi
Reto Koradi

Reputation: 54592

If you're comfortable using GLU (which is deprecated as a whole), then yes, there is. gluDisk() renders a filled circle by default, but can also be used to render just a circle outline:

GLUquadric quad = gluNewQuadric();
...
gluQuadricDrawStyle(quad, GLU_SILHOUETTE);
gluDisk(quad, 0.0, radius, 64, 1);
...
gluDeleteQuadric(quad);

The above code is untested.

Upvotes: 1

genpfault
genpfault

Reputation: 52083

gluDisk() can be used to do so:

void gluDisk(GLUquadricObj *obj,
             GLdouble innerRadius, GLdouble outerRadius,
             GLint slices, GLint loops)

innerRadius and outerRadius control the size of the hole and disk.

Set innerRadius to 0.0 to render a solid circle.
slices: number of sides to disk (eg. 3 for equilateral triangle, 6 for a washer 20 for a circle).
loops: number of concentric rings rendered eg. 1 for circles 2 for washers. Using larger values for loops improves specular lighting and the effect of spotlights.

Official manpage.

Upvotes: 2

Related Questions