How to do it...

To create a shader program that will generate a Bezier curve from a patch of four control points, use the following steps:

  1. Use the following code for the vertex shader. Note that we send the vertex position along to the TCS unmodified:
layout (location = 0 ) in vec2 VertexPosition; 
 
void main() {
    gl_Position = vec4(VertexPosition, 0.0, 1.0); 
} 
  1. Use the following code as the tessellation control shader:
layout( vertices=4 ) out; uniform int NumSegments; uniform int NumStrips; void main() { // Pass along the vertex position unmodified gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; // Define the tessellation levels gl_TessLevelOuter[0] = float(NumStrips); gl_TessLevelOuter[1] = float(NumSegments); ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.