Department of Engineering

IT Services


This talk attempts to list some of the computer graphics facilities used at CUED (in particular the Unix Teaching System), offering information and demos so that people wanting to add graphics to their programs can make an informed choice.

The issues

When deciding how to produce on-screen graphics, many issues come to mind

  • Capability - What do people mean when they say they want "graphics" - buttons? a few line-graphs? Tomb-Raider-style animation? Within the department all these types are needed, but no single facility provides all the answers.
  • Portability - In the past each type of computer had its own (often proprietary) graphics system which was incompatible with every other system. Over the years attempts have been made to solve this problem. Two of the most successful are
    • X Windows - began on Unix machines. Allows cross-network use (i.e. you can run the program on one machine and display it on another machine which needn't be of the same type). Intended as a low-level base upon which other graphics can be delivered.
    • OpenGL - High level. OpenGL applications can run on new PCs, Macs and the Unix Teaching System. If it's good enough for Lara Croft...
    Saying that these options are portable doesn't mean that you won't need to install extra things first. Even if the resulting programs run without preparation, you'll probably need to install a "development kit" in order to write and compile programs.
  • Language - If you're a Fortran writer, you don't want to learn a new language just so that you can add some graphics to your program. Some graphics systems can only be used from certain languages. The Java language has some graphic ability, but the routines can only be called if you use java.

    Some options (like Visual BASIC) lock you into using a particular language and a particular type of machine.

  • Extendibility - can new commands be added to the graphics facility?
  • Speed - Without appropriate graphics cards, many graphics options are slow, but OpenGL is well supported.
  • Ease of Use - If you're only drawing a line or 2, you don't want to write loads of code. X is so low-level that simple programs if properly written could be 100s of lines long (local users can look at /export/Examples/X/XR5demo.c).

Any sufficiently useful graphics library is also likely to be complicated too - people don't usually bother going to all the trouble of producing a platform-independant graphics library just to do simple lines and dots.

Matlab and Java

The trouble with the older languages (Fortran, C++ etc) is that they have no graphics. Before you start wondering how to add graphics to the language you know, it may be worth considering new languages. Maybe matlab can do the whole job. Or maybe it's time to consider java. On the Teaching System you can run a Java demo by typing

  java -jar ~tpl/javadir/Java2Demo.jar 


We'll first consider drawing lines and dots, etc (not buttons, menus, etc).

X is too low-level for simple use. The vogle graphics library is layered on top of the X library. Until 2006 it was used by undergraduates here when they learnt C++. It supports 3D coordinate systems and animation (you can fling wire-frames around in 3D, for example). It can be used from Fortran, C, C++ etc and can run with X Windows, MS Windows, etc. It's easy to use, but ancient.

plotutils is a GNU product with support for X (i.e. it will run on any machine that supports X)

Some CUED groups use OpenGL. It's free and works with many languages (C++, Fortran, Python, Perl, Java, etc). As with X, you need to write many line of code even to draw a line. The OpenGL Utility Kit (GLUT) makes it considerably easier to learn about and explore OpenGL programming. It's designed for constructing small to medium sized OpenGL programs. There's a local introduction to Using GLUT. But even that's not simple enough for undergraduate use, so we provide a simplified version for the first years, called GLUE.

Drawing anything from scratch is a struggle. Matlab can be used like a graphics library from fortran, C, and C++, letting you do in a few lines what would otherwise take hundreds.

Another option is the Visualization ToolKit (VTK).

Advanced 3D effects

Blender is one of several free programs that deals with Rigging, Animation, modeling, Rendering, Shading, and game creation. Yafray is a free raytracer that can be used as a plug-in to Blender.

Graphics User Interfaces

The Graphical User Interfaces (GUI - pronounced "goo-ee") can make or break a program, and can be a significant proportion of the code. The principles behind many GUI systems are similar. I'll talk about Motif. Motif is built on top of the X library. It has Widgets of 2 main types: simple widgets like buttons, text labels, etc, and container widgets that group and align other widgets. The Widgets can respond to Events like button presses, etc. The idea is that you specify the features of the widgets (color, text size, etc) and how you'd like them organised (button1 to the left of button2, etc) and Motif does the rest, coping with window-resizing etc. The Widgets can have callbacks - routines that are called when particular events happen.

One particular type of Widget is a Drawing Area widget (sometimes called a canvas) - an area in which graphics (using Xlib routines for example) can be drawn.

A number of options exist for creating GUIs. The best way is to use a GUI creator that lets you draw the kind of application you want to write and then creates the source code you need. Matlab's guide does this for matlab programs. Some other programs give you a choice of types of source code to produce. The final appearance is unlikely to be exactly the same in each case though. Indeed, you may prefer them to look different - people running your program on Windows might expect a program with the look'n'feel of other Windows programs.

If you don't have a GUI creator you can use

  • GTK+ (Open Source Free Software GUI Toolkit, primarily developed for use with the X Window System) and gtk-- libraries are installed on the Teaching System. See the Tutorial. The airfoil and specbuilder teaching programs use these.
  • The GLUI User Interface Library is an OpenGL-based C++ user interface library which provides controls such as buttons, checkboxes, radio buttons, and spinners. There's a local introduction to Using GLUI.
  • The GLUE library combines features from GLUT, GLUI and OpenGL to produce a simple entry-level library.
  • wxwidgets can do a lot more than GLUI does, and is correspondingly harder to use. It can be used with Win32, Mac OS X, X11, Motif, etc from C++, Python, C#/.NET, etc. It's used in the IIA Software project. See our local wxWidgets page for more information.

On our Installing C++ compilers page we show how to install C++ compilers with support for openGL and GLUT on Macs, Windows, and Linux.

Scripting Languages

Most of the options above use compiled languages, but some scripting languages might be useful. Type wish ~tpl/tcldir/demos/widget to see a demo of the Tcl/Tk language. The demos let you see the corresponding source code. There's almost a 1-to-1 relationship between source code lines and objects. Note that Tcl/Tk uses container widgets (called frames), and callbacks (using the "-command" option). Tcl/Tk is free, and available for many types of machines, but it's not often installed.


Within CUED, activity seems to be focussing around 2 main styles of work

  • All-in-one solutions - Java and Matlab
  • wxWidgets and openGL - often used with GLUT