$ wish % load ./libtom.so
OpenGL procs and variables are defined in the ::GL namespace. As you can see when comparing simple.tcl and more_simple.tcl files, it can be boring to type ::GL:: before every call to OpenGL procs. The first thing to do to avoid that is to import ::GL namespace :
% namespace import ::GL::*
When starting, there's no current context, and a call to an OpenGL proc will produce an error :
% glClearColor 0.0 0.0 0.0 0.0 error: no current context
By default, OpenGL widget creation initializes the current context to this widget :
% tom current % tom .gl1 .gl1 % tom current .gl1
It is possible to control context initialisation with -current option :
% tom .gl2 -current 0 .gl2 % tom current .gl1 % .gl2 makecurrent % tom current .gl2
There are other options when creating a new widget : -width (0), -height (0), -doublebuffer (0), -alpha (0), -direct (1), -depth (0) and -share (NULL).
When there is a current context, OpenGL procs are accessible and apply to it. To clear .gl1 with black and .gl2 with white :
% .gl1 makecurrent % glClearColor 0.0 0.0 0.0 0.0 % .gl2 makecurrent % glClearColor 1.0 1.0 1.0 0.0
Then, display result on screen :
% proc display {w} { $w makecurrent glClear $GL::GL_COLOR_BUFFER_BIT } % proc reshape {w width height} { $w makecurrent glViewport 0 0 $width $height } % bind .gl1 <Configure> {reshape %W %w %h} % bind .gl2 <Configure> {reshape %W %w %h} % bind .gl1 <Expose> {display %W} % bind .gl2 <Expose> {display %W} % pack .gl1 .gl2 -fill both -expand 1