OpenGL Viewer



The main goal of this tool is to recreate OpenGL rendering environments. The tool allow to set most of the OpenGL rendering options and save them in an ascii file. Once options are saved, any application can use the tool and the file in order to set the rendering options to the same value. This can be very useful when comparing the speed of rendering between different graphic systems for instance.

Other applications of this tool are:

  • a simple viewer where the user is focused on the geometry and can get different visualizations very easily.
  • a teaching tool for explaining shading models, lighting, etc.


The view volume is defined by a unitary cube centered on the origin. The options that the tool offers and that can be changed using the graphic user interface are:

  • Clear color: white, black, blue or own.
  • Window size: 350x300, 750x576 (pal), 800x600, 1024x768, full screen, game mode.
  • Shade model: flat or smooth.
  • Polygon model: fill or line.
  • Front face: CW or CCW.
  • Cull face: front or back.
  • Backface cull: enabled or disabled.
  • Projection: parallel or perspective.
  • Lighting: enabled or disabled, light0 and material enabled or disabled.
  • Save image '.ppm'.
  • Save and reload the options file.

Other options that can be changed by editing the file of options are:

  • Camera fovy.
  • Normalization of normals.
  • Enable light two side.
  • Enable light local viewer.
  • Light model ambient value.
  • Light 0 values: position, diffuse, specular and ambient.
  • Material values: ambient, diffuse, specular, emission and shininess.

Interaction options:

  • Left button to rotate the scene.
  • Ctrl + left button for zooming.
  • Shift + left button for panning.
  • Esc or 'q' to exit.

This is an example of the simplest program:

#include <GL/glut.h>
#include "glvViewer.h"

class my_glvViewer: public glvViewer {
  void glvMyDisplay (void);

void my_glvViewer::glvMyDisplay(void) {
  glutSolidSphere (0.5f, 10, 10);

int main (int argc, char **argv) {
  my_glvViewer v;
  v.glvInit (argc, argv);
  v.glvLoop ();
  return 0;

Together with the glvMyDisplay method, you can extend the popup menu, the keyboard callback and set your own rendering options as fog, etc, by defining the following methods:

void glvMyMenu(int id) {}; /* Your menu callback. id: is the id of the current menu. */
void glvMyKeyboard(unsigned char key, int px, int py) {}; /* Your keyboard callback */
void glvMyRenderOptions(void) {}; /* Your render options function */

This is an example of the file that describes the rendering environment:

#### Rasterization
window_size 800 600
window_pos 484 233
game_mode 640x480:8@60
clear_color blue
own_clear_color 0 0 0 0
shade_model flat
polygon_mode line
front_face cw
cull_face_mode back
cull_face no
#### Transformation
projection parallel
camera_fovy 45
normalize no
#### Lighting
Enable_Light0 no
Enable_Lighting no
Enable_Color_Material no
Enable_Light_Two_Side no
Enable_Light_Local_Viewer no
Light_Model_Ambient 0.2 0.2 0.2 1
Light0_Position 0 0 10 1
Light0_Diffuse 0.7 0.7 0.7 1
Light0_Specular 0.2 0.2 0.2 1
Light0_Ambient 0.1 0.1 0.1 1
Material_Ambient 0.1 0.1 0.1 1
Material_Diffuse 0.7 0.7 0.7 1
Material_Specular 0.2 0.2 0.2 1
Material_Emission 0 0 0 0
Material_Shininess 50


This software requires OpenGL and the GLUT library. Comments or suggestions are welcome. You can make free use of the software under the terms of the GNU General Public License.