CGP - Computer Graphics Programming library

mesh cube = mesh_primitive_cube();
for(int k=0; k<cube.position.size(); ++k)
    cube.position[k] += 0.1f * cube.normal[k];

cube_drawable.initialize_data_on_gpu(cube);
cube_drawable.material.color = { 1,1,0 };

   // ----------------- //

draw(cube_drawable, environment);
draw_wireframe(cube_drawable, environment);
assets/cgp_image.jpg
Example of CGP code and associated 3D result.

Download the library

  • Or via direct download: [cgp.zip]

CGP General Principles

CGP (Computer Graphics Programming library) is a lightweight and minimalist C++ library using OpenGL to represent, animate, and interact in real time with 3D scenes.
It features a set of simple structures and functions (vectors, matrices, mesh structures, transforms, camera, etc) that are simple to use and read. The objective is to save time compared to raw OpenGL coding, while preserving the fundamental logic and comprehension of high-performance Graphics.

The main objective of CGP is to provide

Example of CGP usage

Default use

Import the header file "cgp/cgp.hpp" to access all functions and structure of CGP.
#include "cgp/cgp.hpp"

// All cgp functions are in the namespace cgp::
using namespace cgp;

int main()
{
    // declare two 3D vectors and display their sum on command line
    vec3 a = {1,2,3};
    vec3 b = {4,5,6};

    std::cout<< a + b <<std::endl; // Displays 5 7 9
}

Example code

A set of example codes are provided here: github.com/drohmer/cgp_examples.
See example page for more information.

Example of advanced usage in teaching context

Compiling CGP

The directory library/ contains the source code of CGP, while the directory examples/ contains a set of scene setup (ex. directory examples/00_empty_3D_scene/).
Each example is an independant program with its own Makefile and/or CMakeLists.txt.
If needed, a detailed tutorial on how to install your system and compile C++ code is available there:

General dependencies

CGP requires a C++14 (>=) compatible compiler (CGG/CLang or a recent Visual Studio), and an OpenGL 3.3 (>=) compatible system.
On Linux/MacOS, GLFW and pkgconfig are expected to be installed on the system. Both can be installed using the standard packages of any distribution.

Linux/MacOS

Assuming a command line opened in one of the example scene.
Method 1. Using the provided Makefile:
$ make
$ ./[executable-name]
Method 2. Using the provided CMakeLists.txt:
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./[executable-name]

Windows

Method 1. Create a Visual Studio project using CMake. The script scripts/windows_cmake_visual.bat is provided to automatize this generation.

General architecture

The library rely on basic C++ code with a few dependencies for OpenGL and the GUI
The library directories are as follow