Getting ready

We'll use the following vertex shader:

#version 430 
 
layout (location = 0) in vec3 VertexPosition; 
layout (location = 1) in vec3 VertexColor; 
 
out vec3 Color; 
 
uniform mat4 RotationMatrix; 
 
void main() { 
  Color = VertexColor; 
  gl_Position = RotationMatrix * vec4(VertexPosition,1.0); 
} 

Note that the RotationMatrix variable is declared using the uniform qualifier. We'll provide the data for this variable via the OpenGL program. The RotationMatrix variable is also used to transform VertexPosition before assigning it to the default output position variable, gl_Position.

We'll use the same fragment shader as in the previous recipes:

#version 460 in vec3 Color; layout (location = 0) out vec4 FragColor; void main() { FragColor = vec4(Color, ...

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.