Rendering onscreen charts
In the Implementing an immediate mode drawing canvas recipe, we learned how to create immediate mode drawing facilities in Vulkan with basic drawing functionality. In this recipe, we will continue adding useful utilities built on top of a 2D line drawing.
Getting ready
We recommend revisiting the Implementing an immediate mode drawing canvas recipe to get a better grasp of how a simple Vulkan drawing canvas can be implemented.
How to do it...
What we need at this point essentially boils down to decomposing a 2D chart or graph into a set of lines. Let's go through the code to see how to do it:
- We introduce the
LinearGraph
class to render a graph of floating-point values. It stores a collection of values and the maximum number of points that should be visible on the screen. A deque is used here for the sake of simplicity:class LinearGraph { std::deque<float> graph_; const size_t maxPoints_; public: ...