22

Circles are one of the basics geometric entities. Yet there is no primitives defined in OpenGL for this, like lines or polygons. Why so? It's a little annoying to include custom headers for this all the time!

Any specific reason to omit it?

2
  • Saying this depends on resolution May 30, 2010 at 15:58
  • 17
    So that we can ask people to write a circle function in technical interviews.
    – i_am_jorf
    May 30, 2010 at 15:59

4 Answers 4

25

While circles may be basic shapes they aren't as basic as points, lines or triangles when it comes to rasterisation. The first graphic cards with 3D acceleration were designed to do one thing very well, rasterise triangles (and lines and points because they were trivial to add). Adding any more complex shapes would have made the card a lot more expensive while adding only little functionality.

But there's another reason for not including circles/ellipses. They don't connect. You can't build a 3D model out of them and you can't connect triangles to them without adding gaps or overlapping parts. So for circles to be useful you also need other shapes like curves and other more advanced surfaces (e.g. NURBS). Circles alone are only useful as "big points" which can also be done with a quad and a circle shaped texture, or triangles.

If you are using "custom headers" for circles you should be aware that those probably create a triangle model that form your "circles".

2
  • can you explain what you meant by "Custom headers"?
    – Xavier Ho
    May 31, 2010 at 9:08
  • 3
    It's from the question. I don't know what exactly Ram meant by that but I guess it's a library with some OpenGL utility functions. May 31, 2010 at 9:36
2

Because historically, video cards have rendered points, lines, and triangles.

You calculate curves using short enough lines so the video card doesn't have to.

0
2

Because graphic cards operate on 3-dimensional points, lines and triangles. A circle requires curves or splines. It cannot be perfectly represented by a "normal" 3D primitive, only approximated as an N-gon (so it will look like a circle at a certain distance). If you want a circle, write the routine yourself (it isn't hard to do). Either draw it as an N-gon, or make a square (2 triangles) and cut a circle out of it it using fragment shader (you can get a perfect circle this way).

4
  • 1
    +1. To be pendantic, fragment shaders still only approximate the circle by the pixels on the screen. Not a perfect circle. =P
    – Xavier Ho
    May 31, 2010 at 9:09
  • @Xavier Ho: Still, with a fragment shader you'll get perfect approximation almost at any distance from circle (at very close distance there might be a precision errors). Throw a bit of antialiasing into calculation, and there will be nothing to complain about.
    – SigTerm
    May 31, 2010 at 12:30
  • "Perfect approximation" - I call oxymoron! And yes, you would be correct.
    – Xavier Ho
    May 31, 2010 at 12:33
  • @Xavier Ho: "I call oxymoron!" :) (explaining just in case) I meant to say that it will be still made from square pixels, but there will be no "straight"(non-curved) line segments or wasted vertices as with traditional N-gon circle approximation.
    – SigTerm
    May 31, 2010 at 13:02
-1

You could always use gluSphere (if a three-dimensional shape is what you're looking for).

If you want to draw a two-dimensional circle you're stuck with custom methods. I'd go with a triangle fan.

The primitives are called primitives for a reason :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.