To Bezier or Not To Bezier?

Member
Posts: 321
Joined: 2004.10
Post: #1
Right now I create curves in Illustrator by drawing the curve and then adding anchor points (think vertices) to the curves. I then tell Illustrator to treat all lines between vertices as “straight” So my curves are actually approximated with lots of straight line segments. I then save off the file as SVG and read it into My openGL program which then draws these “curves” (via CallLists) by just drawing a whole lot of tiny straight lines.

Is this an adequate technique? Or do real OpenGL coders draw Bezier curves using evaluators (or NURBS or whatever)?

Thanks
Quote this message in a reply
Oldtimer
Posts: 832
Joined: 2002.09
Post: #2
Depends on what you're going to do with them. If you intend to have a boatload of Beziers, then I'd suggest the line approximations, but give it a shot and see what kind of performance you get. Smile
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #3
Technically when postscript rasterizes curves it uses your "lots of tiny lines" technique. Had problems with this on postscript devices for years, usually out of photoshop with the paths tool where there is a flatness setting.

I don't see a problem with the lots of straight lines, unless you are using it for movement along paths and find lots of jitteriness.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
That's not entirely true either. There are algorithms that draw pixel perfect bezier curves by finding all pixels touched by the curve.

OpenGL doesn't have a bezier primitive though, so you don't have much choice. You can break it into segments yourself, or let OpenGL do it for you. The latter would probably do it faster, but caching the results into a display list is still a good idea.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 41
Joined: 2006.01
Post: #5
There are no hardware accelerated curves. Sadly, even line segments are drawn in software on my old computer (G4 cube).
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #6
Skorche Wrote:OpenGL doesn't have a bezier primitive though, so you don't have much choice. You can break it into segments yourself, or let OpenGL do it for you. The latter would probably do it faster, but caching the results into a display list is still a good idea.
Nonsense. Lerp is plenty easy to code by hand (and get fast results) for bezier curves.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
What exactly does linear interpolation have to do with drawing bezier curves faster?

I just meant that if OpenGL could do it for you, it is probably fairly well optimized and faster than code you could easily write to do it yourself. Not that 2D bezier curves are difficult or computationally intensive though.

Perhaps I shouldn't have said anything though. Can OpenGL split 2D bezier curves for you anyway? I never bothered to read the chapters of the Red Book that deals with tessellations, evaluators or NURBS. It seems simple enough that they just might not bother.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #8
Skorche Wrote:What exactly does linear interpolation have to do with drawing bezier curves faster?

I just meant that if OpenGL could do it for you, it is probably fairly well optimized and faster than code you could easily write to do it yourself. Not that 2D bezier curves are difficult or computationally intensive though.

Perhaps I shouldn't have said anything though. Can OpenGL split 2D bezier curves for you anyway? I never bothered to read the chapters of the Red Book that deals with tessellations, evaluators or NURBS. It seems simple enough that they just might not bother.
Lerp allows you to dynamically change your LOD for curves.
1) Calculate endpoints and midpoint.
2) lerp between them.
3) Compare lerp'd point to actual point calculated on curve.
4) if differences is above an arbitrary detail threshold, subdivide and go back to step 2.

This way you can do fast approximations of curves and still get the detail results that you want.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 78
Joined: 2002.06
Post: #9
Just a few thoughts. I used Bézier curves in TracktorBeam to describe the landscape.

Saving the curves as Bezier paths and not lines, saves you disk space and loading time.
It let me tweak the curves by hand much more easily.
It means that you can do dynamic LOD, and if you change your mind later it doesn't matter.
I used Apple's NSBezierPath to linearise the curves to lines to draw as polygons in OpenGL This makes life a bit simpler.

Here's bits of the code I use in TracktorBeam:
Code:
[landscape setFlatness:5];
landscape = [landscape bezierPathByFlatteningPath];
[landscape retain];

...

NSPoint p[3];
int i, count = [path elementCount];
for(i=0;i<count;i++)
{
    NSBezierPathElement type = [path elementAtIndex:i associatedPoints:p];
    glVertex3f(p[0].x, p[0].y, 1);
}
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #10
kelvin Wrote:Lerp allows you to dynamically change your LOD for curves.
1) Calculate endpoints and midpoint.
2) lerp between them.
3) Compare lerp'd point to actual point calculated on curve.
4) if differences is above an arbitrary detail threshold, subdivide and go back to step 2.

Are you describing this? From what that is saying, it will get you a good curve approximation with few points, but generating it that way looks really expensive.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #11
Skorche Wrote:Are you describing this? From what that is saying, it will get you a good curve approximation with few points, but generating it that way looks really expensive.
No, seriously, it's not.

In the example you site, to get the same LOD with uniform division, you need ~27 times as many points. Even if calculating your points with adaptive subdivision takes 5 times as long for each point, it's still over 5 times faster.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
kelvin Wrote:No, seriously, it's not.

In the example you site, to get the same LOD with uniform division, you need ~27 times as many points. Even if calculating your points with adaptive subdivision takes 5 times as long for each point, it's still over 5 times faster.

I guess that makes sense.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply