Creating a 2D plot using primitives
Creating a 2D plot is a common way of visualizing trends in datasets in many applications. With OpenGL, we can render such plots in a much more dynamic way compared to conventional approaches (such as basic MATLAB plots) as we can gain full control over the graphics shader for color manipulation and we can also provide real-time feedback to the system. These unique features allow users to create highly interactive systems, so that, for example, time series such as an electrocardiogram can be visualized with minimal effort.
Here, we first demonstrate the visualization of a simple 2D dataset, namely a sinusoidal function in discrete time.
Getting ready
This demo requires a number of functions (including the drawPoint
, drawLineSegment
, and drawGrid
functions) implemented earlier. In addition, we will reuse the code structure introduced in the Chapter 1, Getting Started with OpenGL to execute the demo.
How to do it…
We begin by generating a simulated data...