Public Group

# Circles and ellipses or curves in OpenGL

This topic is 4616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Maybe a silly question, but after reading some I still don't know how to go about it. For a simple throwaway gui and some basic shapes I would like to draw (parts of a) circle, ellipse or maybe even a curve...[dead] What would be a good way to go about it, in OpenGL? This is all in ortho mode, 2D. As I understand it, I can have these options: - compute coordinates myself and draw with a GL_TRIANGLE_FAN (or line strip, or polygon?). Which primitive should I use? How could I get this to look smooth? - use a texture (I don't want this actually, though texture mapping would be nice) - use evaluators or NURBS with glu (this is a bit complicated for me but I found some tutorials I could sort of follow) - use quadrics with glu I feel a bit stupid because of my total lack of math (dropped it in school), however I am trying to read up on it. Thanks.

##### Share on other sites
Curves are a 1D primitive and could be seen as a sequence of infinite many points. They could be approximated by straight line segments to overcome the infinite effort. To make it smooth one could look at the curvature of the curve and use shorter line segments where the curvature is higher. A "perfect" approximation is found if the error between any straight line segment and its belonging curve segment is less than a screen pixel (i.e. the displayed curve cannot become closer to its original due to screen resolution). In OpenGL this kind of job could be done well with a line strip, right you are.

Drawing a closed surface (a 2D primitive), e.g. bounded by an ellipse, could be done similarly. You could use tri fan, tri strip, or polygon for this purpose as long as the surface is convex. At least GL_POLYGON needs a tesselation of non-convex surfaces, but in general tri fan and tri strip need so, too. GLU provides a convenience function for drawing a flat concave polygon.

Quadratics and even NURBS could be used for a subset of possible surfaces. If you use them the tesselation is done behind the scenes.

[Edited by - haegarr on March 1, 2006 1:24:24 PM]

##### Share on other sites
ok cool. I didn't think of curves as a set of 1D primites, but that makes sense.

Is it true then that opengl draws everthing as triangles on the hardware side of things? I mean, would drawing a curve or circle 'manually' as a series of connected vertices amount to the same (kind of) thing 'internally' as using NURBS or evaluators?

##### Share on other sites
Your graphics card renders triangles, points, and lines. So yes, if you render something using GL_QUADS, it's going to be triangulated. The glu routines that compute complex shapes ultimately render with GL_QUADS or GL_POLYGON, which are triangulated and sent to the card.

##### Share on other sites
Use OpenGL's quadrics and evaluator functions where appropriate. If you want to learn to draw them using primitives (lines and/or tris), the key phrase for efficiency is "recursive subdivision."

##### Share on other sites
Quote:
 Original post by igni ferroqueUse OpenGL's quadrics and evaluator functions where appropriate. If you want to learn to draw them using primitives (lines and/or tris), the key phrase for efficiency is "recursive subdivision."

Ok thanks. I'm going to play around with this a bit, it will be good for my math knowledge.

You say quadrics and evaluators are preferable? (where appropriate) Is that because of the ease of use and don't-reinventing-the wheel reason, or efficiency, or perhaps both?

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 86
• 11
• 10
• ### Forum Statistics

• Total Topics
632971
• Total Posts
3009608
• ### Who's Online (See full list)

There are no registered users currently online

×