Archive Pages Design$type=blogging

Drawing Bézier curves in Opengl C++

Bézier curves have important use in computer graphics thus we will learn Drawing Bézier curves in Opengl C++ in this post.

Curves in Computer graphics is one of the important topics to learn. Today we are going to learn about the about a special curve type - Bezier Curve. First we know about the curves, then what is bezier curves then we will learn drawing bezier curves in opengl.

Curves

Curves are set of indefinite set of points which need not to be straight. Curves are differently defines in mathematics, hence context will tell the proper definition. A curve can be in 2d (plane curves) or in 3d (space or Euclidean Space curves). A line is special type of curve which is straight. A curve is represented with some set of equation called the equation of curve.

Classification of Curves

There are mainly two types of curves -
  • Open Curve : The curves which have no endpoints are called open curves. Eg - Parabola, Hyperbola.
  • Closed Curve : When the curves end points are joined, they are called closed curves. Eg - Circle, Ellipse.
The curves can be further classified into three types -  implicit, explicit and parametric curves.
  • Implicit Curve - These type of curves implicitly represent the set of points on a curve which can be easily tested. The general function form is  - f(x, y) = 0. Eg.  Cricle (x2 + y2 - R2 = 0, R = Radius)
  • Explicit Curve - Curves which is explicitly represented and for each value of x there is only one y can be calculated are Explicit curves. They are generally represented with the function y = f(x). Eg. Cubic curves (Y=aX3+bx2+cx+d)
  • Parametric Curve - The curves that can be represented by parametric form, described by expressing the position of all its points as function of one parameter. The general functional form is P(t) = f(t), g(t). Eg. Bezier Curve.

Bézier Curves

Bézier curves are parametric curves that are generated with the control points. It is widely used in computer graphics and other related industry, as they appear reasonably smooth at all scales. Bézier curves was name after french engineer Pierre Bézier, who discover it. Mathematically Bézier curves is represented as -


Bézier curves are of different degree - linear curves, quadratic curve, cubic curve and high order curve. See the images below taken from wikipedia.

Quadratic Bézier curves

Cubic Bézier curves

Drawing Bézier curves in opengl

To draw bezier curve opengl c++ you need to define the curve center points. First we will define a function that will compute the points of the curve. This functions is very important for drawing bezier curves in opengl. 

 void bezierCoefficients(int n, int *c)
{ int k,i; for(k=0;k<=n;k++)
{ c[k]=1; for(i=n;i>=k+1;i--)
c[k]*=i; for(i=n-k;i>=2;i--)
c[k]/=i;
 } } 

In bezier curve opengl code display function we will define an array that holds the x, y coefficients of end points. In this function only we will define the line width which will define the width of curve. The bezierCoefficients function is called, then we looped it to form the curve. We are going to use the GL_LINE_STRIP to develop the curve. In the drawing bezier curves in opengl we also need to define the glPointSize as well as set the gluOrtho2D to certain x, y values which define the curve path.

I hope you like this article showcasing the bezier curve opengl c++ and learn more about drawing the curve. Download the full bezier curve opengl code from below and tell us about it in comments.


COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa First Come First Serve Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Random Flowing lines Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: Drawing Bézier curves in Opengl C++
Drawing Bézier curves in Opengl C++
Bézier curves have important use in computer graphics thus we will learn Drawing Bézier curves in Opengl C++ in this post.
http://2.bp.blogspot.com/-ZdUxm8f4MTs/Vnb6pxKetBI/AAAAAAAAHhY/H8DokwsUB28/s640/Drawing%2BB%25C3%25A9zier%2Bcurves%2Bin%2BOpengl%2BC%252B%252B.png
http://2.bp.blogspot.com/-ZdUxm8f4MTs/Vnb6pxKetBI/AAAAAAAAHhY/H8DokwsUB28/s72-c/Drawing%2BB%25C3%25A9zier%2Bcurves%2Bin%2BOpengl%2BC%252B%252B.png
OpenGL Projects
http://www.openglprojects.in/2015/12/drawing-bezier-curves-in-opengl-c.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2015/12/drawing-bezier-curves-in-opengl-c.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago