OpenGL logo
Geant4 Workshop Visualization Tutorial using the OpenGL Event Display


This tutorial has been updated for use at the October 2003 Fermilab Geant4 Tutorial, but is also designed for use by anyone else who wants to learn OpenGL Visualization for Geant4.

This tutorial can be used on its own, but gives the most comprehensive introduction to Geant4 visualization when used as part of the following full set of documents:

While some Geant4 visualization drivers are always included by default in your Geant4 build (because they require no external libraries), OpenGL is not included by default. You must explicitly add OpenGL to your build by setting an environment variable and then remaking.

At the time of this writing, OpenGL for Geant4 only works on Linux, not Windows. But stay tuned for updates - that situation is likely to change soon (OpenGL is included as part of the Windows operating system, but Geant4's OpenGL driver is not correctly designed yet to take advantage of that version).

Installing OpenGL (but usually you will find you already have it)

OpenGL is a standard Linux system component, and should be part of the RedHat or Debian distribution, so you probably already have it installed.

Rebuilding Geant4 to Include OpenGL

The pre-built Geant4 that you used in an earlier tutorial does not include OpenGL. This is done both to make the pre-built version more portable and to make the pre-built version able to run with JAIDA/JAS. Unfortunately, you cannot run JAIDA/JAS if OpenGL is in your build.

Geant4 has several different modes in which it can run OpenGL. We will just show you one mode, the easiest to get started, but you may later want to experiment with the other powerful modes.

For details on using these other OpenGL modes (necessary libraries, environment variables, etc.), see the Geant4 Visualization README file:

Set some environment variables before you rebuild Geant4:

You now have the correct environment to rebuild Geant4 with OpenGL (and without JAIDA/JAS).

Running Geant4 with OpenGL

Now for the easy part. Since OpenGL runs directly from Geant4, you just start Geant4 and then issue a few visualization commands.

Recap of Geant4 Commands Used in this Tutorial

If you need to quickly get back to where you were in the tutorial, it may be helpful to cut and paste a set of commands from this list:
/vis/open OGLIX
/vis/viewer/set/viewpointThetaPhi 70 20
/vis/viewer/zoom 2
/vis/viewer/set/viewpointThetaPhi 40 40
/vis/viewer/panTo -5 -1
/vis/viewer/zoom 4.
/tracking/storeTrajectory 1
/run/beamOn 1
/vis/viewer/set/style surface
/run/beamOn 1
/vis/viewer/set/style wireframe
/run/beamOn 1

Further Resources

Joseph Perl

14 October 2003