3

I know that there are algorithms of drawing line, circle, ellipse pixel by pixel (e.g. Bresenham's algorithms):

  1. http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
  2. http://en.wikipedia.org/wiki/Midpoint_circle_algorithm

I wonder why these algorithms (and I am sure that there are algorithms for drawing ellipsoid, sphere, cylinder in 3D) and not being used in OpenGL to draw corresponding primitives. Isn't it more simple and effective in terms of performance (which is very important in OpenGL) to have such primitives too instead of drawing a circle with lines, and sphere with triangles?

3
  • Simply because the graphics card doesn't usually understand these primitives. So the primitives have to be transformed to a representation which the graphics card understands (i.e. lines, triangles etc.) There are several such transformations, which is one reason why there is no implementation in OpenGL. Aug 23, 2014 at 15:06
  • @NicoSchertler if it was a good idea, the graphics cards will support them for sure. My point is that it is not a good idea, but I don't understand why.
    – Narek
    Aug 23, 2014 at 15:15
  • 3
    Ellipses and the like are completely different from lines, triangles etc. Thus, it would require additional hardware, which would only be used once in a while. Since all those primitives can be approximated sufficiently well with the existing primitives, this would be a waste of space and money. Furthermore, the algorithms you mentioned are iterative algorithms - not something the graphics card is particularly good at. No sure if there are parallel algorithms. Furthermore, interpolation would become a bit more complicated. All those things are better suited for the CPU. Aug 23, 2014 at 15:19

1 Answer 1

3

Who said OpenGL can't draw these shapes? There is no direct implementation of Bresenham and friends in the GPU core for the reasons Nico already explained.

However, since a couple of years GPU are fully programmable and therefore you can render almost anything you like. Including circles, ellipses and related primitives. You just have to write a shader program to do so :-)

Here is a little tutorial which shows you how it's done: http://www.geeks3d.com/20130705/shader-library-circle-disc-fake-sphere-in-glsl-opengl-glslhacker/

2
  • great. But why they are not integrated in the list of primitives like line, triangle, triangle fan, triangle stripes, quads and so on.
    – Narek
    Aug 23, 2014 at 19:25
  • @Narek: Becaue each kind of primitive requires additional silicon area, but more importantly connections to other parts of the GPU which just complicates things. Just program a shader doing what you want. This is just a cost/gain assessment and curved edges are a much more difficult to generalize problem than straight edges.
    – datenwolf
    Aug 23, 2014 at 23:36

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.