Writing texturing vertex and fragment shaders
Texturing is a common technique that significantly improves the quality of rendered images. It allows us to load an image and wrap it around the object like a wallpaper. It increases the memory usage, but saves the performance which would be wasted on processing much more complex geometry.
How to do it...
- Create a vertex shader in a text file called
shader.vert
(refer to the Writing vertex shaders recipe). - Apart from the vertex position, define an additional input variable (attribute) in the vertex shader through which texture coordinates are provided from the application:
layout( location = 1 ) in vec2 app_tex_coordinates;
- In the vertex shader, define an output (varying) variable through which texture coordinates will be passed from the vertex shader to a fragment shader:
layout( location = 0 ) out vec2 vert_tex_coordinates;
- In the vertex shader's
void main()
function, assign theapp_tex_coordinates
variable to thevert_tex_coordinates
...