|
|
The IGL (IGPM Graphics Library)
|  |
Purposes
The IGL is a small cross-platform C++-library for displaying everyday-tasks in
mathematics and provides a multithreaded C++-Interface for
GLUT.
At the IGPM it is used for generating graphical output of numerical
implementations (solving equations, integration, splines, etc.) in a beginners
C++-Programming Tutorial. Providing an object-oriented abstraction layer for
openGL (which has become the cross-platform standard for almost all operation
systems) it offers the basic functionality of rendered vectorgraphics. On the
other hand it has a small User-Interface that satisfies
the needs for a novice C++-Programmer. IGL is designed for displaying
static Graphics, if you are looking for an advanced environment that also
allows real-time rendering, GLT
might be a better choice.
Interface and Implementation
Roughly spoken, IGL serves as a object-orientated Wrapper for GLUT. The
context-orientation (said to be the "poor man's object orientation") of
the window management is wrapped by creating an object for each window-context
comprising all the data and callback-functions needed.
The Design of IGL differentiates between the Interface, the
IGLWin-Object (declared in the 'public' header
IGL.h, defined in
IGLWin.cpp) and the Implementation, the
BaseWin-Object (declared in
BaseWin.h, defined in
BaseWin.cpp).
The two Objects communicate through a tiny Event-System as noted below.
Event-Handling
When IGLWin receives a method call (for example
Line2D(0,0,1,1);) it generates an event (in this case a
CmdObj) and appends it to the corresponding queue (in this
case the drawQueue) of BaseWin.
BaseWin has two queues, the cmdQueue and the
drawQueue. The cmdQueue stores the Window-Operations
(Open, Close, Clear, Resize, Redraw) represented by CmdWin and is
emptied every WINDOW_REFRESH_TIME (defaults to 0.1s) by a
timer-function. The drawQueue stores all the drawing Commands and
keeps them until a Clr (via cmdQueue) is issued.
Whenever the Window needs to be redrawn, the drawQueue is
iterated (but not emptied) and each Command (CmdObj or
CmdSetProp) is executed. Whether a window needs to be redrawn is
determined by the GLUT Event-System, to which control has been handed over by
glutMainLoop().
The IGLoop
The object-oriented wrapper of the glutMainLoop() call is
the IGLoop (IGLoop.h,
IGLoop.cpp). This is a private
static variable of IGLWin which is initialized, when its
first Instance is constructed. It then creates a separate thread and
calls the never-returning glutMainLoop() which issues all
the window-related callback-function calls of GLUT.
For bootstrapping, an invisible dummy window has to be created,
which is a private member of IGLoop and plays no further
role after initialization.
Threading issues
Because GLUT is not thread-safe, all operations of BaseWin
which change the state variables of GLUT (e.g. glutSetWindow())
have to be executed synchronized with glutMainLoop(). This means,
that they must be implemented in callbacks, either event-driven
(e.g. glutDisplayFunc) or by timer (glutTimerFunc)
Feedback
If all this is of any use to you, I would be happy for a short
comment.
|