5

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?

SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
  • 1
    even if there is a built in method for drawing circles I think you should still learn how to do it manually IMO – SemperAmbroscus Mar 20 '15 at 22:36
  • I'll be glad to know how to do it myself, but now I want to avoid bugs and tests and prefer to use something already tested and widely used – SomethingSomething Mar 20 '15 at 22:38
  • 1
    If you're not drawing points, lines, or triangles, you're using depreciated functionality. OpenGL is a low-level API meant for drawing stuff as fast as possible; convenience stuff like drawing basic primitives is intentionally left out (or removed) to slim down the API. I suggest you use the core profile ([fairly decent tutorial](https://open.gl/)) or using a higher-level framework. – Colonel Thirty Two Mar 20 '15 at 22:38

3 Answers3

2

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
1

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.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
  • I study a Computer Graphics course in the university and we use very old software - OpenGL with GLU and GLUT. I struggled to find a working binary of GLUT from ~2001. We draw lines and polygons with `glBegin()` and `glEnd()`... I hope it will help me also with newer technologies – SomethingSomething May 12 '15 at 13:29
0

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.

Ola
  • 68
  • 4
  • Thank you, it looks nice. If I also want to fill the circle, will it work if I use lines instead of points? – SomethingSomething Mar 20 '15 at 22:41
  • 1
    @SomethingSomething you should be using lines if you want lines (so the outline of the circle) or triangles if you want anything else. – user253751 Mar 20 '15 at 22:45
  • @immibis, thank you for your input. I've just started the a computer graphics course in the university, and currently we need only to paint simple shapes, so they just see that we succeed using somehow OpenGL. Still didn't get to the level of understanding these triangles practice – SomethingSomething Mar 20 '15 at 22:51
  • @SomethingSomething "simple shapes" A circle hardly qualifies as a simple shape in opengl IMO because it isn't as simple as drawing a triangle or square since a true circle has infinite sides – SemperAmbroscus Mar 20 '15 at 23:04
  • Use `GL_TRIANGLE_FAN` instead of `GL_LINE_LOOP` or `GL_LINES` as argument to the glBegin() function. – Ola Mar 20 '15 at 23:16