0

Actually I have in my project function which generate vertex data for drawing ring with specified minimum radius and maximum radius. In edge case (minimum radius equal 0) it is circle with solid fill. To draw my data I'm using GL_TRIANGLE_STRIP.

Now I want refactor my function in way, that will be possible prepare data to draw dashed circle (something like that http://www.andyhorner.com/wp-content/uploads/2012/04/dashedlines-24.jpg).

Also I want to stay with only one buffer for every circle, so I think I have to switch to drawing by GL_TRIANGLES. Do you have any advices what is the best approach to prepare vertex data to draw this kind of shapes?

Gie
  • 1,907
  • 2
  • 24
  • 49

1 Answers1

1

I would see two different approaches to draw a dashed circle:

  1. Prepare the exact geometry of the dashes (I believe that's what you had in mind) and render this geometry untextured with a solid color. In this case, your vertex buffer contains only position attributes. You can use a single triangle strip or triangles. When using a triangle strip, you will have to repeat the (index of the) last vertex of one dash and the (index of the) first vertex of the next one (this inserts degenerate triangles to fake a primitive restart). You may want to evaluate the size of the vertex and index buffers to decide between a single triangle strip or triangles (generally a single triangle strip wins). I am also assuming you are using indexed geometry (glDrawElements + index buffer).

  2. Prepare the geometry of the full circle, and then apply a semi-transparent 1D texture on it to render the dashes. Obviously you can keep using a single triangle strip. You won't need fake primitive restart, but you will still need to generate vertices at the dash boundaries. Your vertex buffer contains not only position attributes but also the corresponding 1D texture coordinates. And of course, you need to enable blending when rendering.

Both approaches are using a single draw call to render the whole dashed circle. The textured approach is more complex and slower. I would go for 1., the purely geometric approach, with a single triangle strip.

user3146587
  • 4,250
  • 1
  • 16
  • 25