# The contribution examples

The following examples do not directly illustrate a functionality of the library. Some are very simple while others are much more involved. Feel free to browse the files and to cut and paste. Only a short description is here given, the different source code are available in the `examples/contribs` directory.

## 3dsViewer

| The LGPL lib3ds library is used to load and display a 3ds scene. You need to install the lib3ds library (version 1.2) in order to compile this file. See http://lib3ds.sourceforge.net/. The current version (Version 1.2, Dec 2002) of the lib3ds library is flawed and results in :
    3dsViewer.cpp:62: `lib3ds_file_bounding_box' undeclared (first use this function)
A patched version is available on the Unix installation page. You can alternately add this line in the file that uses `lib3ds_file_bounding_box()` (or in `lib3ds/file.h`) :
    extern "C" { LIB3DSAPI void lib3ds_file_bounding_box(Lib3dsFile *file, Lib3dsVector min, Lib3dsVector max); }
This example is simply a translation of a lib3ds example. Although it uses display lists, the rendering speed does not seem to be as good as with other 3ds libraries (10 factor speed up). Note however that this is due to the lib3ds library and not QGLViewer. Press 'L' (load) to load a new 3DS scene.

## agora

| Implementation of the game of Agora. Agora is a strategy game for two players. The code is rather complex and can be divided in two parts : a QGLViewer implementation for the viewer and an artificial intelligence that allows you to play against the computer. You should find the rules of the game on the web. Questions relative to the artificial intelligence implementation should be asked to `Jean-Guillaume dot Dumas at imag dot fr`. Computer player programs are expected to take three parameters: a board file name, an allowed time (expressed in milliseconds and which sign determines which player is to play) and the remaining number of moves before the game is declared over. The output should be the x,y coordinates of the start and end positions of the move to play.

## anaglyph

| Displays a scene in pseudo-stereo using anaglyph. The anaglyph stereo mode displays simultaneously two colored views of the scene. You need to wear glasses with colored lenses (here red and blue) to view the stereo image. Each eye then sees the associated view, creating the stereo illusion. All that is needed is to use the `loadModelViewMatrixStereo()` and `loadProjectionMatrixStereo()` camera functions to set appropriate `GL_MODELVIEW` and `GL_PROJECTION` matrices.

## backgroundImage

| Displays a background image in the viewer. This example is derived from the textureViewer example. It displays a background image in the viewer using a texture. The texture is simply mapped to a quad, drawn before the rest of the scene. The depth buffer is flushed after the drawing. `startScreenCoordinatesSystem()` enables an easy pixel coordinate placement of the quad. This example was created by Sylvain Paris. Thanks to him.

## blobWar

| Implementation of the game of BlobWar. BlobWar is a strategy game for two players. The rules are available in the help menu. The two players can be human or computer. Computer player programs are expected to take two parameters: a board file name and an allowed time (which sign determines which player is to play). The output should be the x,y coordinates of the start and end positions of the move to play. A naive greedy AI program is provided in the AI directory.

## cornerAxis

| Displays a world axis in the lower-left corner of the window. A world axis representation is drawn in the lower left corner, so that one always sees how the scene is oriented. The axis is drawn in `postDraw()` with appropriate ortho camera parameters. `glViewport` and `glScissor` are used to restrict the drawing area. This example is very similar to the thumbnail example.

## dvonn

| Implementation of the game of Dvonn. Dvonn is a very good strategy game for two players. See the Help menu for complete rules. Consider buying the game if you liked it. It is quite cheap and really nicer than this version. See the GIPF project web page for details. This example was created by Xavier Decoret.

## eventRecorder

| Records a scenario that can be replayed and converted into a movie. An `EventRecorder` is associated to a `QGLViewer`. When the `EventRecorder` `isRecording()`, the different events that are sent to the qglviewer() are recorded in an internal data structure. The EventRecorder then can replay these events with an identical timing in order to reproduce the recorded scenario. Snapshots can optionally be captured during playback, and the resulting image series can be converted into a movie.

## quarto

| A simulation of the game of Quarto. See the `rules.txt` file for explanations. This program was originally coded by Matthieu Richard.

## terrain

| A random fractal terrain with trees, animated water, sky and shadows. This example was created by Serigne Sow and Joerg Liebelt. It features a textured quadtrees fractal terrain, which resolution is dynamically updated depending on the camera position. Acknowledgments to Stefan Roettger for his article Real-Time Generation of Continuous Levels of Detail for Height Fields.

## textureViewer

| Loads an image file and texture maps a polygon with it. Pedagogical example that shows how to apply a texture on a 3D object. Inspired from the Qt texture example. The Qt `QImage` class and its `convertToGLFormat()` function are used to load any image format. The image is included in a larger image whose dimensions are powers of two. This is not required if your hardware supports the GL_TEXTURE_RECTANGLE extension. Feel free to cut and paste.

## thumbnail

| Displays an alternative 3D view in a corner thumbnail. This example shows how a thumbnail can be inserted in a corner of the viewer to display an alternative display. This can be useful for data structure inspection, different rendering (as illustrated here) or debugging. It uses `glViewport` and `glScissor` to restrict the drawing area. This example was created by Sylvain Paris.

Back to the examples main page.

Last modified on Monday, August 31, 2009.