VglTools is designed to provide a set of modules which perform functions and support entities in software which are normally found implemented in hardware in 3D graphics environments. VglTools is meant to be integrated into existing graphics software systems such as finite element post processors and visual data analysis (VDA) systems with minimal impact upon established data structures and low level graphics subsystems. The modules currently available in VglTools may be divided into 5 categories: 1) raster, 2) transformation 3) user interaction 4) utilities and 5) drawing function.
Bitmap Define bitmaps, line styles and stipples FBuffer Software frame buffer Texture Texture maps Pixelmap Device dependent frame buffer storage RasFont Raster font operations ZBuffer Z-buffer for hidden line and hidden surface removal
Xfm Define transformation matrix XfmStack Model and viewing transformations
IActor Object manipulation Popup Popup menus
Quadric Draw quadric surfaces
DataBuf Data rendering DrawFun Define functions pointers to graphics subsystem DFile Display file DList Display list DOpt Graphics primitive optimization DTee Display tee GDIDev Interface to Microsoft Windows OpenGLDev Interface to SGI OpenGL RendBuf Software rendering X11Dev Interface to X Windows
The most straight-forward application of VglTools involves the use of the graphics interface modules. Each module provides a uniform interface to a common 2D or 3D graphics API environment such as GL, OpenGL, X11, etc. For 3D APIs such as OpenGL, the interface modules are optimized to allow the API to maximize graphics hardware utilization. For 2D APIs such as X windows, operations such as z-buffering, transformation, lighting and color dithering are done in software using other VglTools modules.
Software scan conversion of points, lines, polygons and raster text occurs using the ZBuffer module. Polygon fill patterns and raster text may be defined using the Bitmap and RasFont modules respectively. The objects instanced from these modules are given to a ZBuffer object as attribute objects to control polygon filling and raster text generation.
In addition to the overall C preprocessor definitions described in section DevTools, Compiling and Linking a DevTools Application, there are four categories of C preprocessor definitions which are used to conditionally compile source code. The first category is the window system. Possible window system APIs are the following,
The Mesa 3D graphics library may accessed at the following URLVKI_WIND_WIN32 Microsoft Windows VKI_WIND_X11 X windows VKI_WIND_MESA Mesa windowless
http://www.mesa3d.org
The second category is the 3D graphics device interface API. The architectures for which the graphics device interfaces are allowed appear in parentheses.
The official support level of OpenGL on Windows is OpenGL 1.1. In order to use the vertex buffer objects, vertex array features and shader features of OpenGL in Windows it is recommended using GLEW, the OpenGL Extension Wrangler Library to enable more current versions of OpenGL. To compile support for this library define VKI_LIBAPI_GLEWVKI_3DAPI_OPENGL OpenGL (Any architecture)
This library may accessed at the following URLVKI_LIBAPI_GLEW OpenGL Extension Wrangler Library (Microsoft Windows)
http://www.glew.sourceforge.net
The third category is publicly available external library support for image file format reading and writing and font rendering. In some cases there are two options. The user may conditionally compile source to reference a user supplied installation of the external library or conditionally compile source to reference a modified version of the publicly available source which is delivered in the vgl/ext directory.
VKI_LIBAPI_JPEG JPEG user installed external library VKI_LIBAPI_PNG PNG user installed external library VKI_LIBAPI_TIFF TIFF user installed external library VKI_LIBAPI_FFMPEG FFMPEG user installed external library VKI_LIBAPI_FREETYPE FreeType user installed external library
The FFmpeg library may accessed at the following URLVKI_EXTAPI_JPEG JPEG vgl/ext/jpeg source VKI_EXTAPI_PNG PNG vgl/ext/png source VKI_EXTAPI_TIFF TIFF vgl/ext/tiff source
http://www.ffmpeg.org
The FreeType library may accessed at the following URL
http://www.freetype.org
The fourth category is used to configure the text drawing features of VglTools for single byte or double byte (wide) characters. The affected text drawing functions use a type of Vtchar for all string arguments which are configurable in this way.
If VKI_WIDECHAR is not defined, Vtchar is typedef'ed as char. If VKI_WIDECHAR is defined, Vtchar is typedef'ed as wchar_t. All Text and TextDC drawing functions contain Vtchar string arguments. In addition, all functions in the RasFont object which draw or manipulate text strings contain Vtchar string arguments. On Microsoft Windows platforms, it is required that the user define UNICODE if VKI_WIDECHAR is defined when compiling all application code.VKI_WIDECHAR Vtchar double byte
To use VglTools on a particular computer platform, the VglTools source must be compiled and linked to an application. Either the object files may be used
As an example of compiling VglTools on a SGI system create a directory SGI under lib to hold the final devtools.a archive file. Assume that X11 window system and OpenGL 3D graphics interfaces are desired. Then from the devtools/src/vgl directory compile using
creating .o files in the vgl directory. To place the object files in an archive file issuecc -c -O2 -ansi -DVKI_ARCH_SGI -DVKI_WIND_X11 -DVKI_3DAPI_OPENGL \\ -I.. *.c
The object files may be deleted after the devtools.a archive is successfully created. Place the devtools.a archive immediately before the display subsystem libraries in the load line. A devtools.a archive must be built for each computer platform using the methodology outlined above.ar rs ../../lib/SGI/devtools.a *.o
On Microsoft Windows platforms, if the OpenGL device interface is used, the final executable should be linked with the library opengl32.lib. The library vfw32.lib must be included to satisfy references to the audio visual interface (AVI) system.
Some modules are drawing function filters and other are renderers. The filter modules such as DList and DOpt accept drawing functions as input, perform some operation on the drawing function data and invoke drawing functions as output. The render modules act as a terminal point for drawing function data, accepting drawing functions as input and rendering to a hardware or software frame buffer as output. In this way a user can form a pipeline of drawing function objects to implement "immediate" mode rendering directly to a graphics device interface object or "retained" mode rendering through a drawing function object containing display list functions.
Currently, VglTools supports the graphics device interface modules in an X windows or Microsoft Windows environment. The user is responsible for opening the X window display and selecting a screen. Each graphics interface module which ultimately draws to an X window must be informed of the appropriate X window display and screen. When a user closes the X window display he should notify any graphics interface modules first so that they may release memory resources, etc. properly.
Complete HTML based guides to running vgltest.x and vglperf.x are located in the vgl/test/html directory. Use the root HTML files vgltest.htm and vglperf.htm with a Web browser.make vgltest make vglperf
#include "base/base.h" #include "vgl/vgl.h" /*---------------------------------------------------------------------- Hello World ----------------------------------------------------------------------*/ int main() { #ifdef VKI_WIND_X11 Display *display; int screen; #endif Vfloat x[3], c[3]; vgl_OpenGLDev *ogldev; vgl_DrawFun *df; /* connect to window system */ #ifdef VKI_WIND_X11 display = XOpenDisplay (0); screen = DefaultScreen (display); vgl_OpenGLDevConnectX (display,screen); #endif #ifdef VKI_WIND_WIN32 vgl_OpenGLDevConnectWIN (); #endif /* create drawing functions */ df = vgl_DrawFunBegin(); /* create device objects and load drawing functions */ ogldev = vgl_OpenGLDevBegin(); vgl_OpenGLDevDrawFun (ogldev,df); /* open windows */ vgl_DrawFunPositionWindow (df,400,400,400,300); vgl_DrawFunOpenWindow (df,"OpenGL window"); /* draw hello world in raster font */ vgl_DrawFunClear (df); c[0] = 1.; c[1] = 1.; c[2] = 1.; vgl_DrawFunColor (df,c); x[0] = 0.; x[1] = 0.; x[2] = 0.; vgl_DrawFunText (df,x,"Hello World"); vgl_DrawFunSwap (df); /* wait */ vgl_DrawFunDelay (df,5.); /* close windows */ vgl_DrawFunCloseWindow (df); /* free objects */ vgl_OpenGLDevEnd (ogldev); vgl_DrawFunEnd (df); /* disconnect from window system */ vgl_OpenGLDevDisconnect (); /* close X display */ #ifdef VKI_WIND_X11 XCloseDisplay (display); #endif return 0; }
A window is sized and opened and zbuffering is enabled. All colors are specified using red, green and blue color components. The window is cleared, and a white raster text title, a transparent white triangle, a double width magenta line and yellow raster text are drawn. The white triangle appears somewhat gray because of the 50 percent transparency against a black background. The function vgl_DrawFunSwap is used to ensure that all graphics primitives have been rendered to the window.
To terminate the graphics application, reverse the initialization procedure. The window is closed, objects deleted, the X11Dev module is disconnected from the X windows display and the X windows display is closed. The output from this example is shown in Figure 1-2 rendered on a grayscale PostScript device. The source to this example resides in file intro2.c in the exam directory. A C++ version is in file intro2cc.cxx.
#include "base/base.h" #include "vgl/vgl.h" static Vfloat xtri[3][3] = { {0.,.5,0.}, {.5,-.5,0.}, {-.5,-.5,0.} }; static Vfloat xlin[2][3] = { {-.7,0.,.1}, {.7,0.,.1 }}; static Vfloat xtex[3] = { -.9,-.6,.1 }; /*---------------------------------------------------------------------- Draw to an X11 Device ----------------------------------------------------------------------*/ int main() { Display *display; int screen; vgl_X11Dev *x11dev; vgl_DrawFun *df; Vfloat x[3], c[3]; /* open X display */ display = XOpenDisplay (0); screen = DefaultScreen (display); /* inform X device of display information */ vgl_X11DevConnectX (display,screen); /* create drawing function */ df = vgl_DrawFunBegin(); /* create X window device object */ x11dev = vgl_X11DevBegin(); /* load drawing functions for X device */ vgl_X11DevDrawFun (x11dev,df); /* request size and open window */ vgl_DrawFunPositionWindow (df,100,100,500,400); vgl_DrawFunOpenWindow (df,"X11 Device"); /* turn on zbuffering */ vgl_DrawFunSetMode (df,VGL_ZBUFFERMODE,VGL_OFF); /* clear window and draw text */ vgl_DrawFunClear (df); c[0] = 1.; c[1] = 1.; c[2] = 1.; vgl_DrawFunColor (df,c); x[0] = -.9; x[1] = .9; x[2] = 0.; vgl_DrawFunText (df,x,"Transparent triangle, wide line and raster text"); /* transparent triangle */ vgl_DrawFunTrans (df,.5); c[0] = 1.; c[1] = 1.; c[2] = 1.; vgl_DrawFunColor (df,c); vgl_DrawFunPolygon (df,VGL_POLYGON,3,xtri,VGL_NOSHADE,NULL); /* wide line */ c[0] = 0.; c[1] = 1.; c[2] = 1.; vgl_DrawFunLineWidth (df,2); vgl_DrawFunColor (df,c); vgl_DrawFunPolyLine (df,VGL_LINESTRIP,2,xlin); /* text strings */ c[0] = 1.; c[1] = 1.; c[2] = 0.; vgl_DrawFunColor (df,c); vgl_DrawFunText (df,xtex,"!#$%&''()*+,-./0123456789:;<=>?@"); xtex[1] -= .15; vgl_DrawFunText (df,xtex,"ABCDEFGHIJKLMNOPQRSTUVWXYZ[[]^_`"); xtex[1] -= .15; vgl_DrawFunText (df,xtex,"abcdefghijklmnopqrstuvwxyz{|}~"); /* make sure window is current */ vgl_DrawFunSwap (df); /* wait a bit */ vgl_DrawFunDelay (df,10.); /* close window */ vgl_DrawFunCloseWindow (df); /* delete objects */ vgl_X11DevEnd (x11dev); vgl_DrawFunEnd (df); /* disconnect from X */ vgl_X11DevDisconnect (); /* close X display */ XCloseDisplay (display); return 0; }