# Looking for Bezier curve OpenGL open source implemention [closed]

well in short im looking for something like this as open source.

i need to implement especially the Bezier curve editing in my app in open gl . any ideas where i can find such open source implementation ? ( can be c++ or java )

• "This video is not available." How about a screenshot or description? Do you just want to draw a bezier curve or want to move the points etc.? Also keep in mind that this site is more about "I've written this, it's not working, why?" It's not meant as a loose collection of links or suggestions/recommendations. – Mario Jan 2 '15 at 8:34
• the video does show on my browser .. i know what this site about , the problem is i dont have any starting point , i want to able to draw Bezier curve with handlers to change its curve . – user3689 Jan 2 '15 at 9:15
• You want to know how to draw a bezier curve or how to make an interactive graphic editor? Those should be two (or more) separate questions as making an editor is quite a complex task. – Stephane Hockenhull Jan 2 '15 at 16:33
• draw a bezier curve – user3689 Jan 3 '15 at 9:20

To draw a bezier curve using OpenGL or Direct3D you need to sub-divide the bezier into line segments. If you do this with enough sub-divisions it will look like a smooth curve.

Interpolation functions:

vec2 Lerp(vec2 a, vec2 b, float i) {
return a + (b - a) * i;
}

vec2 Bezier4(vec2 a, vec2 b, vec2 c, vec2 d, float i) {
return Lerp(Lerp(a, b, i), Lerp(c, d, i), i);
}


Then you generate a series of points on the bezier curve and draw connected lines between them:

vec2 bezier[4] = { bezier control points };

int resolution = 8;
vec2 points[resolution];

for(int n=0; n < resolution; ++n){
float i = (float)n / (float)(resolution-1);

points[n] = Bezier4(bezier[0], bezier[1] bezier[2] bezier[3], i);
}

DrawConnectLines(points, resolution);


You can increase the resolution to make the curve approximation smoother.