Rendering a triangle
Now that we’ve learned about all basic Vulkan objects and how they work, we can finally create a small example application that displays a static shaded triangle on the screen.
In this recipe, we will present a full example that renders a static triangle on the screen. The vertex data and attributes are statically provided in the vertex shader.
Getting ready
The code in this recipe can be found in the repository in source/chapter1/main.cpp
. The vertex and fragment shaders are located in source/chapter1/resources/shaders
, in the triangle.vert
and triangle.frag
files.
How to do it…
The code presented here is an unabridged version of the code in the repository.
- For this recipe, we will use two shaders:
triangle.vert
andtriangle.frag
. The vertex shader does not accept any inputs, as all the data it needs is defined right there in the shader itself as two arrays: one for vertex data (positions
) and the other for color data (colors...