Time for action - generating a Bezier curve
OpenGL has provided functions to generate Bezier and NURBS curves and surfaces for years, but they are not as good as we wish. Today's geometry shader can do the same work in a more convenient and efficient way. Take the generation of a Cubic Bezier curve as an example. Given two endpoints, and two control points to the shader, it will then produce a smooth curve, with specific segments, that begins and ends at two different endpoints, and be pulled away towards the control points.
- Include the necessary headers. We'd like to change the output line width, so the
osg::LineWidthclass is used here, too:
#include <osg/Program> #include <osg/LineWidth> #include <osgDB/ReadFile> #include <osgViewer/Viewer> ...