Book Image

OpenGL Data Visualization Cookbook

Book Image

OpenGL Data Visualization Cookbook

Overview of this book

OpenGL is a great multi-platform, cross-language, and hardware-accelerated graphics interface for visualizing large 2D and 3D datasets. Data visualization has become increasingly challenging using conventional approaches as datasets become larger and larger, especially with the Big Data evolution. From a mobile device to a sophisticated high-performance computing cluster, OpenGL libraries provide developers with an easy-to-use interface to create stunning visuals in 3D in real time for a wide range of interactive applications. This book provides a series of easy-to-follow, hands-on tutorials to create appealing OpenGL-based visualization tools with minimal development time. We will first illustrate how to quickly set up the development environment in Windows, Mac OS X, and Linux. Next, we will demonstrate how to visualize data for a wide range of applications using OpenGL, starting from simple 2D datasets to increasingly complex 3D datasets with more advanced techniques. Each chapter addresses different visualization problems encountered in real life and introduces the relevant OpenGL features and libraries in a modular fashion. By the end of this book, you will be equipped with the essential skills to develop a wide range of impressive OpenGL-based applications for your unique data visualization needs, on platforms ranging from conventional computers to the latest mobile/wearable devices.
Table of Contents (16 chapters)
OpenGL Data Visualization Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Compiling and running your first OpenGL application in Mac OS X or Linux


Setting up a Linux or Mac machine is made much simpler with the command-line interface. We assume that you have all the components that were discussed earlier ready, and all default paths are used as recommended.

Getting ready

We will start by compiling the sample code described previously. You can download the complete code package from the official website of Packt Publishing https://www.packtpub.com. We assume that all files are saved to a top-level directory called code and the main.cpp file is saved inside the /code/Tutorial1 subdirectory.

How to do it...

  1. Open a terminal or an equivalent command-line interface.

  2. Change the current directory to the working directory:

    cd ~/code
    
  3. Enter the following command to compile the program:

    gcc -Wall `pkg-config --cflags glfw3` -o main Tutorial1/main.cpp `pkg-config --static --libs glfw3`
    
  4. Run the program:

    ./main
    

Here is your first OpenGL application that runs natively on your graphics hardware and displays a rotating triangle. Although we have defined the color of only three vertices to be red, green, and blue, the graphics engine interpolates the intermediate results and all calculations are performed using the graphics hardware.

To further simplify the process, we have provided a compile script in the sample code. You can execute the script by simply typing the following commands in a terminal:

chmod  +x compile.sh
./compile.sh

You may notice that the OpenGL code is platform-independent. One of the most powerful features of the GLFW library is that it handles the windows management and other platform-dependent functions behind the scene. Therefore, the same source code (main.cpp) can be shared and compiled on multiple platforms without the need for any changes.