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);
Download the library
- Source code available on github: https://github.com/drohmer/CGP
- The library is provided under the MIT Open Source License.
- 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
- - Easy to use CG basic tools.
-
-
Provide common elements (3D vectors, transformations, etc.) with direct access to their degrees of freedom.
-
- - Data and structure ready for simple real-time interaction and animation.
-
-
Lightweight structures that are bloat-free by default.
-
Large elements stored contiguously in memory.
-
No assumptions on the structure of animation loop (beyond the use of GLFW and ImGui for events and gui handling).
-
- - Source code which is easy to read and understand.
-
-
Most CGP structures don't have private internal state and restrict their parameters to the minimal needed set.
-
- - Helping structures and functions that do not impose a framework.
-
-
Code remains fully compatible with direct OpenGL calls.
-
Most structures are independant to each other without requiering object hierarchy relations.
-
Custom higher-level OOP structure can easily be added on top of CGP elements for specific projects.
-
- - Code which is secured and easy to debug.
-
-
Buffers are bound checked by default, no direct pointer manipulation.
-
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
- - 3D Animation and Simulation course (INF585) - github page
- - Introduction to 3D Graphics (fr, INF443) - github page
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.-
ex. cgp/example_compilation/
Method 1. Using the provided Makefile:
$ make $ ./[executable-name]
$ mkdir build $ cd build $ cmake .. $ make $ ./[executable-name]
Windows
Method 1. Create a Visual Studio project using CMake. The scriptscripts/windows_cmake_visual.bat
is provided to automatize this generation. - Once opened by Visual Studio, the project should be configured to compile and be executed directly without further setup. Make sure your Windows version is updated for Visual Studio to be able to compile correctly C++14.
General architecture
The library rely on basic C++ code with a few dependencies for OpenGL and the GUI- Only GLFW is an external dependencies on Unix system, otherwise all libraries are provided with the code
- Glad is used to load functions for OpenGL 3.3
- GLFW is used to create the window and handle mouse/key events
- ImGUI is used to handle the GUI widgets
- jpeg-compressor used for JPEG, and lodepng for PNG images handling.
- library/cgp/: Contains the actual source code of the CGP library: set of structures and functions to ease generating 3D scene.
- library/third_party/: External library/dependencies used by CGP.
- examples/: Provide a set of independant program illustrating example use cases of CGP library.