This repo demonstrates how to use OpenGL's tessellation shaders to render Bézier curves and surfaces. Such curves and surfaces are an intuitive, extendable, and numerically stable way to add character to renders. And the tessellation shaders provide a performance minded and memory efficient way to implement Bézier curves and surfaces in OpenGL, what a great combination!
Looking at the structure of the tessellation shader I believe it was built for these types of operations. As such the purpose of each file in the demonstrations follows naturally from their shader type, which can be read about here, with main.c acting as minimal driving code to build the shanders and send them user input. Hence the following table only gives a mathematical summary of each demonstration:
Demonstration | Summary |
---|---|
cubic curve | Implementation of a cubic Bézier curve which can be thought of as a smooth line between two end point and their tangents. |
bicubic rectangle | Implementation of a bicubic Bézier surface which can be thought of as a soft rectangle controlled by 16 points which can be used to 'pull' the rectangle towards them. |
cubic triangle | Implementation of a biquadratic Bézier surface which can be thought of as a soft triangle controlled by 10 points which can be used to 'pull' the triangle towards them. |
conic section | Implementation of a rational quadratic Bézier curve which can be thought of as as the conic section between two endpoints, their tangents, and an arbitrary third point. |
width and color | Implementation of a cubic Bézier curve where both width and color are also parameterized by the control points alongside position. |
composite curve | Implementation of a composite Bézier curve with velocity continuity such that the geometry is specified once and locally at each point defining the curve. |
intersections | Implementation of the intersections of a cubic Bézier curve and a line using iterative subdivision. Note that the intersection isn't directly related to OpenGl and reuses the shaders from the cubic curve demonstration. |
And more to come!
- Set-up: For general SDL examples and set-up advice consider Lazy Foo' Productions SDL Tutorials.
- Tessellation Shader: For background on the Tessellation Shader consult the OpenGL wiki's Tessellation page.
- Mathematics: For further reading into how the presented algorithms work consider reading "Curves and Surfaces for CAGD: A Practical Guide".