Scriptive OpenGL Rendering. XBit has implemented a Tcl shell for OpenGL primatives at Windows platforms. The implementation focuses on scriptive programing in OpenGL rendering with an emphasis on code reusability and GUI. It provides an OpenGL rendering engine whose states can be changed with a greater flexibility during execution. Many C codes of OpenGL primitives have been kept in a similar symbolic syntax in Tcl in order to achieve the maximum reusability of the existing C programs. For those who are familiar with programing in C for OpenGL rendering may convert their C code to Tcl with a benefit of greatly simplified GUI. For those who are learning OpenGL may find the XBit's Tcl shell an easy-to-use tool to grasp OpenGL primitives. The current implementation tries to boost the applications of Tk widgets with 3D rendering capabilities of OpenGL. Rendering Context Suite. A widget or an image with an associated rendering context (RC) makes a rendering context suite. A Tk widget or image is capable of drawing graphics. In order to draw rendering result into a widget or an image, a rendering context (RC) is required. However, RC is not supported by every widget that is created in Windows. Only those widgets that have their own device context (DC) will be able to support a RC of OpenGL. Widgets of Tk 4.2 are able to support RC of OpenGL because every widget has its own DC. Widgets of Tk8.0 and later have been registered with a window class of a shared DC and are unable to support a RC required for OpenGL rendering. A general solution is to provide a widget that has its own DC. Another solution is to provide a Tk image type that supports OpenGL rendering and can be used in any Tk widgets that uses a Tk image. XBit provides both solutions with a widget command glw and an image type glw. For examples, glw widgetName creates a widget for OpenGL rendering and image create glw imgName creates an image for OpenGL rendering. Table. Tcl commands for OpenGL widget/image manipulation.
Rendering Context Switching. OpenGL rendering in multiple widgets/images requires switching RCs among these widgets/images. A Tcl command glw current widgetName/imgName switches the current OpenGL RC to the widget/image identified by widgetName/imgName. After a successful RC switching, the command returns the name of a previous widget/image so that its RC can be restored after drawing the current widget/image. A successful RC switching among multiple widgets/images can be implemented with a sandwiched usage of the glw current command, i.e., calling glw current at the entry and exit of a Tcl procedure to switch and restore the RCs respectively. A typical implementation of scriptive programing is to writing a procedure sandwiched with glw current. For example, proc foo {pathName args} {
RC Associated Variables. To optimize and enhance scriptive OpenGL rendering, XBit provides a suite of Tcl commands such as GLdouble, GLfloat, GLint and etc. to create corresponding OpenGL data variables associated with the current RC. The scope of these private variables is defined by the current RC rather than the procedure's scope where they are created. The scope will be changed when a RC switching occurs. Use of private variables significantly eliminate the redundancy of converting parameter values from strings to their internal binary formats. Utility commands such as glset, glv, gldel and etc. are also provided to set the value of a variable, get the value of a variable and delete the variable associated with the current RC. When a RC is destroyed, the memories of all the associated variables will be garbage-collected. Table. Tcl commands for OpenGL private variable manipulation.
Attaching A RC To A Widget. The widget for OpenGL rendering needs to have its own DC. In another words, a widget that has its own DC may be attached with a RC for OpenGL rendering. When the command glw is called, it first checks to see if the widget identified by the pathname exists. If the widget does exist, but is not a GLW widget (i.e., a regular Tk widget), the glw command will try to attach a RC to it. After a successful RC attachment, a regular Tk widget may be used for OpenGL rendering. For example, the following scripts frame .frame
will create a regular frame widget and then attach an OpenGL RC to it. The following OpenGL rendering will display the result in the frame widget .frame. If the attched widget is a canvas, the rendering result will be displayed at the bottom layer with all other items on its top. This will work with Tk 4.2 since every widget of Tk4.2 has its own DC. For Tk8.0 or later, XBit will try to re-register a window class for Tk such that a Tk widget has its own DC. Such an attempt may be successful if the dynamic link library of XBit is loaded before the main Tk window is created. For example, if the XBit DLL is loaded with scripts invoked via a wish's command line, a re-register process will be successfully done before the main Tk window is created. Modular
GUI To 3D Rendering. GUI programing for OpenGL rendering can
achieve greater modularity following a Tk widget binding approach.
A widget provides a unique identity to which corresponding procedures may
be bound to various events in an interactive manipulation. Procedures
associated with an object of OpenGL rendering usually includes the following
procedures:
Choice Of Script/C Programing. Since OpenGL is a state machine, scriptive rendering may become as efficient as with compiled C codes. This is true especially when OpenGL lists are used. On the other hand, Tcl is very efficient in handling scripts, resulting in satisfied performance in many cases. Therefore, Tcl scriptive OpenGL rendering is a very attractive choice. However, there are applications where a rendering process involves heavy calculation or data initialization before OpenGL primitives can be called to configurate the state machine. In such cases, Tcl commands in compiled C codes are more efficient than Tcl scripts. Mixed coding with both scripts and compiled Tcl commands of C language usually results in efficient programing for OpenGL rendering. Sometime there is a need to convert a program between Tcl scripts and C languages. Since XBit's OpenGL scripts are very similar to C function calls, converting between scripts and C codes is almost straightforward. |
object rendering objct rendering object rendering Grand Canyon - A GLW widget rendering rendering rendering with multiple texture |