Example codes

Several example code are provided on the cgp_example repository
Direct download: [cgp_examples.zip] [cgp_examples.tar.gz]

Transparent billboards

This code uses a shader to display partly transparent textures. The code illustrates this use to display complex foliage of a pine tree.

Marching Cube - Static

Example of simple marching cube applied to an arbitrary function (a blobby function here) within a fixed domain.

Marching Cube - Dynamic update

Example of marching cube updated dynamically when the field function is modified via the GUI. The surface is made of triangle soup (duplicated vertices on shared triangle edges), and the normals are obtained from the field gradients computed from finite differences. The structures used in the example are more involved compared to the simple call to marching_cube, but it is compatible with more efficient update.

Shader deformation

This code shows a procedural deformation fully computed in the vertex shader. A regular flat grid is displayed at each frame, and a deformation is applied in the vertex shader based on a time variable.

Multi-texturing

This code shows the use of a shader using two textures. The two textures are blended together in multiplying their respective color. The amount of blending is modified based on the (u,v) coordinates.

2D Curve sketch

Example of direct curve sketching on screen. The sketch is done in the 2D space under an orthographic projection. Each sketched stroke is handled as a curve_dynamic_drawable.

Skybox

Simple use of the class skybox_drawable to display a skybox (using 6 textures) in your scene.

Environment map

This code shows the use of environment (/reflection) mapping. A "Skybox" is displayed in the background = a cube with a seamless environment texture that follows the user. And the main shape is displayed with a reflective mapping (the normal of the shape indicates which part of the texture is displayed).

Multi-Pass Image Filter

This code shows a multi-pass render using a Frame Buffer. In a first pass a scene is render and stored as a texture. In the second pass, the image is filtered using a second derivative convolution kernel and displayed finally on screen.

Image Filter - Basic Effects

A selection of image-based effects applied in a two pass-rendering. Each effect is generated by a shader that is dynamically loaded from the gui.

Multi-Pass chaining effects

This code shows a 3-pass rendering using two consecutive Frame Buffer and two consecutive image filters (gradient, and thickening).

Shadow Mapping

This code shows an example of shadow mapping implementation.

Camera Fly Mode

This code shows the possibility to navigate in a "fly-mode" using the key arrows: left/right/up/down.

Camera 2D Displacement

This code shows the possibility to navigate on a 2D plan using standard game-like mode (arrows + mouse).

Instancing (basic)

This code shows an example of use of Instancing to display a large quantity of similar shapes. The positions of the instances are sent as additional data buffer to the shader.

Instancing (procedural)

This code shows an example of use of Instancing to display a large number of similar shapes. In this example, the number of instances can be controled via the GUI, and the position/orientation and deformation of each blade of grass is procedurally computed in the shader, while the color is pre-computed.

Advanced OBJ Loader

Example of use of the advanced obj loader using the external library tinyobj. Allows to load obj mesh files made of multiple parts with several textures.