[Solved] Draw An Arc In opengl [closed]


Not necessarily the best way, but if you just need to get something working, you can modify your circle code slightly. Add a float arc_length parameter to the function signature. Replace 2.0f * 3.1415926f with arc_length. If you need to start the arc at a given offset, you can add another parameter called float arc_start. Then add arc_start to theta in each iteration of your for loop.

Edit based on Saman’s comments:

What you actually want is not an arc, but a more general representation of a curve. An arc is a kind of curve, but it’s a very particular kind–i.e. one with a constant radius. It sounds like you want to draw arbitrary curves, potentially with varying radii. If so, then my recommendation is Bezier curves. Here is a pretty solid introduction:

http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/

Note the part later in the tutorial about drawing them, where the author says “the simplest approach is to use small increments of t to calculate successive points.” This is pretty much what you have to do in order to draw a Bezier curve in OpenGL. Pick a value of t, and increment it in a for loop, just like you did with theta in your original circle code. For each iteration, draw a point.

6

solved Draw An Arc In opengl [closed]