Purpose: to provide a collection point of information about the use of Tcl/Tk and the OpenGL 3D graphics libraries.

100. While not directly supporting Tcl, the WWW page at http://WWW.thp.Uni-Duisburg.DE/Ygl/ReadMe.html describes an X11 version of a simulation of SGI's GL under X11. You might try this with the Tcl/Tk OpenGL interfaces.

Zinc is an impressive achievement that will interest OpenGL students. Only 2D.

Tk3D has (among other things) an OpenGL widget. Unfortunately, the open-source version only supports Unix/linux. (That's easy to fix, though, for someone who knows openGL on Windows. Any takers?)

Tcl3D enables the 3D functionality of OpenGL and other 3D-related libraries (Cg, SDL, FTGL, GL2PS, ODE, OpenSceneGraph) at the Tcl scripting level. It comes with lots of demo programs. More info and images can be found at

The Tcl3D website has a reference page [1 ] of all supported OpenGL core and extension functions. It also shows, which functions have been deprecated with OpenGL 3.X.

The function and extension names support direct links to the official references on .

AM 2008-09-09: This is a short summary of my limited wisdom regarding OpenGL:

First of all, OpenGL defines a platform-independent API for drawing objects in two or three dimensions. However, it does not define a platform-independent way to specify the window in which to draw and it specfications only include very basic objects (no circles for instance). For this reason a number of auxiliary libraries exist:

  • GLU - the standard OpenGL utilities library (several more complex objects, higher-level routines and texture mapping)
  • GLX - a library to interact with the X Window system
  • AUX - a library that you can use interact with the MS Windows system (comes from the so-called Red Book, may not be restricted to MS Windows)

Needless to say that the GLX and AUX libraries have nothing in common, except their goal. This means that a program that uses OpenGL will have to cope with all the relevant platforms itself - though only as far as window interaction is concerned.

A further complication, especially when dealing with older X Window dispalys, is that OpenGL requires a special extension to work with OpenGL: GLX (normally a command "glXinfo" exists to inform you about the status of your X display). On MS Windows platforms, such an extension is not necessary - most computers running MS Windows have support for OpenGL, as this is a very popular platform for implementing games.

There is an alternative: the MESA library. It has the same API as the OpenGL libraries that rely on the hardware and software support, but it does not use anything special. As a consequence it is (much? noticeably?) slower.

(I have recently tried to use a very simple OpenGL program - a minimal example from the man pages - on different machines, but failed in most cases, except on an SGI workstation. The reason is unclear to me, but it does make me a bit scared - alas! All these problems were caused in one of the calls to X Window routines: some gave a coredump, some produced X errors)

Perhaps a word or two on the programming model:

The 2D and 3D graphics is mostly handled by specifying what you want. For instance:

   glColor3d( 1.0, 0.0, 0.5 ) ; /* Make the next objects purple (RGB) */
   glBegin( GL_POLYGON )      ; /* Start a polygon definition */
   glVertex3f( x, y, z )      ; /* Define the first vertex */
   glVertex3f( x, y, z+1 )    ; /* Define the second vertex */
   glVertex3f( x, y+1, z+1 )  ; /* Define the third vertex */
   glEnd()                    ; /* Complete the definition and draw it */

This type of code is found in the drawing routine that is called when the window containing the OpenGL picture needs refreshing. All kinds of shortcuts exist (making a display list for instance or use one of the utilities to make a more complex object), but this is the basis.

OpenGL relies heavily on matrix manipulation to move, rotate and scale the objects to be drawn:

   glRotatef( 90.0, 1.0, 0.0, 0.0 ) ; /* Rotate the next objects over 90
                                         degrees around the x-axis */
   glTranslatef( 0.0, 1.0, 0.0 )    ; /* Translate the next objects over
                                         a distance 1 in the y-direction */

The combination of such transformations is stored as a single operation on all the subsequent objects (by using so-called homogeneous coordinates, the translation is turned into a linear transformation too, a fourth coordinate is introduced which has the value 1 for all objects).

So an important part of OpenGL programming is the manipulation of these linear transformations.

Other features:

  • Texture maps can be comfortably stretched onto an arbitrary surface
  • Lighting can be taken care of
  • Hidden lines and surfaces are automatically removed from the drawing

The largest drawback of OpenGL, as far as the graphics is concerned, is that you need to have a fair understanding of low-level stuff to create a decent looking picture. But it certainly works!

Note: Something that was rather unclear in the Red Book (the standard book for starting OpenGL programmers) is the role of normal vectors to a surface. These are very important:

  • They determine the lighting properties (you need them to get a real 3D look)
  • The length of these vectors must be 1, because they also determine the brightness. A thing I only found out by experimentation :(

GWM 2004-09: NB the transforms are not essential to OpenGL - you can program a scene with the coordinates alone. Matrices make moving the objects relative to each other (anyone want a car race where the cars cannot move?) easier. Matrices also provide the perspective distortion applied when the scene is drawn, and the effective 'eye' or camera position.

Also normals (as complained about above) are transformed by any transform matrix resulting in non-unit normals if a scaling is applied. There is a setting to ensure that normals are re-set to unity, but this adds some processing overhead. Only use this if scaling is part of your transformation.

My own technique using the OpenSceneGraph ( ) is to set up Tcl/Tk from the C++ coding without the call to Tk_MainLoop but calling every frame:

do while (Tcl_DoOneEvent(TCL_DONT_WAIT )); // doOneEvent returns 0 if no events were handled.

OSG is a real time simulation program, it follows the common block diagram: Start - read files, initialise view, events etc.

Loop until end:

  • update scene
  • draw scene
  • HANDLE TCL/TK // above - loops until all Tcl/Tk events handled


The handle tcl/tk events is placed in the Loop, usually I place this after draw has started as there are likely to be unused CPU cycles while the graphics is rendering. (OSG supplies nice things like Stereo, frustum culling, lazy state sorting, access to GLSL etc and is fast method of doing OpenGL. It is a little less suited to developing a graphical editor as objects are display listed for speed, making editing a single vertex position slower.)

I have also used TkOGL though this was jerky while a window was resized.

jcw 2004-02-12: I've built a stubs-enabled version of Tkogl 1.1 for Windows, it's available at [3 ]. A small trick was needed to work around the fact that TkWinChildProc() is not in the stubs table. See also these posts on comp.lang.tcl [2 ].

TV: I combined a C program with openGL/Mesa graphics, in this case under windows, but the principles would work under other OS-es: Maze in openGL om windows navigation controlled by Tcl/Tk

By using a socket (or pipe) connection, the interactions with the tcl script can be seperately programmed, and possibly run on a seperate machine, leaving the primary graphics engine free.

PO 2005-07-27: DKF references the tclogl package, which now has its own Wiki page.

DKF 2005-06-06: Looking through the open issues outlined at [4 ] I see a fair few that can actually be dealt with smartly, and others that we can surely help with (issues in bold):

  • GLU callbacks are currently not supported. This implies, that tesselation does not work, because this functionality relies heavily on the usage of C callback functions. What would be needed to support these callbacks?
  • There is currently no possibility to specify a color map for OpenGL indexed mode. As color maps depend on the underlying windowing system, this feature should be handled by the Togl widget.
  • Picking with depth values does not work correctly, as depth is returned as an unsigned int, mapping the internal floating-point depth values [0.0 .. 1.0] to the range [0 .. 2**32 -1]. As Tcl only supports signed integers, some depth values are incorrectly transferred into the Tcl commands. Actually, you can easily describe a 32-bit unsigned value as a wide integer, and from 8.5 onwards Tcl has support for integers of arbitrary precision.
  • The handling of Tcl errors inside of Togl callbacks could be improved.
  • To evaluate the Tcl callbacks, Tcl_Eval is currently used, which does not compile the script into bytecode. Use the object-interface instead. This will help a lot with speed issues, especially if no substitutions are performed. If you have to perform substitutions, the fastest way to handle the script is if you restrict it to a command invokation and then pre-parse it into a list of words which you stash in an array; then you can substitute Tcl_Obj pointers directly and invoke Tcl_EvalObjv() to execute the command. This is very fast.

 What: GENERIC 3D Kernel
 Description: A generic 3D graphics kernel which can be used to implement
        one's own system by derivation from the generic.  Provides
        device drivers for a lot of graphics system, including
        Tk 3.6/4.0.  Includes an OpenGL Tk widget.
        See some of the following for examples of use of GENERIC:
 Contact: mailto:[email protected] (send subject of
        subscribe GENERIC mailing list)

 What: GRacer
 Description: 3D Motor sports simulator.
        Requires Tcl/Tk and OpenGL.
        Currently at version 0.1.5.
 Updated: 05/2000
 Contact: mailto:[email protected]

 What: Nebula Device
 Description: Free multi-platform game engine running under Linux and Windows.
        Uses OpenGL and/or Direct3D for rendering and Tcl/Tk for scripting.  
        C++ objects can be browsed and manipulated at runtime.  
        Currently at version 2003-09-03.
 Updated: 09/2003
 Contact: mailto:[email protected]

 What: OpenSpace
 Description: A discrete-event modeling and simulation package for developing
        autonomous agents.  It is designed to support
        contruction of distributed, interactive, multi-user, 3D
        shared environments, using VRML as the shape description language
        and OpenGL/Mesa as the rendering engine.  
        Requires TkSM (see , 
        Tk 7.4/Tk 4.0 or newer, and OpenGL.
 Contact: mailto:[email protected] (Irving Shang-Yi Hsu)

 What: polymer
 Description: Polymer Visualization System, written in Tcl/Tk.  Requires
        Togl and OpenGL or Mesa. The system has been built
        only on Sun SPARCs running Solaris 2.4/2.5.1 using Tcl7.6/Tk4.2
        and Togl 1.2. Both Sun's OpenGL and Mesa-1.2.8 have been used.
        It also uses the tiff lib.
 Updated: 10/1999
 Contact: mailto:[email protected] (S. F. Bellenot)
        mailto:[email protected] (Z.-H. Duan)

 What: Tecate
 Description: As described in Dr. Dobbs Journal, July 1997, Tecate is an
        extension of Tcl providing commands to interact with 3-D objects.
        Based on the OpenGL/Mesa library, Tecate provides the ability to
        create scriptable 3D browser applications.
 Updated: 08/1997
 Contact: mailto:[email protected] (Peter D. Kochevar)

 What: TIGER
 Description: Tcl-based Interpretative Graphics EnviRonment is a tool for
        programming OpenGL.  It has a Tcl extension for OpenGL 1.0,
        with integration of the Tk widget set, extensibile TIGER kernel,
        a Tk editor/soft debugger (in development), and a course for students
        to learn OpenGL.  Depends on Tcl 7.3.  
        Runs on Irix, SunOS, AIX, Linux, NetBSD, HPUX.  
        Not for professional or commercial usage without registration.
        Send the line "subscribe TIGER mailing list" to join the TIGER mailing
 Contact: mailto:[email protected] (Ekkehard 'Ekki' Beier)
        mailto:[email protected] (TIGER mailing list)

        To join the TIGER mailing list mailto:[email protected] 
        send a "subscribe TIGER mailing list" to
        mailto:[email protected] .

 Description: Tcl based Interpretative Graphics EnviRonment (TIGER) is
        a tool for interpretative graphics programming, providing a one to
        one binding for OpenGL 1.0.
 Updated: 04/1999
 Contact: mailto:[email protected]

 What: MAM/VRS (deprecated, see VRS below)
 Description: Library for animated interactive 3D graphics, written in
        C++.  Works on Unix (Linux, Solaris, Irix) and Windows 95/98/NT.
        Produces output for OpenGL/Mesa, POVRay, RenderMan, VRML.  
        Provides Xt (Motif/Lesstif/Athena), Qt, Tcl/Tk, MFC and GTk bindings.
        iMAM has a variety of interactive elements.
        Covered by GNU LGPL.
        Currently at version 2.2 Alpha.
 Updated: 06/2000
 Contact: mailto:[email protected]
        mailto:[email protected] (Tobias Gloth)


 What: iVRS (sucessor to MAM/VRS, see above).
 Description: Library for animated interactive 3D graphics, written in
        C++.  Works on Unix (Linux, Solaris, Irix) and Windows 95/98/NT.
        Produces output for OpenGL/Mesa, POVRay, RenderMan, VRML.  
        Provides Xt (Motif/Lesstif/Athena), Qt, Tcl/Tk, MFC and GTk bindings.
        iMAM has a variety of interactive elements.
        Covered by GNU LGPL.
        Currently at version 3.3.
 Updated: 07/2004
 Contact: mailto:[email protected]
        mailto:[email protected] (Juergen Doellner)
        mailto:[email protected] (Oliver Kersting)

 What: OpenGL context Tk widget
 Description: Tk widget that maintains an OpenGL context.
 Contact: mailto:[email protected] (Michael D. McCool)

 What: OpenGL Tk output widget
 Description: This Tk opengl widget allows integration of windows, having
        three-dimensional graphics output produced by OpenGl, into
        Tk applications.  It is available for Unix and Windows platforms.
 Updated: 06/1997
 Contact: mailto:[email protected] (Frank Wicht)

 What: TkOGL
 Where: ???
 Description: Prelim release of a Tk OpenGL binding.
        Tested under Linux with Mesa and on RS6000/AIX 3.2.5 with
        IBM OpenGL and Meta.  Requires Tcl/Tk.
        [[Are all these references to the same extension?]]
 Updated: 09/2003
 Contact: mailto:[email protected]

 What: Tkoglx
 Description: Experimental extension to support a small subset of
        Open GL.  Use tkGLX if you need everything.
        The one from princeton supports Tk 4.0 and 
        supports all possible visuals available from OpenGL.
 Contact: mailto:[email protected] (Dan Wallach)

 What: TkSM
 Where: (???)
 Description: A Mesa/OpenGL 3D modeling widget extension for Tcl 7.[45]/Tk.
        This provides no direct access to OpenGl routines.
        Includes VRML support, line and point models, material and
        normal bindings on a per-vertex basis.
        The umd files appear to be gone, but are present on the linux
        mirror site.
        The ospace page is a discrete-event modeling and simulation package
        for autonomous agents.  It requires TkSM.
 Updated: 11/2000
 Contact: mailto:[email protected] (Irving Hsu) (???)

 What: Togl
 Description: Togl allows for OpenGL rendering into a Tk widget.  It
        is based on Ben Bederson's OGLTK widget, but adds stereo rendering,
        color-index mode support, support for requesting stencil, accumulation
        alpha buffers, etc., multiple OpenGL drawing widgets, and OpenGL
        extension testing.  Togl works on Microsoft Windows, Mac OS X, and
        Linux/Unix X11.  Release 2.1 will add multisampling and pbuffer support.
 Updated: 02/2008
 Contact: mailto:[email protected] (Greg Couch)

 What: Frustum
 Description: Frustum is a TOGL 1.5 widget hacked to run scripts packaged with a SWIG
        wrapper for OpenGL, GLU and a few additional extensions.
 Updated: 02/2000

 What: Tom
 Description: Tom is an OpenGL wrapper for Tcl / Tk. About 90 % of OpenGL
  functionalities implemented, plus some GLUT functions. Both Linux and Windows supported. 
 Updated: 03/2004
 Contact: [email protected]

 What: Visualization Toolkit (VTk)
 Description: An object-oriented 3D visualization system
        written in C++ with full bindings for Tcl/Tk, Java and Python.
        It has rendering support for OpenGL, Starbase, GL, XGL, and X.
        It will run on UNIX, Windows96 and WindowsNT.
        This is the code from the Prentice Hall book
        "The Visualization Toolkit, an Object-Oriented Approach to 3D
        Graphics" (ISBN 013199837-4).  
        Current version is 5.0.2
 Updated: 07-Sep-2006  
 Contact: mailto:[email protected] (Kenneth M Martin)

Celtk - Antennavis: OpenGL antenna visualisation toolkit - tclvogle

Gdhe is a tool for 3D visualization of robotics applications.

It is totally programmable using the Tcl/Tk scripting language. It uses the OpenGL library to display the 3D primitives.

GDHE allows to build a 3D representation of the geometrical model of an environment and make it change with time. In order to achieve this, GDHE acts as a server that receives requests from a set of client processes. These requests describe the evolution of the model. Clients can be either modules that control a real system and that send data about the state of this system or simulation processes producing a simulated state of a virtual system.

OpenGL with C and Tcl/Tk : a simple widget from scratch (updated 2017 - supports Windows and Linux X11)

The Tcl-FAQ provided related information in its time.