Home
Tcl3D: Doing 3D with Tcl
Contents
1. The next lines show an example of SWIG s pointer encoding set theNurb gluNewNurbsRenderer puts StheNurb _10fa1500 p GLUnurbs The returned name can only be used in functions expecting a pointer to the appropriate struct 3 1 5 Exceptions from the standard rules The GLU library as specified in header file glu h does not provide an API that is using the const specifier as consistent as the GL core library So one class of function parameters TYPE is handled differently with GLU functions Arguments of type TYPE are used both as input and output parameters in the C version In GLU 1 2 most functions use this type as input parameter Only two functions use this type as an output parameter Tcl3D User Manual Version 0 4 1 August 2009 Page 22 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 3 Wrapping in detail Tcl3D Doing 3D with Tcl So for GLU functions there is the exception that TyPE is considered an input parameter and therefore is wrapped as a Tcl list Input parameter TYPE GLU onl void gluNurbsCurve GLUnurbs nobj GLint nknots C decl ti GLfloat knot GLint stride eclaration GLfloat ctlarray GLint order GLenum type float rvePt 4 2 0 25 0 5 0 25 0 75 075r OTS A075 Os SF C float rveKnots 8 0 0 0 0 0 0 0 0 amps 1 0 1 0 1 0 1 0 uNurbsCurve theNurb 8 curveKnots 2 amp curvePt 0 0 4
2. tcl3dcg 0 4 1 2 2 0006 tcl3dftgl Ov4 d 2 1 2 tcl3dgauges 1 0 4 1 tcl3dgl2ps 0 4 1 1 3 3 tcl3dode 0 4 1 0 7 0 tcl3dogl 0 4 1 1 2 APPLE 1 4 56 tcl3dosg 0 4 1 2 8 2 tcl3dsdl 0 4 1 1 2 9 2 3 Extending Tcl3D 2 3 1 General information Each optional module wrapping a library eg SDL has to have at least 2 files in folder tclfiles pkgindex tcl and tcl3dPKGQuery tcl The latter file contains procedures to query functionality related to the package All procedures contained in this file must be able to work even if the corresponding dynamic library does not exist or is just a dummy This file must be loaded in pkgindex tcl before the dynamic library All other package related Tcl files should be loaded after the dynamic library 2 3 2 Extending with a Tcl utility 2 3 3 Extending with a C C utility 2 3 4 Extending with a newer version of an external library 2 3 5 Extending with a new external library Tcl3D User Manual Version 0 4 1 August 2009 Page 18 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 3 Wrapping in detail Tcl3D Doing 3D with Tcl 3 Wrapping in detail This chapter explains how parameters and return values of the C and C based library functions are mapped to Tcl command parameters and return values The intention of the wrapping mechanism was to be as close to the C interface and use Tcl standard types wherever possible e C f
3. EdgeFlag GLboolean flag ag GL TRUE Table 3 4 Wrapping of a GLboolean input parameter 3 1 2 Pointer input parameters The mapping of const TYPE pointers is handled in file tel3dPointer i Constant pointers as function input parameter must be supplied as a Tcl list const TYPE SIZE const TYPE void glMaterialfv GLenum face GLenum pname const GLfloat params GLfloat mat diffuse 0 7 0 7 0 7 1 0 glMaterialfv GL FRONT GL DIFFUSE mat diffuse set mat diffuse 0 7 0 7 0 7 1 0 glMaterialfv GL FRONT GL DIFFUSE Smat diffuse Table 3 5 Wrapping of a pointer input parameter Copyright 2005 2009 by Paul Obermeier All rights reserved Tcl3D User Manual Version 0 4 1 August 2009 Page 20 of 65 3 Wrapping in detail Tcl3D Doing 3D with Tcl Note e This type of parameter is typically used to specify small vectors 2D 3D and 4D as well as control points for NURBS e Unlike in the C version specifying data with the scalar version of a function ex glVertex3f is faster than the vector version ex g1Vertex3fv in Tcl e Tcl lists given as parameters to a Tcl3D function have to be flat i e they are not allowed to contain sublists When working with lists of lists you have to flatten the list before supplying it as an input parameter to a Tcl3D function One way to do this is shown in the example below set ctrlpoints 4 0 4 0 0
4. 2005 2009 by Paul Obermeier All rights reserved 8 References Tcl3D Doing 3D with Tcl 8 References Tcl3D specific references 1 Tcl3D homepage http www tcl3d org 2 Tcl3D page on the Tclers Wiki http wiki tcl tk 15278 3 Tcl3D discussion page on the Tclers Wiki http wiki tcl tk 16057 4 Tcl3D Demo of the month page on the Tclers Wiki http wiki tcl tk 17771 5 Tcl3D Reference Manual http www tcl3d org html docs html Libraries wrapped with Tcl3D 6 Togl page at SourceForge http sourceforge net projects togl 7 Cg download http developer nvidia com object cg_toolkit html 3 SDL download http www libsdl org 9 FTGL download http nomepages paradise net nz henryj code index html 10 Freetype download http www freetype org 11 GL2PS download http www geuz org gl2ps 12 ODE download http www ode org 13 OSG download http www openscenegraph org 14 GLEW http glew sourceforge net 15 GLsdk library http oss sgi com projects ogl sample sdk html Demos used in TclI3D 16 NeHe s tutorials http nehe gamedev net 17 Kevin Harris code samples http www codesampler com oglsrc htm 18 Vahid Kazemi s GameProgrammer page http www gameprogrammer org 19 Nate Robins OpenGL tutorials http www xmission com nate tutors html 20 The Redbook sources http Awww opengl red
5. See the demo program ftg Demo tcl for an example on how to use the trackball procedures See the NeHe demo program Lesson48 tcl for an example on how to use the ArcBall procedures Implementation details The functionality of the trackball module is implemented in the following files Implementation files tcel3dUtilTrackball c tcl3dUtilTrackball tcl Header files tcl3dUtilTrackball h Wrapper files util i The functionality of the ArcBall module is implemented in the following files Implementation files tcl3dUtilArcBall c Header files tcl3dUtilArcBall h Wrapper files utili 4 3 12 C based utilities for demo applications This sub module implements C based utility functions for some of the demo applications Overview tcl3dDemoOgILogo implements an animated 3 dimensional OpenGL logo It is used in demo animlogo tel in directory LibrarySpecificDemos tcl3dOg I tcl3dDemoReadRedBooklmg implements a parser for the simple image file format used in some of the RedBook demos It is used in demos colormatrix tcl colortable tcl convolution tcl histogram tcl and minmax tel in directory TutorialsAndBooks RedBook tcl3dHeightmap implements a converter from a Tk photo image into a heightmap It is used in NeHe demo Lesson45 tcl in directory TutorialsAndBooks NeHe Implementation details The functionality of the OpenGL logo animation is implemented in the following files Implementation files tcl3dDemoOglLogo c Heade
6. The OS X port is tested on a MacBook only with limited graphics capabilities 1 5 Getting started The easiest way to get started is using a Tcl3D starpack Starpacks for Windows Linux IRIX and Mac OS X Intel based can be downloaded from http www tcl3d org See chapter 2 for a detailed information about all available Tcl3D distribution packages The only prerequisite needed for using the Tcl3D starpack distribution is an installed OpenGL driver Everything else even the Tcl interpreter is contained in the starpack The starpacks are distributed as a ZlIP compressed file Unzipping this file creates a directory containing the starpack tcl3dsh OS VERSION Distributions for Unix systems contain an additional shell script tcl3dsh OS VERSION sh which should be used for starting the Tcl3D starpack After starting the starpack a toplevel Tk window labeled Tc13D as well as a console window labeled Tc13D Console should appear similar to starting a wish shell The console window should contain the following usage message as well as a tcl3d prompt Type pres to start Tcl3D presentation Type inst to write the Tcl3D installation packages to disk Nove The OpenSceneGraph library and demos are not included in this presentation tcl3d gt Typing pres in the console window starts the Tcl3D presentation showing an introductionary animation as shown in the screenshot below The available key and mouse bi
7. render swapbuffers makecurrent postredisplay loadbitmapfont unloadbitmapfont Bitmap fonts Specifying bitmap fonts can be accomplished with the loadbitmapfont command The font can either be specified in XLFD format or Tk like with the following options family courier times weight medium bold slant regular italic size PixelSize Examples Stoglwin loadbitmapfont courier bold r 10 toglwin loadbitmapfont family fixed size 12 weight medium slant regular Tcl3D User Manual Version 0 4 1 August 2009 Page 25 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl See the tcl3dToglFonts tcl and tcl3dFont tcl demos for more examples on how to use fonts with Togl 4 1 2 Togl options The following is a list of currently available Togl options The options changed or new in Tcl3D are marked bold and explained in detail below For a description of the other options see the original Tog documentation height width setgrid rgba redsize greensize bluesize double depth depthsize accum accumredsize accumgreensize accumbluesize accumalphasize alpha alphasize stencil stencilsize auxbuffers privatecmap overlay stereo cursor time sharelist sharecontext ident indirect pixelformat swapinterval multisamplebuffers multisamplesamples createproc displayproc reshapeproc These configurat
8. tcl3dName2Hexa white returns FFFFFFFE tcl3dName2rgb white returns 255 255 255 tcl3dRgb2Name 255 255 255 returns FFFFFE tcl3dName2rgba white returns 255 255 255 255 tcl3dRgba2Name 255 255 255 255 returns FFFFFFFE tcl3dName2rgbf white returns 1 0 1 0 1 0 tcl3dRgbf2Name 1 0 1 0 1 0 returns FFFFFF tcl3dName2rgbaf white returns 1 0 1 0 1 0 1 0 tcl3dRgbaf2Name 1 0 1 0 1 0 1 0 returns FFFFFFFEF tcl3dName2rgb 0a0c0e returns 10 12 14 Implementation details The functionality of this module is implemented in the following files Tcl3D User Manual Version 0 4 1 August 2009 Page 36 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Implementation files tcl3dUtilColors tcl Header files None Wrapper files None 4 3 5 Large data module This module provides miscellaneous functions for handling large data like textures and vertex arrays Overview The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter tcl tor tcl3dvecto Create a new Tcl3D Vector by calling the low level memory allocation routine new_TYPE and create a new Tcl procedure See example below La a St eNO et ae Peco obey Create a new T
9. More detailed information can be obtained by using the tcl3dInfo tcl script located in the demos directory in category Tcl3DSpecific The help and documentation menu gives you some online information about how to use the Tcl3D presentation framework The demo and tutorials menu has lots of sample programs divided into 3 categories e Library specific demos contains scripts showing features specific to the wrapped library e Tutorials and books contains scripts which have been converted from C to Tcl3D coming from the following sources OpenGL Red Book NeHe tutorials Kevin Harris CodeSampler web site Vahid Kazemi s GameProgrammer page e Tcl3D specific demos contains scripts demonstrating and testing Tcl3D specific features Some notes about the demos contained in the starpack OpenSceneGraph related demos are not included in the starpack Depending on your operating system graphics card and driver some of the programs may raise an error message or will not work properly As the demos contained within the starpack were written to be standalone programs no error recovery was implemented The programs typically just quit This is why you may get a confirmation window from time to time asking you if you want to quit the presentation In most cases you may proceed with other demos but be warned that strange effects may occur Tcl3D User Manual Version 0 4 1 August 2009 Page 9 of 65 Copyright 2005 2009 by Paul Oberm
10. commands e SWIG versions up to 1 3 24 had an annoying but not critical bug in the Tcl library file swigtcl8 swg Please check if your version has a line printf Searching s n key in function SWIG Tcl _GetConstant and delete this line if existent Tcl3D User Manual Version 0 4 1 August 2009 Page 55 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 5 Miscellaneous TcI3D information Tcl3D Doing 3D with Tcl swigtcl8 swg can be found in usr lib swig1 3 tcl or usr share swig VERSION tcl on Linux or in the lib tcl subdirectory of your SWIG Windows installation e SWIG version 1 3 21 as delivered with SUSE 9 3 does not correctly wrap the ODE library e The PDF files generated with Gl2ps are not displayed correctly with the Preview program on a Mac Acrobat Reader displays them correctly e tcl3d0glGetVersion and tcl3d0glGetPackageInfo dump core on Mac OSX if no Togl window has been created On other systems the function returns an empty string in that case See also the note about glGetString in chapter 4 2 5 5 Starpack internals For an introduction to Tclkits starkits and starpacks see Jean Claude Wippler s homepage at http www equi4 com 5 5 1 Starpack issue 1 If shipping external libraries with your starpack you have to copy them to the file system before they can be used A convenient place is the directory containing the starpack Check if all necessary
11. 1 Svec set Sindex val Set the elements with the tcl3dVector object method set Most elegant way but also the slowest Only useful for small vectors Method 2 s type setitem vec Sindex val Set the elements with the tcl3dVector low level function setitem Not so elegant because you need to know the type of the vector but much faster than method 1 Method 3 tcl3dListToVector type list vec len Set the elements with the low level functions tcl3dListToVector_TYPE introduced in Tcl3D 0 3 3 Not so elegant because you need to know the type of the tcl3dVector and you have to build a Tcl list before setting the tcl3dVector This is the fastest way Method 4 set vec tcl3dVectorFromList type list Set the elements with the utility function tcl3dVectorFromList which internally calls the low level functions tcl3dListToVector_TYPE You don t have to care about allocating a tcl3dVector of approriate size This is only slightly slower than method3 The test program vectorspeed tcl implements the above mentioned four different methods and shows output similar to the following lines Tcl3D User Manual Version 0 4 1 August 2009 Page 40 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl D tcl3d tcl3d0gl tests gt tclsh vectorspeed tcl Number of runs 100 Size of vectors 1000 Setting 100000 elements per method SetMethod1l 25339 3 microsecond
12. 1 Introduction Tcl3D Doing 3D with Tcl y 2 tct3d0 4 1 w 2 tecl3dsDL _ tcl3dSDLUtil tcl _ tcl3dSDLQuery tcl E tcl3dSDL dylib pkgindex tcl L tcl3dOsg L tcl3dOgl 3 tcl3dOde L tcl3dGi2ps I tcl3dGauges 9 tel3dFTGL 3 tcl3dCg EE pkgindex tcl Figure 1 1 Tcl3D package layout TvvvvVvy The next figure shows the currently available modules of Tcl3D The Tcl3D Modules tcl3dGauges Tcl Extension Package SWIG generated Tcl interfaces Tcl Interface B tcl3dCg tcl3dSDL tcl3dFTGL Cg Shading Joystick and CD Font Rendering tcl3dGI2ps tcl3dOde tcl3dOsg OpenGL to PS PDF Physics Engine OpenSceneGraph Figure 1 2 Overview of TcI3D modules 1 2 Modules overview This chapter gives a short overview of the modules available in Tcl3D 1 2 1 Tcl3D core module The Tcl3D core module tc 3dOg consists of the following 3 sub modules e Togl e OpenGL Tcl3D User Manual Version 0 4 1 August 2009 Page 3 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 1 Introduction Tcl3D Doing 3D with Tcl til Note e The Tcl3D core module is free of C code since version 0 4 0 Togl Enhanced Togl widget This sub module is an enhanced version of the Togli 6 widget a Tk widget for displaying OpenGL graphics The following enhancements are currently implemented e Callback functions in Tcl e Better bitmap font support e Multisampling support
13. GLenum pname GLint param It is called in C typically ae follows lTexParameteri GL TEXTURE 2D GL TEXTU GL TEXTU Po E WRAP _S GL_ REPEAT E MAG FILTER GL _ NEAREST 7m Ge ernie eee ty A As the 3 parameter is not of type GLenum you have to specify the numerical value in Tcl glTexParameteri GL TEXTURE 2D GL TEXTURE WRAP S GL_REPEAT glTexParameteri GL TEXTURE 2D GL TEXTURE MAG FILTER GL_NEAREST If called with the enumeration name IT _TEXTURE_2D GL TEXTURE WRAP S GL REPEAT lTexParameteri GL you will get the above error message Hint 4 Error expected floating point number but got 08201905 p float This error message indicates that a tcl3dVector has been specified as parameter to a function which expects a Tcl list This often happens when using one of the glMultMatrix commands Use a sequence like shown below to convert the tcl3dVector into a Tcl list before supplying it to the function set matAsList tcl3dVectorToList mat 16 glMultMatrixf SmatAsList Hint 5 Error Package tcl3dcg couldn t load library C Tcl lib tcl3d tcl3dCg tcl3dCg dll this library or a dependent library could not be found in library path This typically indicates that the dependent library or libraries ex cg dil or cgGL
14. Information component e File utility component Tcl3D User Manual Version 0 4 1 August 2009 Page 31 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Color names component Large data component tcl3dVector Image utility component Screen capture component Timing component Random number component 3D model and shapes component Virtual trackball and arcball component C C based utilities for demo applications Requirements for this module None all files are contained in the Tcl3D distribution The master SWIG file for wrapping the utility library is util i 4 3 1 3D vector and transformation matrix module This module provides miscellaneous 3D vector and 4x4 transformation matrix functions Overview The following tables list the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Tcl command Description L3dVvec3 Print the contents of a 3D vector onto standard output Compare Compare two 3D vectors tcl3dVec3 Fill a 3D vector with 0 0 0 0 0 0 tcl3dVec3fCopy Copy a 3D vector tcl3dVvec3fLength Calculate the length of a 3D vector 3dVec3f Normalize Normalise a 3D vector tel Calculate the distance between two 3D vectors tcl3dVec3f Dot Product Calculate
15. Tcl Interface tcl3dCg tcl3dSDL tcl3dFTGL Cg Shading Joystick and CD Font Rendering tel3dGI2ps tcl3dOde tcl3dDemouUtil OpenGL to PS PDF Physics Engine C utilities for demos Tcl3D Version 0 2 Released 2006 01 07 Major rewrite and support of new libraries OpenGL 2 0 OpenGL extensions Cg SDL gauges Domain created Tcl3D Demos and Applications tcl3dGauges Tcl Extension Package SWIG generated Tcl interfaces Tel Interface Tcl3D Version 0 3 1 Released 2006 06 16 Support for GL2PS and ODE alpha added Starpack versions Tcl3D Demos and Applications tcl3dGauges Tcl Extension Package SWIG generated Tcl interfaces Tcl Interface tel3dCg tel3dSDL Cg Shading Joystick and CD Font Rendering tel3dGI2ps tcl3dOde OpenGL to PS PDF Physics Engine Tcl3D Version 0 3 3 Released 2008 09 14 Bug fixes minor enhancements and several new demos Tcl3D Demos and Applications tcl3dGauges Tcl Extension Package SWIG generated Tcl interfaces Tcl Interface tel3di tcl3dSDL tcl3dFTGL Cg Shading Joystick and CD Font Rendering tel3dGI2ps tcl3dOde tcl3dDemouUtil OpenGL to PS PDF Physics Engine C utilities for demos Tcl3D User Manual Version 0 4 1 August 2009 Copyright 2005 2009 by Paul Obermeier All rights reserved Page 59 of 65 7 Release notes Tcl3D Doing 3D with Tcl Tcl3D Version 0 4 0 Tcl3D Version 0 4 1 Released 2008 12 30 OpenGL wrapping based on GLEW 1 5 1 Support of Op
16. code is copyrighted by Mark Kilgard The original code of tcl3dSphere is copyrighted by Paul Bourke The original code of tcl3dHelix is copyrighted by Dario Corno The original code of tcl3dArcBall is copyrighted by Tatewake com The original code of tcl3dTrackball is copyrighted by Gavin Bell et al The Tcl3D gauge library is copyrighted by Victor G Bonilla and distributed under the BSD license The original Togl widget is copyrighted by Brian Paul and Benjamin Bederson and distributed under the BSD license see http sourceforge net projects togl The modified Tcl3D version of Togl is copyrighted by Paul Obermeier and distributed under the BSD license See the following table of wrapped unmodified libraries for their license conditions Library License More information GLEW Modified BSD license http glew sourceforge net glew txt Cg Redistributable license http developer nvidia com object cg_toolkit html see file license pdf in Cg installation FTGL LGPL http sourceforge net projects ftgl Freetype Freetype License BSD style http www freetype org FTL TXT GL2PS LGPL See file COPYING GL2PS in directory tcl3dGl2ps ODE BSD http www ode org ode license html OSG OpenSceneGraph Public License http Awww openscenegraph org projects osg attachment LGPL style wiki Legal LICENSE txt SDL LGPL http www libsdl org license Igpl php Table 5 1 License information of
17. directory demos OpenSceneGraph for examples on how to use the OSG functions 4 10 tcl3dGauges Tcl3D package for displaying gauges This package implements the following gauges airspeed altimeter compass tiltmeter This is an optional module Requirements for this module None all files are contained in the Tcl3D distribution The gauge package has been implemented by Victor G Bonilla See the demo programs gaugedemo tcl and gaugetest tcl for examples on how to use the gauges Tcl3D User Manual Version 0 4 1 August 2009 Page 52 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 5 Miscellaneous Tcl3D information Tcl3D Doing 3D with Tcl 5 Miscellaneous Tcl3D information This chapter contains miscellaneous information about Tcl3D e License information Programming hints Open issues Known bugs Starpack internals 5 1 License information The SWIG wrapper files as well as the C and Tcl utility files of all modules are copyrighted by Paul Obermeier and distributed under the BSD license See below for exceptions regarding single files and the external libraries The Tcl3D utility library files see below for exceptions are copyrighted by Paul Obermeier and distributed under the BSD license The following files of the Tcl3D utility library have differing copyrights The original Wavefront parser code is copyrighted by Nate Robins The original GLUT shape
18. e Swap Interval support A detailed description of this sub module can be found in chapter 4 1 OpenGL Wrapper for OpenGL functionality This sub module wraps OpenGL functionality up to OpenGL Version 3 0 the GLU library functions based on Version 1 2 and most of the available OpenGL extensions It is implemented with the help of the GLEW 14 library Standard shapes box sphere cylinder teapot with a GLUT compatible syntax are supplied here too A detailed description of this sub module can be found in chapter 4 2 Util Tcl3D utility library This sub module implements C and Tcl utilities offering basic functionality needed for 3D programs It currently consists of the following components 3D vector and transformation matrix component Information component File utility component Color names component Large data component tcl3dVector Image utility component Screen capture component Timing component Random number component 3D model and shapes component Virtual track and arcball component C based utility functions for some of the demo applications A detailed description of this sub module can be found in chapter 4 3 1 2 2 Tcl3D optional modules The following Tcl3D optional modules are currently available e tcl3dCg tcl3dSDL tcl3dFTGL tcl3dGl2ps tcl3dO0de tcl3dOsg tcl3dGauges Tcl3D User Manual Version 0 4 1 August 2009 Page 4 of 65 Copyright 2005 2009 by Paul Obermeier All rights r
19. external libraries exists in the directory containing the starpack Copy them to the filesystem if necessary set _tcl3dExecDir file dirname starkit topdir set _ tcl3dD11lList glob nocomplain dir file join starkit topdir extlibs info sharedlibextension foreach starkitName tcl3dDllList set osName file join tcl3dExecDir file tail starkitName if file exists SosName set retVal catch file copy force starkitName tcl3dExecDir puts Copying DLL starkitName to directory tcl3dExecDir if retVal 0 error Error copying DLL starkitName to directory _ tcl3dExecDir This aforementioned solution seems to be the best possible solution today but has the following two disadvantages e Windows user will typically place the starpack onto the desktop Starting the starpack inflates the desktop with lots of DLL s e On Linux Unix the current directory typically is not included in the LD_LIBRARY_PATH variable That s why the starpacks are distributed in it s own folder and the Unix distributions come with an additional start shell script tcl 3dsh OS VERSION sh bin sh Startup script for tcl3dsh the Tcl3D starpack Unix iD LIBRARY PATH LD LIBRARY PATH IRIX D LIBRARYN32_PATH LD LIBRARYN32_ PATH Darwin DYLD LIBRARY PATH DYLD LIBRARY PATH Tcl3D User Manual Version 0 4 1 August 2009 Page 56 of 65 Copyr
20. generate screenshots from the Tcl3D presentation the Twapi extension is needed on Windows It is therefore recommended to use an ActiveTcl distribution 24 which contains all of the above listed Tcl extensions To build the Tcl3D modules from source the following additional tools need to be installed and accessable from the command line GNU make http www gnu org SWIG gt 1 3 38 http www swig org Table 2 2 Tools for building Tcl3D Note e A binary version of SWIG for IRIX is available from my private home page http www posoft de e Tcl3D prior to version 0 4 1 has been successfully generated and tested with SWIG versions 1 3 24 1 3 29 and 1 3 36 e For wrapping the OpenSceneGraph library SWIG version 1 3 38 is needed Older versions of SWIG as stated above are not supported anymore with Tcl3D versions 0 4 1 and newer e See chapter 5 4 for known bugs with other SWIG versions Download and unzip the following distribution packages suitable for your operating system tcel3d src 0 4 1 zip tcl3d 0S 0 4 1 zip tcl3d demos 0 4 1 zip tcl3d starpack 0 4 1 zip Example installation procedures Version 1 TclI3D Basic OpenGL support no external libraries Needed tcl3d srce 0 4 1 zip Recommended tcl3d demos 0 4 1 zip Unzip tcl3d src 0 4 1 zip in a folder of your choice This creates a new folder tcl3d containing the sources Unzip tcl3d demos 0 4 1 zip into the new folder te 3d You should end up with
21. in chapter 4 2 4 3 11 Virtual trackball and arcball module This module provides functions for emulating a trackball and an arcball Overview The following tables list the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter The trackball module implements the following commands tcl3dTbInit Call this initialization procedure before any other trackball procedure tel3dTbStartMotion tcl3dTbAnimate Call with parameter 1 or GL_ TRUE if you want the trackball to continue spinning after the mouse button has been released Call with parameter 0 or GL_FALSE if you want the trackball to stop spinning after the mouse button has been released Table 4 16 tcl3dUtil Trackball commands The ArcBall module implements the following commands Create new ArcBall with given width and height tcl3dDeleteArcBall Delete an ArcBall tc 1 Cc Update start vector and prepare for dragging Update end vector and get rotation as Quaternion Table 4 17 tcl3dUtil ArcBall commands l Ball L r reshape callback 1 1Cli 1 1D Tcl3D User Manual Version 0 4 1 August 2009 Page 46 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Examples
22. library consists of C files tcl3dShapesTeapot c for the teapot tcl3dShapesGlut c for all other GLUT shapes and the common header file tel3dShapesGlut h and the Tcl file tcl3dShapesGlut tcl The GLUT shape objects are available under identical names for porting test and demonstration programs to Tcl3D These shapes are used extensively in the examples of the OpenGL redbook 26 See there for a description of the functions and its parameters lutSolidCone glutWireCone gt O E lutSolidCube eee o utSolidDodecahedron lutWireDodecahedron utSolidIcosahedron lutWireIcosahedron utSolidOctahedron lutWireOctahedron utSolidSphere lutWireSphere utSolidTeapot lutWireTeapot utSolidTetrahedron lutWireTetrahedron utSolidTorus lutWireTorus Table 4 2 tcl3d0gl GLUT shape commands QQ JQ e je PQ JQ je Q 4 Note e The teapot implementation differs in the original GLUT and the freeglut implementation If using the teapot in a benchmark application note that Freeglut uses 7 for the grid parameter Original GLUT and Tcl3D use 14 as grid parameter All supported GLUT compatible shapes Demo glutShapes tcl Examples The following code snippet shows how to call tc13d0g1GetVersions Tcl3D User Manual Version 0 4 1 August 2009 Page 30 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl foreach gliInfo tcl3d0glG
23. wrapped libraries Tcl3D User Manual Version 0 4 1 August 2009 Page 53 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 5 Miscellaneous TcI3D information Tcl3D Doing 3D with Tcl 5 2 Programming hints Hint 1 Most OpenGL examples written in C use the immediate mode As Tcl is a scripted language and each OpenGL call has to go through the wrapper interface it s almost always a bad idea in terms of speed to translate these examples one by one Using display lists or vertex arrays does not add much complexity to your Tcl3D program but enhances performance significantly Try the Spheres tcl or ogi_benchmark_sphere tcl demo for an example how display lists or vertex arrays can speed up your Tcl3D application Also note that immediate mode and display lists are marked deprecated in OpenGL 3 1 Hint 2 Do not use global variables GL VERSION _X Y ex info exists GL VERSION 1 3 to check the OpenGL version supported on your computer This does not work because these variables are all defined independently of the underlying OpenGL implementation Use the utility functions tcl3dHaveVersion and tcl3dHaveExtension instead Hint 3 Error expected integer but got GL REPEAT Some OpenGL functions expect an integer or floating point value which is often given in C code examples with an enumeration as shown in the next example extern void glTexParameteri GLenum target
24. 0 20 4 0 0403 f glMaplf GL MAP1 VERTEX 3 0 0 1 0 3 4 join ctrlpoints The mapping of const void pointers is handled by SWIG standard typemaps Constant void pointers as function input parameter must be given as a pointer to a contiguous piece of memory of appropriate size Input parameter const void SIZE const void C decl ti void glVertexPointer GLint size GLenum type eciaration GLsizei stride const GLvoid ptr static GLint vertices i 25 25 100 325 175 25 C example 175 325 250 25 325 325 glVertexPointer 2 GL INT 0 vertices set vertices tcl3dVectorFromArgs GLint Tel 25 25 100 325 175 25 C xampie 175 325 250 25 325 325 glVertexPointer 2 GL INT 0 vertices Table 3 6 Wrapping of a void pointer input parameter Note e The allocation of usable memory can be accomplished with the use of the tcl3dVector commands which are described in chapter 4 3 5 e This type of parameter is typically used to supply image data or vertex arrays See also the description of the image utility module in chapter 4 3 6 3 1 3 Output parameters The mapping of non constant pointers is handled by the SWIG standard typemaps Non constant pointers as function output parameter must be given as a pointer to a contiguous piece of memory of appropriate size tcl3dVector See note above Tcl3D User Manual Version 0 4 1 August 2009 Page 21 of 65 Copyright 2005 2009 by Paul Obe
25. 3D starpack o lt Tcl Tk 8 4 18 http www equi4 com tclkit index html Tklmg 1 4 http sourceforge net projects tkimg Snack 2 2 http www speech kth se snack Twapi 2 1a3 Windows only http twapi magicsplat com 1 4 Supported platforms The following table gives an overview on the availability of the different Tcl3D modules on the supported operating systems It also tries to give an indication on the quality of the module 32 bit Intel En ea a zs a Co tcl3dFTGL a jects e ia aa a eae ToN Table 1 2 Availability of TcI3D modules Legend for Table 1 2 Column Wrap Column Test Interface of module fully wrapped Module extensively tested No errors known Interface of module partially wrapped Module tested Minor errors known 0 Module not yet wrapped 0 Module in work Module not available for the platform Module not available for the platform Tcl3D User Manual Version 0 4 1 August 2009 Page 6 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 1 Introduction Tcl3D Doing 3D with Tcl Short summary The Windows and Linux ports are supported best and are regularly tested on different graphics card and OpenGL driver combinations On IRIX every module except OSG and Cg which is not available for SGI has been wrapped and seems to be running fine but no extensive tests have been done
26. CRBS eS INMOUMANON satesiiiesietaciveiipeetet dikes a 53 92 Programming NNS i ae hia ii i ihc ari ede ile 54 ILOPO MLS ELSE ie eee ore eRe Not een RE EEN Perea tnt er tment eee rr AA 55 T RELEASE NOTES coui a bans vad nca vida cours aada aad ia aitaa aii A 59 Se HSO naaa i ce 59 1 2 Obsolete TUT Ss ios ieee ccna as ne Sica kdeapnaeanoinancdanladiacesanadanalin AEREA EAEE 63 Be ee eo a soa itn ess aaa a a E 64 Tcl3D User Manual Version 0 4 1 August 2009 Page 1 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 1 Introduction Tcl3D Doing 3D with Tcl 1 Introduction TclI3D enables the 3D functionality of OpenGL and various other portable 3D libraries at the Tcl scripting level It s main design requirement is to wrap existing 3D libraries without modification of their header files and with minimal manual code writing The Tcl API shall be a direct wrapping of the C C based library APs with a natural mapping of C types to according Tcl types This is accomplished mostly with the help of SWIG 23 the Simplified Wrapper and Interface Generator Tcl3D is based on ideas of Roger E Critchlow who formerly created an OpenGL Tcl binding called Frustum 29 1 1 Architecture overview The Tcl3D package currently consists of the following building blocks also called modules throughout the manual Tcl3D core module tcl3dOgl I Enhanced Tog widget a Tk widget
27. D with Tcl See the demo programs contained in directory LibrarySpecificDemos tcI3dFTGL for examples on how to use the FTGL functions 4 7 tcl3dGl2ps Wrapper for the OpenGL To Postscript Library This module wraps Christophe Geuzaine s GL2PS 11 library based on version 1 3 3 and adds some GL2PS related utility procedures Note e GI2PS currently does not support textures This is an optional module Requirements for this module None all files are contained in the Tcl3D distribution The master SWIG file for wrapping the Gl2ps library is tel3dGl2ps i Implementation files g 2ps c tcl3dGI2psQuery tcl tcl3dG 2psutil tcl Header files gl2ps h Wrapper files gl2ps i The wrapping for this module is based on the unmodified GL2PS implementation and header files Gl2ps utility module Get the version of the wrapped GL2PS library Create a PDF file from current Togl window content Table 4 21 tcl3dGl2ps utility commands See NeHe demo Lessond2 tc l or the benchmarking demo sphere tc in directory LibrarySpecificDemos tcl3dOgI for an example on how to use the GL2PS functions for PDF export 4 8 tcl3dOde Wrapper for the Open Dynamics Engine This module wraps the ODE 12 library based on version 0 7 and adds some ODE related utility procedures Note e This module is still work in progress It s interface may change in the future This is an optional module Requirements for t
28. GLU MAP1 TRIM 2 t curvePt 0 25 0 5 0 25 0 75 0 75 0 75 0 75 0 5 Tel t curveKnots 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 CrEXAMPIG uNurbsCurve theNurb 8 ScurveKnots 2 ScurvePt 4 GLU MAP1 TRIM 2 Table 3 9 Wrapping of GLU functions The two aforementioned functions which provide output parameters with TYPE are gluProject and gluUnProject These are handled as a special case in the SWIG interface file glu i The 3 output parameters are given the keyword OUTPUT so SWIG handles them in a special way SWIG builds a list consisting of the normal function return value and all parameters marked with that keyword This list will be the return value of the corresponding Tcl command Definition in glu h Redefinition in SWIG interface file glu i extern GLint gluUnProject Lint gluUnProject GLdouble winX GLdouble winyY double winX GLdouble winyY GLdouble winZ double windZ const double model const GLdouble model const double proj const GLdouble proj const Lint view const GLint view double objX double OUTPUT double objY double OUTPUT double objZ double OUTPUT Table 3 10 Wrapping exceptions for GLU Example usage see Redbook example unproject tc for complete code glGetIntegerv GL VIEWPORT viewport glGetDoublev GL MODELVIEW MATRIX Smvmatrix glGetDoublev GL PROJECTION MATRIX p
29. Tcl3D Doing 3D with Tcl Tcl3D Doing 3D with Tcl LINTRODUC TON cini 2 1 1 Architecture CORIO sinisiin aaa a a E Aaaa 2 1 2 Modules cata lea indicia ci i re Soe 3 22 Installation of a source GIStrIDUTION 0 ee ee eee ecc cece eee eseeeenseeeseeseusseeseeeseeesenseesaenesnees 12 2 2 Ree Nn E a ea E 18 3 WRAPPING IN DETAIL eiccin aa a A aA a a A A Ra 19 4 2 tcl3dOgl EE Wrapper for OpenGL functionality 2 cis crs nce retencastesesnreee releases 28 remo ait Seve Te r TEAD lity 2 cs ee ene renee ere eter err res 31 4 4 tcl3dCg Wrapper for NVidia s Cg shading lanQuage no cccccceseeesseeesseeceeeeessnnnneesneeeeuees 48 4 5 tcl3dSDL Wrapper for the Simple DirectMedia Library ccseseeeeeeeeeeeeeeeeeeeeeeeees 48 4 6 tcl3dFTGL Wrapper for the OpenGL Font Rendering Library cssseceeesseeeeeeeees 49 4 7 tcl3dGI2ps Wrapper for the OpenGL To Postscript Library cccccceeeeeeeeeeeeeeeeeeeeees 50 4 8 tcl3dOde Wrapper for the Open Dynamics Engine ssceecceeeeeeeeeeeeeeeseeeeeeeeeeeeeeees 50 4 9 tcl3dOsg Wrapper for the OQpenSceneGraph library ccccccccceceeeseeeeeeeeeeeeeeeeeeeseeeeess 51 4 10 tcl3dGauges Tcl3D package for displaying gaugeS sssseseseennnnnnnnnnnrnnsssssssnnrennessns 52 5 MISCELLANEOUS TCL3D INFORMAT ION nssssssnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnne 53 SL
30. Vector functionality Utility functions for manipulation of image data stored in tcl3dVectors tcl3dVectorCopy tcl3dVectorCopyChannel tcl3dVectorManip tcl3dVectorManipChannel tcl3dVector member functions for content independent manipulation setvec addvec mulvec tcl3d0de now uses ODE version 0 7 and is available for Windows Linux Mac OS X and Irix Wrapper still in alpha version and not complete tcl3dGl2ps now uses GL2PS version 1 3 2 tcl3dCg now uses Cg version 1 5 0015 The 1 4 versions of Cg did not work with OS X on Intel platforms Version 0 3 1 2006 06 19 Starpack support for TcI3D Starpack version of Tcl3D including demos and external libraries First shown at TclEurope 2006 New optional module tcl3dGl2ps wrapping the OpenGL To Postscript library Thanks to Ian Gay for idea and first implementation New optional module tcl3d0de wrapping the Open Dynamics Engine Very alpha preview Windows only More NeHe tutorials added Lessons 19 21 Version 0 3 2006 02 12 MacOS X and enhanced font support Support for Mac OS X added Thanks to Daniel A Steffen for supplying patches and binaries New optional module tcl3dFTGL wrapping the OpenGL font rendering library FTGL based on freetype fonts Corrected and enhanced font handling under Windows in the tcl3dTogl widget No more private Tcl header files needed Added new font related demo programs tcl3dFont tcl tcl3dToglFonts tcl ft
31. a directory and file structure as shown in the next figure Tcl3D User Manual Version 0 4 1 August 2009 Page 13 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl a B E config_cygwin demos E config_Darwin O swiafiles E config_IRIX64 H O tcl3dcg E config_Linux tcl3dFTGL E config_Linux64 O tcl3dGauges E config_mingw 5 tcl3dGl2ps 3 config_win32 O tel3dode E make macros O tcl3doql E make oscheck 4 O tcl3dOsq E make wrap tcl3dSDL E Makefile Ej pkgIndex tcl E Readme txt E Tel3D_Announce txt E Tcl3D_License txt Figure 2 1 Tcl3D Basic directory structure If only basic OGL support is needed disable the optional modules by commenting all WRAP _ macro lines in file make wrap The presentation framework presentation tcl works but the texts are displayed as 2D bitmaps only Most OpenGL only demos should work Version 2 Tcl3D Complete OpenGL support plus optional modules Needed tcl3d srce 0 4 1 zip Needed tcl3d 0S 0 4 1 zip Recommended tcl3d demos 0 4 1 zip Unzip tcl3d src 0 4 1 zip in a folder of your choice This creates a new folder ftcl3d containing the sources Unzip tcl3d demos 0 4 1 zip into the new folder tcl3d Unzip tc13d 0S 0 4 1 zip into a temporary folder Then copy the dynamic libraries contained in subfolder extlibs OS into a directory which is listed in your PATH environment va
32. afeMode tcl3d0glSetDebugMode to switch between the 3 OpenGL execution modes Normal Safe Debug Corresponding buttons added in the presentation framework New utility function tcl3dVectorFromLinspace to create new linearly spaced Tcl3D Vector Added test file vectorlinspace tcl New utility functions tcl3d0glFindFunc tcl3d0glGetExtSuffixes to find an implemented OpenGL function from it s core name by searching all known extension names Added test file findFuncs tcl CAUTION Incompatible changes if used from the Tcl level Replaced Int8 Float32 with corresponding GLbyte GLfloat typedefs Also changed function names accordingly Bug fixes Corrected bug in OpenGL wrapper createGlewSwigFile tcl glGetStringi was not wrapped t Corrected bug in telsautilkractal c telsdhractalToPhouo had Incorrect x and y scaling Removed features Support for Visual C 6 0 and CygWin deprecated Version 0 4 0 2008 12 30 OpenGL wrapping now based on GLEW Enhancements New features CAUTION Possibly incompatible changes OpenGL wrapping is now based on GLEW because the previously used OglExt extension library is no longer supported OpenGL version now supported is 3 0 based on GLEW version 1 5 1 No C dependency anymore in the core modul No more initialization tcl3dOglExtInit of th xtended OpenGL Tcl3D User Manual Version 0 4 1 Augu
33. age SimgName Serrl else set numChans tcel3dPhotoChans phImg if SnumChans 3 amp amp SnumChans 4 error Error Only 3 or 4 channels allowed S numChans supplied set w image width phImg set h image height SphImg set texImg tcl3dVectorFromPhoto phImg numChans image delete phImg return list texImg w h proc CreateTexture Load an image into a tcl3dVector Tcl3D User Manual Version 0 4 1 August 2009 Page 41 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl set imgInfo LoadImage Wall bmp set imgData lindex SimgInfo 0 set imgWidth lindex SimgInfo 1 set imgHeight lindex SimgInfo 2 Create the texture identifiers glGenTextures 1 texture glBindTexture GL TEXTURE 2D texture get 0 glTexParameteri GL TEXTURE 2D GL TEXTURE MIN FILTER GL LINEAR glTexParameteri GL TEXTURE 2D GL TEXTURE MAG FILTER GL LINEAR glTexImage2D GL TEXTURE 2D 0 3 SimgWidth imgHeight 0 GL RGBA GL UNSIGNED BYTE imgData Delete the image data vector imgData delete Example 2 Read an image from the OpenGL framebuffer and save it with the Img library proc SaveImg imgName set w toglWidth set h toglHeight set numChans 4 set vec tcl3dVector GLubyte expr w Sh SnumC
34. al Version 0 4 1 August 2009 Page 24 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl 4 Modules in detail This chapter explains in detail the different modules Tcl3D is currently built upon Tcl3D core module e Togl Enhanced Togl widget e OpenGL Wrapper for OpenGL functionality e Util Tcl3D utility library Tcl3D optional modules e tcl3dCg Wrapper for NVidia s Cg shading language e tcl3dSDL Wrapper for the Simple DirectMedia Library e tcl3dFTGL Wrapper for the OpenGL Font Rendering Library e tcl3dGl2ps Wrapper for the OpenGL To Postscript Library e tcl3dOde Wrapper for the Open Dynamics Engine e tcl3dOsg Wrapper for the OpenSceneGraph library e tcl3dGauges Tcl3D package for displaying gauges 4 1 tcl3dOgl gt Togl Enhanced Togl widget Togl 6 is a Tk widget with support to display graphics in an OpenGL context The original version only supported issuing drawing commands in C To be usable from the Tcl level it has been extended with configuration options for specifying Tcl callback commands Requirements for this module None all files are contained in the Tcl3D distribution 4 1 1 Togl commands The following is a list of currently available Togl commands The commands changed or new in Tcl3D are marked bold and explained in detail below For a description of the other commands see the original Tog documentation configure
35. artIndex int len int i int endIndex startIndex len for i startIndex i lt endIndex i ary i value static void GLdouble_addvector double ary double value Tcl3D User Manual Version 0 4 1 August 2009 Page 39 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl int startIndex int len int i int endIndex startIndex len for i startIndex i lt endIndex i ary i double value static void GLdouble mulvector double ary double value int startIndex int len int 1 int endIndex startIndex len for i startIndex i lt endIndex i ary i double value static double GLdouble_ind double ary int incr return ary incr static double GLdouble cast void ary return double ary These low level functions are typically not used directly They are accessible via the Tcl command tcl3dVector with the exception of the TYPE ind functions An example for the usage of GLfloat_ind for optimised access to vectors can be found in NeHe demo Lesson37 tcl File bytearray i provides the implementation and wrapper definitions to convert Tcl binary strings ByteArrays into Tcl3D Vectors tcl3dByteArray2Vector and vice versa tcl3dVector2ByteArray Comparison of the different vector methods There are 4 different methods of setting vectors Method
36. ating the sucess of the query the querying command used the key and the value s Utility function for easier use of OpenGL function glGetShaderInfolLog Utility function for easier use of OpenGL function glGetProgramInfoLog Utility function for easier use of OpenGL function glGetShaderSource Utility function for easier use of OpenGL function glGetInfoLogARB ee ee Procedure to implement the OpenGL function glMultiDrawElements Utility function for easier use of OpenGL function glShaderSource Oo Ef Return a list of the names of all wrapped OpenGL functions functions wrapped OpenGL functions eee eee a Tcl3D User Manual Version 0 4 1 August 2009 Page 29 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl e The functions gl1GetString and gluGetString as well as the corresponding high level functions tcl3d0glGetVersions and tcl3d0glGetExtensions only return correct values if a Togl window has been created i e a rendering context has been established This holds true for function tc13d0glHaveFunc too e See Hint 6 in chapter 5 2 for the differences between the GLEW extension library and the previously used OgIExt extension library GLUT shapes library Implementation files tcl3dShapesGlut c tcl3dShapesTeapot c tcl3dShapesGlut tcl Header files tcl3dShapesGlut h Wrapper files tcl3dOgl i The shapes
37. ation into the corresponding OpenGL representation OpenGL colors are returned as a list of 3 unsigned bytes r g b 1l3dName2rgbf Convert a color specification into the corresponding OpenGL representation OpenGL colors are returned as a list of 3 floats in the range 0 1 rg b 13dNamezrgba Convert a color specification into the corresponding OpenGL representation OpenGL colors are returned as a list of 4 unsigned bytes r g b a l3dName2rgbaf Convert a color specification into the corresponding OpenGL representation OpenGL colors are returned as a list of 4 floats in the range 0 1 rgba Rgb2Name Convert an OpenGL RGB color representation into a hexadecimal Tcl color name string OpenGL colors are specified as unsigned bytes in the range 0 255 Rgba2Name Convert an OpenGL RGBA color representation into a hexadecimal Tcl color name string OpenGL colors are specified as unsigned bytes in the range 0 255 Rgbf2Name Convert an OpenGL RGB color representation into a hexadecimal Tcl color name string OpenGL colors are specified as floats in the range 0 1 Rgbaf2Name Convert an OpenGL RGBA color representation into a hexadecimal Tcl color name string OpenGL colors are specified as floats in the range 0 1 Table 4 7 tcl3dUtil Color utility commands Examples See the test program colorNames tcl for examples on how to use these procedures tcl3dName2Hex white returns FFFFFF
38. ay be running from within a starpack Get a name on the file system Use this function if a file is needed for reading from an external TcI3D library like font files used by FTGL or shader files and the script may be executed from within a starpack Table 4 6 tcl3dUtil File utility commands Examples See the demo program Lesson02 tcl for an example usage of tcl3dGenExtName and demo ftglTest tcl for an example usage of tcl3dGetExtFile Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dUtilFile tcl Header files None Wrapper files None 4 3 4 Color names module This module provides miscellaneous functions for handling color specifications in Tcl and OpenGL style Overview The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Tcl3D User Manual Version 0 4 1 August 2009 Page 35 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl 13dGetColorNames Return a list of all supported Tcl color names tcl3dFindColorName Check if supplied color name is a valid Tcl color name representation RRGGBB representation RRGGBBAA 13dName2rgb Convert a Tcl color specific
39. book com source OpenGL GLUT demos http www opengl org resources code samples glut_examples demos demos html 21 Paul Bourke s textured sphere http local wasp uwa edu au pbourke texture spheremap 22 Tools needed for Tcl3D development 23 SWIG Simplified Wrapper and Interface Generator http www swig org 24 ActiveTcl Batteries included distribution http www activestate com 25 Starpack Wiki page http wiki tcl tk 3663 Documentation 26 Woo Neider Davis OpenGL Programming Guide Addison Wesley The Redbook Tcl3D User Manual Version 0 4 1 August 2009 Page 64 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 8 References Tcl3D Doing 3D with Tcl 27 OpenGL Wiki page http wiki tcl tk 2237 28 OpenGL Extension Registry http www opengl org registry Miscellaneous 29 Roger E Critchlow s Frustum http www elf org pub frustum01 zip 30 Paul Obermeier s Portable Software http www posoft de Tcl3D User Manual Version 0 4 1 August 2009 Page 65 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved
40. brot tcl for an example on how to use these procedures to set up random colors for fractal generation Implementation details The functionality of this module is implemented in the following files Tcl3D User Manual Version 0 4 1 August 2009 Page 44 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Implementation files tcl3dUtilRandom c Header files tcl3dUtilRandom h Wrapper files utili 4 3 10 3D Model and shapes module This module provides functions for reading 3D models in Wavefront format and creating basic shapes Overview The following tables list the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter lmUnitize Unitize a model by translating it to the origin and scaling it to fit in a unit cube around the origin texture map the texture map lmDelete Deletes a GLMmodel structure 1lmReadOBJ Reads a model description from a Wavefront OBJ file Writes a model description in Wavefront OBJ format to a file imDraw Renders the model to the current OpenGL context using the mode specified lmList Generates and returns a display list for the model using the mode specified lmWeld Eliminate weld vectors that are within an epsilon of each other Table 4 14 tc
41. cl3D Vector containing the data of a Tk photo image See next chapter for detailed description Linspace_ Create a new linearly spaced Tcl3D Vector Oooo eT Copy the contents of a Tcl3D Vector into a Tcl list Very slow T Copy the contents of a Tcl3D Vector into a string Very slow foByteArray Copy the contents of a Tcl3D Vector into a Tcl binary string Table 4 8 tcl3dUtil tcl3dVector utility commands Note e The tcl3dFromString and tcl3dVectorToString commands can be replaced with the corresponding ByteArray Commands which are much faster e For functions converting photos into vectors and vice versa see the next chapter about image manipulation The tcl3dVector command creates a new Tcl procedure with the following subcommands which wrap the low level vector access functions described above Tcl3D User Manual Version 0 4 1 August 2009 Page 37 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl get Get vector element at a given index TYPE_getitem get set Set vector element at a given index to supplied value TYPE setitem Set range of vector elements to supplied value TYPE setarray mulvec Add supplied value to a range of vector elements TYPE _addarray Muliply supplied value to a range of vector elements TYPE mularray Delete a tcl3dVector delete TYPE Table 4 9 tcl3dUtil tcl3dVec
42. ctory include Wrapper files osg i tcl3dOsg i The wrapping for this module is based on the unmodified OSG header files OSG utility module Tcl3D User Manual Version 0 4 1 August 2009 Page 51 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl 13d0sgGetVersion Get the version of the wrapped OSG library tcl3dOsgKeysym Convert a keysym into decimal and vice versa 13dOsgGetBitmap Get the bitmap image of a node type 13d0sgVec t Print the contents of an osg Vec class tcl3dosgMatPrint Print the contents of an osg Matrix class 13d0sgBBoxPrint Print the contents of an osg BoundingBox class tcl3dOsgBSpherePrint Print the contents of an osg BoundingSphere class 13d0sgVecArrayPrint Print an array of vectors 13d0sgScalarArrayPrint Print an array of scalars Print an array of objects 13d0sgGetVisitorTypeName Get visitor type name 13d0sgGetTraversalModeName Get traversal mode name l3d0sgSendButtonPress Procedures to transfer the corresponding Tk event to the L3dOsgSendButtonRelease OSG event queue osgGA EventQueue l3dO0sgSendMouseMotion 13dOsgSendKeyPress L3dO0sgSendKeyReleas l3dO0sgSendWindowResize tcl3dosgAddTrackballBindings Add OS independent mouse bindings for trackball usage Table 4 23 tcl3dOsg utility commands See the demo programs contained in
43. demos the snack extension is used e To generate screenshots from the Tcl3D presentation the Twapi extension is needed on Windows It is therefore recommended to use an ActiveTcl distribution 24 which contains all of the above listed Tcl extensions Download and unzip the following distribution packages suitable for your operating system tcl3d 0S 0 4 1 zip e tcl3d demos 0 4 1 zip Then copy the resulting folders into the appropriate directories as described in the previous chapter 2 2 Installation of a source distribution This chapter outlines the general process of compiling customising and installing the Tcl3D package See the file Readme txt in the source code distribution for additional up to date information 2 2 1 Step 1 Prerequisites The following prerequisites are needed when using a Tcl3D source package e An OpenGL driver suitable for your graphics card It is recommend to download and install an up to date OpenGL driver from the manufacturer of your graphics card especially if intending to write shader programs in GLSL or Cg e A Tcl Tk version greater or equal to 8 4 Tcl3D User Manual Version 0 4 1 August 2009 Page 12 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl e The Img extension is needed to have access to various image formats which are used as OpenGL textures e For some demos the snack extension is used e To
44. dil are not found i e they are not in a directory contained in your Path environment variable Error Package tcl3dcg couldn t load library C Tcl lib tcl3d tcl3dCg tcl3dCg dll Tcl3D User Manual Version 0 4 1 August 2009 Page 54 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 5 Miscellaneous TcI3D information Tcl3D Doing 3D with Tcl permission denied This typically indicates that the dependent library or libraries ex cg dil or cgGL dil were found but you do not have the permissions to execute the library These errors may occur with the following Tcl3D modules Tcl 3D module Affected libraries cg dil eqGL cil libftgl dll freetype6 dll ode dll osg dil osgDB dlll SDL dill Although the examples shown in this hint use Windows specific library names the above mentioned errors may occur on Unix systems as well Hint 6 The OpenGL extension library Og Ext used in Tcl3D versions before 0 4 for wrapping OpenGL functions and the currently used GLEW library have an important difference OpenGL functions not available in the installed OpenGL driver have been ignored by the OgIExt library i e transformed into a no op The disadvantage of this behaviour was that you did not get any feedback about not available functions in your OpenGL driver implementation With GLEW you will get a core dump when trying to use such a function because the function pointer is NULL You should
45. eier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl 2 Installation Precompiled packages for Windows Linux IRIX and Intel based Mac OS X the source code of the Tcl3D package as well as test and demonstration programs can be downloaded from the Tcl3D home page at http www tcl3d org The precompiled packages have been generated on the following operating system compiler combinations Operating system Compiler Windows XP Home SP3 Mo Express e010 ar SEI Soe Eini O eTe geg a i z SuSE Einu T02 2e Tg geo A12 Mac OSx r0TAT Ii gee 450 1 SCI RIC 6 9 22 gcc 3 4 6 Nekoware Please report problems or errors to info tcl3d org Use the following script when sending bug reports or questions to supply me with information about your environment catch console show package require tcl3d togl t Print information about the OS parray tcl platform Print information about the Tcl3D modules puts tcl3dGetPackageInfo Print information about the OpenGL driver puts tcl3d0glGetVersions If it s a problem with an OpenGL extension you should also include the output of the following statement puts tcl3d0glGetExtensions The following distribution packages are currently available Which packages are needed depends on the proposed usage See the next chapters for detailed information Tcl3D User Manual Version 0 4 1 August 2009 Pa
46. enGL 3 0 Released 2009 08 16 New module tcl3dOsg wrapping the OpenSceneGraph library Reorganization of Tcl3D core module tcl3dGauges tcl3dGauges Tcl Extension Package Tcl Extension Package SWIG generated Tcl interfaces Tcl Interface i SWIG generated Tcl interfaces i Tel Interface tel3dCg tcl3dSDL tcl3dFTGL Cg Shading Joystick and CD Font Rendering tcl3dCg tcl3dSDL tcl3dFTGL Cg Shading Joystick and CD Font Rendering tel3dGI2ps tcl3dOde tel3dGI2ps tcl3dOde tcl3dOsg OpenGL to PS PDF Physics Engine OpenGL to PS PDF Physics Engine OpenSceneGraph Figure 7 1 Tcl3D graphical release history Version 0 4 1 2009 08 23 New module tcl3dOsg for OpenSceneGraph support Enhancements New features New optional module tcl3d0sg wrapping the OpenSceneGraph library Wrapping is based on OpenSceneGraph version 2 8 2 Several demo and test programs showing the new functionality t Support for Visuals Studio 2008 Improved detection of OS and compiler in make files To detect if using a DOS console for compilation the existence of environment variable VSINSTALLDIR is checked This variable is also used to detect a NET compiler i e VS2005 or VS2008 which need manifests Corrected build files and support for MinGW SWIG version 1 3 38 tested for correct wrapping Cg version updated to 2 2 0006 Gl2ps version updated to 1 3 3 New utility functions tcl3d0glSetMode tcl3d0glSetNormalMode tcl3d0glSetS
47. ents of a widget and all of its sub widgets into a photo image tcl3dWidget2Fil Copy contents of a widget and all of its sub widgets into a photo image and save the image to a file Copy the contents of a Tk canvas into a photo image le G the image to a file and save the image to a file 3 cl gel Copy a photo into the Windows clipboard el gl gl Copy the contents of the top level window Alt PrtSc into the Windows clipboard clipboard Copy the contents of the top level window Alt PrtSc into a photo image Copy the contents of the top level window Alt PrtSc into a photo image and save the image to a file Table 4 11 tcl3dUtil Capture commands Note e All of the functionality requires the help of the Img extension e Some of the functionality requires the help of the Twapi extension and is therefore available only on Windows Examples See the demo program presentation tcl for an example on how to use these procedures to save screenshots of the available Tcl3D demos by right clicking on the demo name Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dUtilCapture tcl Header files None Wrapper files None 4 3 8 Timing module This module provides functions for timing purposes Overview The following table lists the available functions of this module For a detailed description of the functions
48. es Tcl3D Doing 3D with Tcl First version called TclOgl introduced at the Tcl Europe 2005 conference Supported features include basic OpenGL wrapping 7 2 Obsolete functions The following table shows all obsolete functions Most of these functions have just been renamed to get a more consistent naming scheme The obsolete functions are still available but may be removed in future versions Version Old Name New Name tcl3dCheckCgError tcl3dCgGetError tcl3dGetCgProfileList tcl3dCgGetProfileList tcl3dFindCgProfile tcl3dCgFindProfile tcl3dFindCgProfileByNum tcl3dCgFindProfileByNum tcl3dPrintCgProgramInfo tcl3dCgPrintProgramInfo 0 3 2 tcl3dHeightMapFromPhoto tcl3dDemoUtilHeightMapFromPhoto tcl3dReadImage tcl3dReadRedBookImage tcl3dCreatePdf tcl3dGl2psCreatePdf tcl3dInit tcl3dO0glExtInit tcl3dCheckGlError tcl3d0glGetError tcl3dPhoto2Vector tcl3dPhotoToVector tcl3dHaveExtension tcl3d0glHaveExtension tcl3dHaveVersion tcl3d0glHaveVersion tcl3dGetVersions tcl3d0glGetVersions 0 3 3 tcl3dGetExtensions tcl3dOglGetExtensions tcl3dGetStates tcl3dOglGetStates tcl3dVector2Photo tcl3dVectorToPhoto Still existent for backwards 0 4 0 tcl3dOglExtInit compatibility but functionality not needed anymore Table 7 1 List of obsolete functions Tcl3D User Manual Version 0 4 1 August 2009 Page 63 of 65 Copyright
49. eserved 1 Introduction Tcl3D Doing 3D with Tcl tcl3dCg Wrapper for NVidia s Cg shading language This module wraps NVidia s Cg 7 shader library and adds some Cg related utility procedures A detailed description of this module can be found in chapter 4 4 tcl3dSDL Wrapper for the Simple DirectMedia Library This module wraps the SDL 8 library based on version 1 2 9 and adds some SDL related utility procedures Currently only the functions related to joystick and CD ROM handling have been wrapped and tested A detailed description of this module can be found in chapter 4 5 tcl3dFTGL Wrapper for the OpenGL Font Rendering Library This module wraps the FTGL 9 library and adds some FTGL related utility procedures The following font types are available e Bitmap font 2D Pixmap font 2D Outline font Polygon font Texture font Extruded font A detailed description of this module can be found in chapter 4 6 tcl3dGl2ps Wrapper for the OpenGL To Postscript Library This module wraps the GL2PS 11 library and adds some GL2PS related utility procedures GL2PS is a C library providing high quality vector output PostScript PDF SVG for an OpenGL application A detailed description of this module can be found in chapter 4 7 tcl3dOde Wrapper for the Open Dynamics Engine This module wraps the OpenSource physics engine ODE 12 and adds some ODE related utility procedures Note e This module is still work i
50. etVersions puts lindex glInfo 0 lindex glInfo 1 VENDOR NVIDIA Corporation RENDERER GeForce FX Go5600 AGP SSE2 VERSION 1 4 0 U VERSION 1 2 2 0 Microsoft Corporation AQAA The following code snippet shows how to call tc13d0g1GetExtensions foreach glinfo tcl3d0glGetExtensions puts lindex SglInfo 0 foreach ext lsort lindex S glInfo 1 puts tSext GL EXTENSIONS GL ARB depth _ texture GL_ARB fragment program GL ARB imaging GLU_EXTENSIONS GL EXT bgra The following code snippet shows how to call tc13d0glGetStates foreach glState tcl3d0glGetStates set msgStr lindex glState 2 lrange glState 3 end if lindex glState 0 0 set tag Unsupported else set tag append msgStr Stag puts SmsgStr VERTEX ARRAY SIZE 4 VERTEX ARRAY TYPE 5126 VERTEX ARRAY STRIDE 0 V N N ERTEX ARRAY POINTER Unsupported ORMAL ARRAY 0 ORMAL ARRAY TYPE 5126 ARAAAD See the demo program tcl3dinfo tcl for other examples on how to use these procedures 4 3 tcl3dOgl gt Util Tcl3D utility library This module implements several utilities in C and Tcl offering functionality needed for 3D programs It currently contains the following components e 3D vector and transformation matrix component e
51. f ifeq KERNEL mingw INSTDIR F Programme poSoft TCLDIR F Programme Tcl endif 2 2 3 Step 3 Customization The optional modules can be included or excluded from the compilation step by setting the following macros in file make wrap in the top level directory of the Tcl3D source tree WRAP_SDL WRAP_ODE Table 2 5 Customization settings Note Tcl3D User Manual Version 0 4 1 August 2009 Page 16 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl e Do not set a macro to 0 but comment the corresponding line i e undefine as shown in the following example WRAP FEATURE 1 enables the feature WRAP FEATURE 1 disables the feature Each Makefile of an optional module additionally checks for the existence of an important include file as listed in column Additional check file to enable extension support for Tcl3D 2 2 4 Step 4 Compilation and installation The following commands should compile and install the Tcl3D package gt gmake gt gmake install The make process prints out lines about the success of wrapping optional modules Tcl3D built with Cg support Tcl3D built without ODE support The starpack is not generated by default If you installed the starpack distribution package you have to go into the directory starpack and call make there e To test the generated starpack copy it into a temporary directo
52. f multisamples Tcl3D Doing 3D with Tcl synchronisation to vertical blank signal the multisample buffer swapinterval swapInterval SwapInterval 0 0 multisamplebuffers multisample Buffers MultisampleBuffers 0 0 multisamplesamples multisampleSamples MultisampleSamples 2 2 Note e Multisampling was implemented for the Togl widget in Tcl3D version 0 3 2 If working with older versions of Tcl3D you may enable multisampling outside of Tcl3D as follows With NVidia cards you can enable GUI Under Linux you can set the env The default value for swapinterval multisampling under Windows via the NVidia driver ironment variable _GL_FSAA MODE to 1 has been changed in version 0 4 0 from 1 to 0 i e if this option is not specified a Tcl3D program does not wait for the vertical blank signal but runs at maximum speed 4 1 3 A simple Tcl3D template A template for a Tcl3D application looks like follows package require tcl3d proc tclCreateFunc toglwin Stoglwin swapbuffers r sir fr expand 1 fill both frame pack glShadeModel GL SMOOTH Enable smooth shading glClearColor 0 0 0 0 0 0 0 5 Black background glClearDepth 1 0 Depth buffer setup glEnable GL DEPTH TEST Enable depth testing proc tclReshapeFunc toglwin wh glViewport 0 0 w h j Reset the current viewport glMatri
53. file make oscheck for details on the mapping of the command output The following lines in the config_ files may be edited Tcl3D User Manual Version 0 4 1 August 2009 Copyright 2005 2009 by Paul Obermeier All rights reserved Page 15 of 65 2 Installation Tcl3D Doing 3D with Tcl WITH_DEBUG If you don t want debug information remove ALL characters after the equal sign Set to your preferred installation directory TCLDIR Set to where your Tcl installation is located on disk TCLMINOR Set to your installed Tcl minor version Table 2 4 Tcl3D configuration variables Examples Compile with debugging information The Tcl installation is located in usr local We install the Tcl3D package into the same location as the Tcl distribution The installed Tcl version is 8 4 WITH DE INSTDIR usr local TCLDIR usr local TCLMINOR 4 Compile without debugging information The Tcl installation is located in C Programme Tcl We install the Tcl3D package into a separate directory The installed Tcl version is 8 4 WITH DE INSTDI Programme Tcl TCLDIR Programme poSoft TCLMINOR Instead of editing the configuration file you may alternatively create a file called make private in the top level directory of TcI3D and add lines according to your needs ifeq S KERNEL win32 INSTDIR F Programme poSoft TCLDIR F Programme Tcl endi
54. for displaying OpenGL content OpenGL Wrapper for core OpenGL functionality GL Version 3 0 GLU Version 1 2 and OpenGL extensions Util Tcl3D utility library Math functions standard shapes stop watch demo Tcl3D optional module cl3dCg cl3dSDL Wrapper for NVidia s Cg shading language Wrapper for the Simple DirectMedia Library cl3dFTGL Wrapper for the OpenGL Font Rendering library cl3dGl2ps Wrapper for the OpenGL To Postscript library cl3dOde Wrapper for the Open Dynamics Engine Wrapper for the OpenSceneGraph library tcl3dCg Wrapper for NVidia s Cg shading language Z Z o Z o tcl3dSDL Wrapper for the Simple DirectMedia Library o Z Z tcI3dFTGL Wrapper for the OpenGL Font Rendering library o Wrapper for the OpenGL To Postscript library Wrapper for the Open Dynamics Engine _ o o Wrapper for the OpenSceneGraph library S E Tcl3D package for displaying gauges Z o Z o o O gt cl3dOs Ji cl3dGauges Tcl3D package for displaying gauges Table 1 1 Overview of Tcl3D modules Each module is implemented as a separate Tcl package and can be loaded explicitely with the Tcl package command ex package require tcl3dsd1 All available Tcl3D modules can be loaded with a single command package require tcl13d Note e Package names are all lower case Tcl3D User Manual Version 0 4 1 August 2009 Page 2 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved
55. for version 0 1 CAUTION Possibly incompatible change Removed wrapping of Windows specific OpenGL functions wgl Operating system specific functions should only be used in the Togl code New demos 4 new demos added since release 0 3 3 These have been previously released as Tcl3D Demo of the month Version 0 3 3 2008 09 14 Bug fix and maintenance release Enhancements Added 64 bit Linux to the supported list of platforms Improved Mac OS X support Fixed resize problems in presentation framework Consistent mouse button behaviour across operating systems Trackball module supports multiple windows CAUTION Incompatible change Additional Togl window parameter in procedures tcl3dTbAnimate tcl3dTbInit tcl3dTbMatrix Thanks to Michael Magoga for this patch New OpenGL utility procedures tcl3d0glGetIntState tcl3d0glGetFloatState tcl3d0glGetDoubleState tcl3d0glGetMaxTextureSize tcl3d0glGetMaxTextureUnits tcl3d0glGetViewport tcl3d0glGetShaderInfoLog tcl3d0glGetProgramInfoLog tcl3d0glGetShaderSource tcl3d0glShaderSource tcl3d0glGetInfoLogARB New low level routines for copying Tcl lists into a vector tcl3dListToVector TYPE Tel utility procedure tcl3dVectorFromList updated to transparently use the new low level routines Starpacks now allow drag and drop of TclKit files tcl3dGetExtFile not constrained to Starkits anymore Thanks to Jean Claude Gohard for supplying a vfs and zv
56. fs enabled version New utility functions for random number generation same algorithm at C and Tcl level Bug fixes Bug fix in tcl3dGauges Eliminated bgerror procedures Thanks to Alexandre Ferrieux and Synic for hints on this bug Several bug fixes in the presentation framework Thanks to Philip Quaiffe for hints and other useful discussions Several other minor bug fixes New demos 19 new demos added since release 0 3 2 These have been previously released as Tcl3D Demo of the month Version 0 3 2 2007 02 25 Demo cleanup and first official Mac OS X support Tcl3D User Manual Version 0 4 1 August 2009 Page 61 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 7 Release notes Tcl3D Doing 3D with Tcl Unification of demo applications and presentation framework New module tcl3dDemoUtil for C C based utility functions needed by some of the demos for speed issues More NeHe tutorials added Lessons 14 22 24 26 28 33 36 37 41 45 48 Nine demos from www GameProgrammer org added Updated Tcl3D manual Created separate demo overview document Added support to capture screenshots Module tcl3dCapture Added new functionality to tcl3dUtil ArcBall emulation Added windowing system specifics SwapInterval Multisampling to the tcl3dTogl widget Added support for Visual Studio 2003 7 1 and 2005 8 0 Enhanced tcl3d
57. g 3D with Tcl 6 Demo applications More than 200 TclI3D applications for testing and demonstration purposes are currently available Most of these applications were converted from existing demonstration programs written in C C found on the web A detailed list of all demos is available online on the Tcl3D homepage at http www tcl3d org demos or in the Tcl3D Demo Manual The Tcl3D demo applications are divided into 4 categories e Category Tutorials and books contains scripts which have been converted from C C to Tcl3D coming from the following sources OpenGL Red Book 20 NeHe tutorials 16 Kevin Harris CodeSampler web site 17 Vahid Kazemi s GameProgrammer page 18 e Category Library specific demos contains scripts showing features specific to the wrapped library e Category Tcl3D specific demos contains scripts demonstrating and testing Tcl3D specific features e Category OpenSceneGraph contains scripts demonstrating and testing the wrapper of the OpenSceneGraph library The next figure shows an excerpt from the demo hierarchy Tcl3D Demo Hierarchy Categories LibraryS pecificD emos OpenSceneGraph Tcl3DSpecificDemos TutorialsAndBooks Tcl3DSpecificD emos Tutorials4ndBooks OpenSceneGraph Demo scripts LibraryS pecificD emos CodeS ampler GameProgrammer NeHe RedBook RedBook m Demo scripts i CodeSampler v x Lc Demo scripts GameProgrammer NeHe Demo scrip
58. ge 10 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl Tc ERSION odt Tcl3D user manual this document OpenOffice format Tcl3D Manual VERSION pdf Tcl3D user manual this document PDF format c13D RefManual VERSION pdf Tcl3D reference manual c13D DemoRef VERSION pdf Tcl3D demo programs reference 13d demos VERSION zip Tcl3D demo sources tcl3d demoimgs VERSION zip Screenshots of all Tcl3D demo programs Starpacks tel 3dsh win32 VERSION zip tel3dsh Linux VERSION zip tel3dsh Darwin VERSION zip tel3dsh IRIX64 VERSION zip Binary packages External libraries DLL s and Tcl3D package for Windows tcl ERSION zip External libraries DSO s and Tcl3D package for 32 bit Linux sinux64 VERSION zip External libraries DSO s and Tcl3D package for 64 bit Linux tc Darwin VERSION zip External libraries DSO s and Tcl3D package for Mac OS X External libraries DSO s and Tcl3D package for SGI IRIX cl Sources EC 13d src VERSION zip Tcl3D source distribution 13d starpack VERSION zip Tcl3D sources for creating starpacks Table 2 1 Tcl3D distribution packages The term VERSION is a template for the Tcl3D version number i e for the currently available version it must be replaced with 0 4 1 2 1 Installation of a binary distribution There are two possibili
59. glTest tcl ftglDemo tcl Added new SDL demo related to CD ROM handling cdplayer tcl Added some of NeHe s OpenGL tutorials If an optional library is not installed no error message is created New procedures to check existence of optional modules tcl3dHaveCg tcl3dHaveSDL tcl3dHaveFTGL Get information on Tcl3D subpackages with tcl3dGetPackageInfo and tcl3dShowPackagelInfo Information program tcl3dInfo tcl enhanced to support commands and enums of SDL and FTGL modules Added new functionality to tcl3dUtil Simple scrollable Tk widgets for demo programs trackball emulation used in FTGLdemo tcl Added new functionality to tcl3dUtil tcl3dVectorFromByteArray tcl3dVectorToByteArray Convert Tcl binary strings to tcl3dVectors and vice versa see demo bytearray tcl Bug fix in OglExt wrapping Parameters of type float and double were wrapped incorrectly Version 0 2 2006 01 07 Major rewrite of TclOgl Major rewrite and inclusion of several new 3D libraries OpenGL 2 0 and extensions NVidia s Cg library SDL the Simple Direct Media Library 4 gauge widgets Thanks to Victor G Bonilla for supplying this library Utility library Renamed from tclogl to Tcl3D Created domain tcl3d org Version 0 1 2005 05 29 Initial version Tcl3D User Manual Version 0 4 1 August 2009 Page 62 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 7 Release not
60. hans glReadPixels 0 0 w h GL RGBA GL UNSIGNED BYTE vec set ph image create photo width w height h tcl3dVectorToPhoto vec ph w h numChans set fmt string range file extension S imgName 1 end Sph write SimgName format fmt image delete phImg Svec delete proc tclReshapeFunc toglwin wh set toglWidth Sw set toglHeight h The actual size of the Togl window toglWidth toglHeight which is needed in command SaveImg can be saved in a global variable when the reshape callback is executed See the NeHe demo program Lesson41 tcl or any demo using textures for examples on how to use the photo image utilities Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dVector tcl Header files None Wrapper files tkphoto i 4 3 7 Screen capture module This module implements functions for capturing window contents into either a photo image an image file or the clipboard Overview Tcl3D User Manual Version 0 4 1 August 2009 Page 42 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Copy cont
61. his module The ODE library and header files Libraries and header files are included in the Tcl3D distribution The master SWIG file for wrapping the Open Dynamics Engine library is tel3dOde j Implementation files tcl3dOdeQuery tcl tcl3dOdeUtil tcl Header files All files in subdirectory ode Wrapper files ode i The wrapping for this module is based on the unmodified ODE header files Tcl3D User Manual Version 0 4 1 August 2009 Page 50 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl ODE utility module Get the version of the wrapped ODE library Table 4 22 tcl3dOde utility commands See the demo programs contained in directory LibrarySpecificDemos tcl3Ode for examples on how to use the ODE functions 4 9 tcl3dOsg Wrapper for the OpenSceneGraph library This module wraps the OpenSceneGraph 13 library based on version 2 8 2 and adds some OSG related utility procedures Note e This is the first release of the OpenSceneGraph wrapper It is far from being finished or error free and work in progress It s interface may change in the future e Check out the Tcl3D homepage for more up to date information This is an optional module Requirements for this module The OSG library and header files Libraries and header files are included in the Tcl3D distribution Implementation files tcl3dOsg tcl Header files All files in subdire
62. ight 2005 2009 by Paul Obermeier All rights reserved 5 Miscellaneous Tcl3D information Tcl3D Doing 3D with Tcl export export export iD LIBRARY PATH D DYL IBRARYN32_PATH D LIBRARY PATH tcl3dsh 0OS 0 4 1 5 5 2 Starpack issue 2 Some of the external libraries need files for initialization ex the FTGL library needs the name of a TrueType font file to construct it s OpenGL commands This font file has to be on the real filesystem so that the FTGL library can find it and not in the virtual filesystem of the starpack Tcl3D supports a utility procedure tc13dGet description of the starpack related file utilities A typical usage is shown in the following code segment ExtFile which you should use if intending to use a Tcl3D script depending on such a library in a starpack See chapter 4 3 3 for a set fontfile file join file dirname info script Vera ttf tcl3dGet You may check availabili Tcl3D versions if info proc tcl3dGetExtFile eq tcl3dGetExtFile Get the font file in a starpack independent way set fontfile tcl3dGetExtFile fontfile ExtFile is available only in versions 0 3 1 and up ty of command first if running scripts with older Tcl3D User Manual Version 0 4 1 August 2009 Copyright 2005 2009 by Paul Obermeier All rights reserved Page 57 of 65 6 Demo applications Tcl3D Doin
63. ion options behave like standard Tcl options and can be queried as such package require tcl3d or just package require tcl3dogl 4 1 togl t t configure height height Height 400 400 displayproc displayproc Displayproc t configure displayproc tclDisplayFunc t configure displayproc displayproc displayproc Displayproc tclDisplayFunc oe O oP Jeo HH oe ole Callback procedures To be usable from the Tcl level the Togl widget has been extended to support 3 new configuration options for specifying Tcl callback procedures createproc ProcName Procedure is called when a new widget is created reshapeproc ProcName Procedure is called when the widget s size is changed displayproc ProcName Procedure is called when the widget s content needs to be redrawn Default settings are createproc createproc Createproc displayproc displayproc Displayproc reshapeproc reshapeproc Reshapeproc The callback procedures must have the following signatures proc CreateProc toglwin proc ReshapeProc toglwin width height proc DisplayProc toglwin Display options Tcl3D User Manual Version 0 4 1 August 2009 Page 26 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail swapinterval multisamplebuffers multisamplesamples Default settings are Enable disable Enable disable Set the number o
64. l3dUtil Wavefront reader commands Draw a textured cube with given center and size tcl3dHelix Draw a helix with given center radius and number of twists tcl3dSphere Draw a sphere with given radius precision Table 4 15 tcl3dUtil Shape commands Examples See the demo program gaugedemo tcl for an example on how to use the Wavefront parser functions See NeHe demo program Lesson23 tcl for an example on how to use tc13dCube See NeHe demo program Lesson36 tcl for an example on how to use tc13dHelix See demo program og _benchmark_sphere tcl for an example on how to use tc13dSphere Tcl3D User Manual Version 0 4 1 August 2009 Page 45 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Implementation details The tcl3dModel and tcl3dModelFmtObj files provide a parser for reading model files in Alias Wavefront format The code to read and draw the models is a modified version of the parser from Nate Robin s OpenGL tutorial 19 The tcl3dShapes files implement a sphere based on an algorithm found at Paul Bourke s excellent pages 22 as well as a cube and a helix based on algorithms found in the NeHe tutorials 23 and 36 16 Implementation files tcl3dModel c tcl3dModelFmtObj c tcl3dShapesMisc c Header files tcl3dModel h tcl3dModelFmtObj h tcl3dShapesMisc h Wrapper files utili Note e The standard GLUT shapes are described
65. n progress It s interface may change in the future A detailed description of this module can be found in chapter 4 8 tcl3dOsg Wrapper for the OpenSceneGraph library This module wraps the OpenSceneGraph library OSG 13 and adds some OSG related utility procedures A detailed description of this module can be found in chapter 4 9 tcl3dGauges Tcl3D package for displaying gauges This package implements the following gauges as a pure Tcl package airspeed altimeter compass tilt meter A detailed description of this module can be found in chapter 4 10 Tcl3D User Manual Version 0 4 1 August 2009 Page 5 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 1 Introduction Tcl3D Doing 3D with Tcl 1 3 Library versions The following table shows a list of the library versions used in the Tcl3D infrastructure Lib Version Comment URL GLEW 1 5 1 Included in Tcl3D source tree http glew sourceforge net Togl 1 7 Modified version included in http sourceforge net projects tog Tcl3D source tree Cg 2 2 0006 http developer nvidia com object cg_toolkit html FTGL 2 1 2 http sourceforge net projects ftgl GL2PS 1 3 3 Included in Tcl3D source tree _ http Awww geuz org gl2ps ODE 0 7 0 http sourceforge net projects opende OSG 2 8 2 http www openscenegraph org SDL 1 2 9 http www libsdl org index php Libraries used forthe TcI
66. nctions based on Version 1 2 and several OpenGL extensions It is implemented with the help of the GLEW 14 library Standard shapes box sphere cylinder teapot with a GLUT compatible syntax are supplied in this module too Requirements for this module An OpenGL driver suitable for your graphics card It is recommend to download and install an up to date OpenGL driver from the manufacturer of your graphics card especially if intending to write shader programs in GLSL or Cg The master SWIG file for wrapping the OpenGL library is tel3dOgI i OpenGL library Implementation files tcl3dOg iQuery tcl tcl3dOgI Util tcl tcl3dOg Help tcl Header files glew h glu h Wrapper files glew i glewautogen i glu i The wrapping for this module is based on the header files glew h and glu h Note e The original GLEW header file is not usable for direct wrapping with Swig so it s infor mation is used for generating the wrapper files glewdefs i and glewfuncs i during the build process with Tcl script createGlewSwigFile tcl e File tcl3dOgl Help tcl is also automatically generated by script createGlewScriptFile tcl The following Tcl3D specific commands are implemented in this module Tcl3D User Manual Version 0 4 1 August 2009 Page 28 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl command tcl3d0glGetVersion tcl3d0glHaveFunc 13d0glHaveExtension HaveVe
67. ndings are shown in the console window Tcl3D User Manual Version 0 4 1 August 2009 Page 7 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 1 Introduction Tcl3D Doing 3D with Tcl _ Tcl3D intro Information Tcl3D intro Tcl3D packages OpenGL information OpenGL extensions Cg profiles 5 m rInstallation 5 z wu g h a y Sh S y Install Tcl packages Pa af O b rmm ei er Install Tcl3D demos Install external libraries Figure 1 3 Tcl3D presentation intro Binding Action o y E eee Start animation Stop animation Table 1 3 Tcl3D presentation shortcuts The presentation can also be started directly by using pres aS a command line parameter to the Tcl3D starpack Description of the Tcl3D starpack The starpack tcl3dsh can be used as e a standalone executable like wish with builtin Tcl3D e atest and presentation program for Tcl3D e an installer for the Tcl3D specific libraries the external libraries and demo programs The Tcl3D presentation is divided into 3 sections Tcl3D User Manual Version 0 4 1 August 2009 Page 8 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 1 Introduction Tcl3D Doing 3D with Tcl e Information and installation e Help and documentation e Demos and tutorials The information menu gives you access to different types of information OpenGL I Tcl3D which are shown as animated OpenGL text
68. nstallation Tcl3D Doing 3D with Tcl e The files contained in the external libraries folder extlibs should be copied into a directory which is listed in your PATH environment variable Windows or your LD_LIBRARY_PATH environment variable Unix e The demonstration programs folder demos can be copied to any convenient place of your file system Note The starpack does not contain the tcl3dOsg library files and demo applications due to space limitations Now you are ready for using Tcl3D from a standard Tcl interpreter by starting a tclsh or wish program and issuing the following command package require tcl13d Alternatively you can extract the 3 installation folders with one of the following methods e Start the Tcl3D starpack and issue the command inst in the console e Start the Tcl3D starpack with command line parameter inst Both steps will copy the 3 above described package folders into the directory containing the starpack 2 1 2 Installation from a binary package The following prerequisites are needed when using a TclI3D binary package e An OpenGL driver suitable for your graphics card It is recommend to download and install an up to date OpenGL driver from the manufacturer of your graphics card especially if intending to write shader programs in GLSL or Cg e A Tcl Tk version greater or equal to 8 4 e The Img extension is needed to have access to various image formats which are used as OpenGL textures e For some
69. profile by name 7a cl3dCgFindProfileByNum Find a supported Cg profile by it s numerical value tcl3dCgPrintProgramInfo Print the Cg program information onto standard output Table 4 18 tcl3dCg utility commands See the demo programs contained in directory LibrarySpecificDemos tcl3dCg for examples on how to use the Cg functions 4 5 tcl3dSDL Wrapper for the Simple DirectMedia Library This module wraps the SDL 8 library based on version 1 2 9 and adds some SDL related utility procedures Note e Currently only the functions related to joystick and CD ROM handling have been wrapped and tested This is an optional module Requirements for this module The SDL library and header files Libraries and header files are included in the Tcl3D distribution The master SWIG file for wrapping the Simple DirectMedia library is tel3dSDL i Tcl3D User Manual Version 0 4 1 August 2009 Page 48 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Implementation files tcl3dSDLQuery tcl tcl3dSDLUtil tcl Header files All files in subdirectory include Wrapper files sdl i The wrapping for this module is based on the unmodified SDL header files SDL utility module Get the version of the wrapped SDL library Convert a SDL focus state bitfield into a string representation Convert a SDL button state bitfield into a string representation
70. r files tcl3dDemoOgILogo h Wrapper files utili The functionality of the RedBook image parser module is implemented in the following files Implementation files _tcl3dDemoReadRedBooklmg c Header files tcl3dDemoReadRedBooklmg h Wrapper files util i The functionality of the heightmap module is implemented in the following files Tcl3D User Manual Version 0 4 1 August 2009 Page 47 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Implementation files heightmap i tcl3dDemoHeightMap tcl Header files None Wrapper files heightmap i 4 4 tcl3dCg Wrapper for NVidia s Cg shading language This module wraps NVidia s Cg 7 library based on version 2 2 0006 and adds some Cg related utility procedures This is an optional module Requirements for this module The Cg library and header files Runtime libraries are included in the Tcl3D distribution The master SWIG file for wrapping the Cg library is tel3dCg i Implementation files tcl3dCgQuery tcl tcl3dCgUtil tcl Header files All files in subdirectory Cg Wrapper files i The wrapping for this module is based on the unmodified Cg header files Cg utility module Get the version of the wrapped Cg library C 13dCgGetError Check if a Cg related error has occured H tcl3dCgGetProfileList Get a list of Cg profile names tcl3dCgFindProfile Find a supported Cg
71. representation e eee SDL event related enumerations into a string representation tcl3dSDLFrames2MSF Convert CD frames into minutes seconds frames representation representation Table 4 19 tcl3dSDL utility commands See the demo programs contained in directory LibrarySpecificDemos tcI3dSDL for examples on how to use the SDL functions 4 6 tcl3dFTGL Wrapper for the OpenGL Font Rendering Library This module wraps the FTGL 9 library based on version 2 1 2 and adds some FTGL related utility procedures The FTGL library depends on the Freetype2 library 10 This is an optional module Requirements for this module The FTGL and Freetype2 library and header files Libraries and header files are included in the Tcl3D distribution The master SWIG file for wrapping the OpenGL Font Rendering library is tel3dFTGL i Implementation files tcl3dFTGLQuery tcl tcl3dFTGLUtil tcl Header files All files in subdirectory include Wrapper files ftgl i The wrapping for this module is based on the unmodified FTGL header files FTGL utility module 13dFTGLGetVersion Get the version of the wrapped FTGL library 13dFTGLGetBBox Get bounding box of a string Table 4 20 tcl3dFTGL utility commands Tcl3D User Manual Version 0 4 1 August 2009 Page 49 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3
72. res Also take a look at the demo program og _fps_controls tcl for a real world example Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dVecMath c tcl3dVecMath tcl Header files tcl3dVecMath h Wrapper files utili 4 3 2 Information module This module provides convenience functions for querying Tcl3D package related information Overview The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Tcl3D User Manual Version 0 4 1 August 2009 Page 33 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl tcl3dHavePackage Check if a Tcl package is available in a given version tcl3dGetLibraryInfo Return the library version corresponding to supplied Tcl3D package name 1l3dGetPackageInfo Return a list of sub lists containing Tcl3D package information Each sub list contains the name of the Tcl3D sub package the availability flag 0 or 1 the sub package version as well as the version of the wrapped library 13dShowPackageInfo Display the version info returned by tcl 3dGetPackagelInfo in a toplevel window Ecl3dHavecg 13dHaveSDL tcl 3dHaveFTGL tel3dHaveGl2ps tel3dHavedsg Table 4 5 tcl3dU
73. riable Windows or your LD_LIBRARY_PATH environment variable Unix You should end up with a directory and file structure as shown in figure 2 1 If you want to build the tcl3dCg module you have to download and install the Cg toolkit version 2 2 0006 from 7 After installation copy all the Cg header files into the tcl3dCg Cg directory These files are not included in the Tcl3D distribution because of license issues The dynamic libraries of Cg are included in the Tcl3D distribution package tc13d 0S 0 4 1 zip If you want to wrap only a sub set of the supported optional modules edit the make wrap file appropriately See chapter 2 2 3 Step 3 Customization for details Version 3 Tcl3D Star Tcl3D Basic or Tcl3D Complete with starpack support Needed Installation of Version 1 or 2 Needed tcl3d starpack 0 4 1 zip Perform the steps as described for Version 1 or 2 Additionally copy the folder extlibs contained in distribution package tcl3d 0S 0 4 1 zip into the source code folder tcl3d Then unzip tcl3d starpack 0 4 1 zip into the source code folder tcl3d You should end up with a directory and file structure as shown in the next figure Tcl3D User Manual Version 0 4 1 August 2009 Page 14 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl 2 ou E config_cygwin O demos E config_Darwin 2 extlibs E config_IRIX64 O starpack E config_Linux O
74. rmeier All rights reserved 3 Wrapping in detail Tcl3D Doing 3D with Tcl TYPE SIZE void SIZE TYPE void LGetFloatv GLenum pname GLfloat params C declaration ReadPixels GLint x GLint y GLsizei width Lsizei height GLenum format Lenum type GLvoid pixels Lfloat values 2 1GetFloatv GL LINE WIDTH GRANULARITY values C example Lubyte vec malloc w h 3 lReadPixels 0 0 w h GL RGB GL UNSIGNED BYT t values tcl3dVector GLfloat 2 1GetFloatv GL LINE WIDTH GRANULARITY Svalues Tcl example set vec tcl3dVector GLubyte expr w Sh 3 lReadPixels 0 0 w h GL RGB GL UNSIGNED BYTE vec Table 3 7 Wrapping of a pointer output parameter 3 1 4 Function return values The mapping of return values is handled by the SWIG standard typemaps Scalar return values are returned as the numerical value Pointer to structs are returned with the standard SWIG mechanism of encoding the pointer in an ASCII string Function return TYPE STRUCT GLuint glGenLists GLsizei range GLUnurbs gluNewNurbsRenderer void GLuint sphereList glGenLists 1 C example GLUnurbsObj theNurb gluNewNurbsRenderer gluNurbsProperty theNurb GLU SAMPLING TOLERANCE set sphereList glGenLists 1 Tcl example set theNurb gluNewNurbsRenderer gluNurbsProperty theNurb GLU SAMPLING TOL Table 3 8 Wrapping of a function return value
75. rojmatrix set viewList tcl3dVectorToList viewport 4 set mvList tcl3dVectorToList S mvmatrix 16 set projList tcl3dVectorToList S projmatrix 16 set realy expr Sviewport get 3 y 1 set winList gluUnProject x realy 0 0 mvList projList viewList puts gluUnProject return value lindex S winList 0 puts format World coords at z 0 0 are Sf Sf Sf lindex SwinList 1 lindex SwinList 2 lindex S winList 3 Note e The above listed exceptions are only valid for the GLU library The optional modules have not been analysed in depth regarding the constness of parameters Tcl3D User Manual Version 0 4 1 August 2009 Page 23 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 3 Wrapping in detail Tcl3D Doing 3D with Tcl 3 2 Wrapping reference card e The notation TYPE stands for any scalar value char int float etc as well as inherited scalar types like GLboolean GLint GLfloat etc It is not used for type void or GLvoid e The notation STRUCT stands for any C struct C parameter type Tcl parameter type Input parameter TYPE Lboolean Lenum Lbitfield CGenum CGGLenum CGprofile CGtype CGresource CGerroz const TYPE SIZE const TYPE ist 3 x const void Output parameter TYPE void Table 3 11 Tcl3D wrapping reference zi Tcl3D User Manu
76. rsion 13d0g GetVersions tcl3d0glGetExtensions tcl3d0glGetStates tcl3d0glGetIntState tcl3d0glGetFloatState tcl3d0glGetDoubleState tcl3d0g1lGetMaxTextureSiz tcl3d0glGetMaxTextureUnits 13d0gl1GetViewport 3d0g1lGetShaderInfoLog ie tcl3d0g tShaderSource 3d0g c z cl 1Get a a GetInfoLogARB glMultiDrawElements tcl3dOglGetGlError cl3d0glShaderSource 3d0g1lGetFuncList tcl3d0glGetFuncSignatureList tcl3d0gl1GetFuncVersionhList 1G tcl3d0glGetExtSuffixes eC AL SiolOvej lL atievelln Vie tcl3d0glSetNormalMode wel Tel a tc 3dOglSetSafeMode 3dOglSetDebugMode tcl3d0glSetMode Table 4 1 tcl3dOgl helper commands Note Tcl3D Doing 3D with Tcl Get the version of the wrapped OpenGL librar Check availability of an OpenGL function in the OpenGL driver Check if a given OpenGL extension is provided by the OpenGL implementation Query the OpenGL library with the keys GL_VENDOR GL_RENDERER GL_VERSION GLU_VERSION and return the results as a list of ke Query the OpenGL library with the keys GL_EXTENSIONS and GLU EXTENSIONS and return the results as a list of Query all state variables of the OpenGL library and return the results as a list of sub lists Each sublist contains a flag indic
77. ry and start it from there as the starpack will copy external libraries into the current directory First installation tests Start a tclsh or wish shell and type the following two commands gt package require tcl3d gt t gl t Now use either the command tcl3dShowPackageInfo for graphical package information or tcl3dGet PackageInfo for textual package information If these procedures fails you may try the low level information supplied in the Tcl array __tcl3dPkgInfo gt parray _ tcl3dPkgInfo __tcl3dPkgInfo tcl3dcg avail __tcl3dPkgInfo tcl3dcg version 0 Cg library not wrapped 1 0 4 1 __tcl3dPkgInfo tcl3dftgl avail __tcl3dPkgInfo tcl3dftgl version Version Tcl3D Basic should print out information similar to the lines listed below when calling tcl3dGetPackagelInfo tcl3dcg 0 Cg library not wrapped tcl3dftgl 0 FTGL library not wrapped tcl3dgauges 1 0 4 1 tcl3dgl2ps 0 GL2PS library not wrapped tcl3dode 0 ODE library not wrapped tcl3dogl 10 4 1 1 2 APPLE 1 4 56 tcl3dosg 0 OSG library not wrapped tcl3dsdl 0 SDL library not wrapped Tcl3D User Manual Version 0 4 1 August 2009 Page 17 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 Installation Tcl3D Doing 3D with Tcl Version Tcl3D Complete should print out information similar to the lines listed below when calling tcl3dGetPackageInfo
78. s per iteration SetMethod3 659 SetMethod4 736 microseconds per iteration 3 SetMethod2 3637 8 microseconds per iteration 2 2 microseconds per iteration 4 3 6 Image utility module This module provides access to Tk photo images Overview The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter tcl3dPhotoChans Return the number of channels of a Tk photo 13dVectorToPhoto Copy from OpenGL raw image format into a Tk photo The photo image must have been initialized with the appropriate size and type 13dPhotoToVector Copy a Tk photo into a tc13dVector in OpenGL raw image format The tcl3dVector must have been allocated with the approriate size and type tcl3dvectorFromPhoto Create a new Tcl3D Vector containing the image data of a Tk photo image Only GL_UNSIGNED_ BYTE currently supported Table 4 10 tcl3dUtil Image utility commands Note e The Img extension is recommended to have access to lots of image formats Examples Example 1 Read an image into a Tk photo and use it as a texture map set texture tcl3dVector GLuint 1 Memory for 1 texture identifier proc LoadImage imgName set retVal catch set phImg image create photo file imgName err1l if retVal 0 error Error reading im
79. scalar input parameter C example Tcl example The mapping of the following enumerations is handled differently see file tc 3dConstHash They can be specified either as numerical value like the other scalar types or additionally as a name identical to the enumeration name e GLboolean GLenum GLbitfield CGenum CGGLenum CGprofile CGtype Tcl3D User Manual Version 0 4 1 August 2009 Page 19 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 3 Wrapping in detail Tcl3D Doing 3D with Tcl e CGresource e CGerror The mapping is explained using the 3 OpenGL enumeration types The Cg types are handled accordingly GLenum as function input parameter can be supplied as numerical value or as name GLenum Enable GLenum cap END Table 3 2 Wrapping of a GLenum input parameter GLbitfield as function input parameter can be supplied as numerical value or as name e A combination of bit masks has to be specified as a numerical value like this glClear expr GL_ COLOR BUFFER BIT GL_ DEPTH BUFFER BIT GLhbitfield glClear GL COLOR BUFFER BIT lear GL COLOR BUFFER BIT lear GL COLOR BUFFER _ Table 3 3 Wrapping of a GLbitfield input parameter GLboolean as function input parameter can be supplied as numerical value or as name GLboolean
80. see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Tcl3D User Manual Version 0 4 1 August 2009 Page 43 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl 13dNewSwatch Create a new stop watch and return it s identifier l3dDeleteSwatch Delete an existing stop watch a TR Ee E Table 4 12 tcl3dUtil Stop watch commands Examples See the demo program spheres tcl for an example on how to use these procedures to measure the rendering frame rate Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dUtilStopWatch c Header files tcl3dUtilStopWatch h Wrapper files utili 4 3 9 Random number module This module provides functions to generate random numbers Overview The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Tcl command Description tcl3dNewRandomGen Initialize a new random number generator tcl3dDeleteRandomGen Delete a random number generator tcl tcl Generate a pseudo random floating point number Table 4 13 tcl3dUtil Random number commands Examples See the demo program mandel
81. st 2009 Page 60 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 7 Release notes Tcl3D Doing 3D with Tcl functionality needed This is done now when creating the Togl widget The old OpenGL extension library OglExt automatically detected if OpenGL functions are not implemented in the OpenGL driver and did nothing in that case This had the disadvantage that programs seem to run but indeed were missing an extension function New OpenGL utility procedures tcl3d0glHaveFunc tcl3d0glGetFuncList tcl3d0glGetFuncSignatureList tcl3d0glGetFuncVersionList CAUTION Possibly incompatible change Togl s command line parameter swapinterval is set to zero by default so that demos always run with maximum framerate instead of being fixed to the display s refresh rate Removed now obsolete swapinterval 0 statements in several demos Demo tcl3dInfo tcl updated to display OpenGL version information function signature and availability of all wrapped OpenGL functions User and reference manuals updated Bug fixes GLEW has wrong glPointParameterfv functions signatures float instead of const float according to OpenGL standard Changed in glew h file tcl3dVecMath c had incorrect tcl3dMatfRotate function Thanks to Stefan Augustiniack for patch Removed features Removed obsolete versions 0 1 and 0 2 from Tcl3D homepage Removed compatibility function
82. swigfiles E config _Linux64 5 td3dcg E config_mingw tcl3dFTGL E config_win32 4 O tel3dGauges E make macros H tcl3delzps E make oscheck O tcl3dode E make wrap O tcladogl E Makefile tel3dosq E pkgIndex tcl O tel3d5DL E Readme txt Tel3D_Announce txt E Tcl3D_License txt Figure 2 2 Tcl3D Complete starpack directory structure Note e The starpack distribution package contains Tclkits for all supported operating systems as well as supporting Tcl packages tklmg snack needed for the Tcl3D demonstration programs 2 2 2 Step 2 Configuration Before compiling edit the appropriate config_ file to fit your platform compiler combination Windows gcc config Linu Linux 32 bit gcc Z Linux 64 bit config Linux64 i Mac OS X SGI RIX 6 5 gcc MIPS Pro 7 3 config_IRIX64 Table 2 3 TcI3D configuration files Note e Visual C 6 0 and CygWin support have been deprecated Visual Studio NET 2003 corresponds to compiler version 7 1 Visual Studio 2005 corresponds to compiler version 8 0 Visual Studio 2008 corresponds to compiler version 9 0 To detect if using a DOS console for compilation the existence of environment variable VSINSTALLDIR is checked This variable is also used to detect a NET compiler i e VS2005 or VS2008 which need manifests e For Unix systems the name after the underscore is derived from the Unix commands uname s and uname m See the
83. th 2 new SWIG commands Tcl3D User Manual Version 0 4 1 August 2009 Page 38 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl sbaseTypeVector for scalar types and complexTypeVector for complex types like structs It not only creates setter and getter functions for accessing single elements of the allocated memory but also adds functions to set ranges of the allocated memory Wrapper functions for the following scalar types are defined in file tcl3dVectors i is mapped to unsigned short int int ooo int Note e tcl3dVectors of type char unsigned char GLchar and GLcharARB are not supported because the corresponding typemaps would collide with the standard SWIG mapping for C strings Use types GLbyte and GLubyte if you need tcl3dVectors with element sizes of 1 byte The generated wrapper code looks like this Example shown for GLdouble Q Q c O K dt oO Q Q iiil Q Q Q static double new_GLdouble int nelements return double calloc nelements sizeof double static void delete _GLdouble double ary free ary static double GLdouble_getitem double ary int index return ary index static void GLdouble_ setitem double ary int index double value ary index value static void GLdouble_setvector double ary double value int st
84. the dot product of two 3D vectors tcl3dVec3f CrossProduct Calculate the cross product of two 3D vectors tcl3dvec3fAdd Add two 3D vectors tcl3dVec3fSubtract Subtract two 3D vectors tcl3dVec3fScale Scale a 3D vector by a scalar value tcl3dVec3fPlaneNormal Create a plane normal defined by three points Table 4 3 tcl3dUtil 3D vector commands Tcl3D User Manual Version 0 4 1 August 2009 Page 32 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Print the contents of a matrix onto standard output tcl3dMatfCompare Compare two transformation matrices crsa ECOPY tf tel plese Build a rotation matrix based on angle around y axis Build a rotation matrix based on angle around z axis Build a scale matrix based on a 3D vector Build a scale matrix based on 3 scalar values Transform a point by a given matrix Build a rotation matrix based on angle around x axis fTransformVector Transform a 3D vector by a given matrix t Multiply two transformation matrices fInvert Invert a transformation matrix tfTranspose Transpose a transformation matrix Table 4 4 tcl3dUtil Matrix commands 1 a i tcl3dMatfIdentity Build the identity transformation matrix tcl a i Examples See the test programs matmathtest tcl and vecmathtest tcl for examples on how to use these procedu
85. therefore always check either the OpenGL version implemented in your driver tcl3d0glHaveVersion the availability of the extensions you intend to use tcl3d0glHaveExtension or to be absolutely sure check the availability of each OpenGL function in your initialization code tc13d0glHaveFunc Starting with Tcl3D version 0 4 1 the utility procedure tcl3dSetSafeMode can be used to avoid core dumps and to get information about which OpenGL functions are not available in your driver Use the demo tcel3dInfo tcl to get information about the supported OpenGL functions of your installed OpenGL driver 5 3 Open issues e 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 e 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 must be handled by the Tog widget 5 4 Known bugs e The tiltmeter widget from the tcl3dGauge package is not working correctly with Tcl versions less than 8 4 7 because of a bug in the namespace implementation e 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 1 As Tcl only supports signed integers some depth values are incorrectly transferred into the Tcl
86. ties to install a Tcl3D binary distribution onto your computer 2 1 1 Installation from a Tcl3D starpack The following prerequisites are needed when installing from a Tcl3D starpack e An OpenGL driver suitable for your graphics card It is recommend to download and install an up to date OpenGL driver from the manufacturer of your graphics card especially if intending to write shader programs in GLSL or Cg Download unzip and start a Tcl3D starpack presentation as described in chapter 1 5 In the right menu pane you will see 3 buttons in the Installation and Information menu see Figure 1 3 on page 8 These allow you to extract the Tcl3D packages tcl3d0 4 1 the external libraries extlibs and the demo programs demos onto the file system so you can use TcI3D from tclsh or wish e The Tcl3D package folder tc 3d0 4 1 should be copied into the library section of your Tcl installation ex C Tcl lib If write access to this Tcl directory is not permitted you can copy the tcl3d0 4 1 directory somewhere else eg C mytcl3d or home user mytcl3d To have Tcl look for packages in this location you must set the TCLLIBPATH environment variable with the above specified directory name as value Note that on Windows the path must be written with slashes not backslashes set TCLLIBPATH C mytcl3d Tcl3D User Manual Version 0 4 1 August 2009 Page 11 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 2 I
87. til Information commands Examples The following code snippet shows how to call tc13dGetPackageInfo foreach pkgInfo tcl3dGetPackageInfo puts lindex SpkgInfo 0 lindex S pkgInfo 1 tcl3dcg 1 0 4 1 2 2 0006 tcl3dftgl 10 4 1 2 1 2 tcl3dgauges 1 0 4 1 tcl3dgl2ps 1 0 4 1 1 3 3 tcl3dode 1 0 4 1 0 7 0 tcl3dogl 10 4 1 1 2 APPLE 1 4 56 tcl3dosg 1 0 4 1 2 8 2 tcl3dsdl 10 4 1 1 2 9 Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dUtillnfo tcl Header files None Wrapper files None 4 3 3 File utility module This module provides miscellaneous functions for file related tasks Handling of temporary directories and file access from a starpack Overview The following table lists the available functions of this module For a detailed description of the functions see the Tcl3D Reference Manual 5 or the source code files as listed in section Implementation details at the end of this chapter Tcl3D User Manual Version 0 4 1 August 2009 Page 34 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl tcl3dGetTmpDir Get the name of a temporary directory tcl3dCreateTmpDir Create a unique temporary directory tcl3dGenExtName Create a name on the file system Use this function if writing to a file from a script which m
88. tor subcommands Examples The following example shows the usage of the tc13dVector command set ind 23 set vec tcl3dVector GLfloat 123 Svec set Sind 1017 0 set x Svec get Sind Svec addvec 33 2 10 Svec delete Create Vector of 123 GLfloats Set element at index 23 to 1017 0 Get element at index 23 Add 33 to ten elements starting at index 2 Free the allocated memory Ne Ne Na Sa Ne Note e Indices start at zero The following example shows the usage of the tcl 3dVectorFromLinspace command t Create a GLdouble vector of length 5 with values from 0 to 0 1 gt set v tcl3dVectorFromLinspace GLdouble 0 0 1 5 gt Lelsdvicerore mimi S 000 025 050 2075 100 E a OO DOLLS See also the test program vectorlinspace tcl for more examples See the demo program bytearray tc l and vecmanip tcl for examples on how to use the ByteArray procedures for generating textures in Tcl Implementation details The functionality of this module is implemented in the following files Implementation files tcl3dVector tcl Header files None Wrapper files vector i bytearray i As stated in chapter 3 1 2 some of the OpenGL functions need a pointer to a contiguous block of allocated memory SWIG already provides a feature to automatically generate wrapper functions for allocating and freeing memory of any type This SWIG feature Sarray functions has been extended and replaced wi
89. ts Demo scripts GL_Blending tel Lesson01 tcl ogl_alpha_blending_frarm ogl_alpha_blending_textu ogl_axis_aligned_billboarc ogl_benchmark_sphere te ogl_cg_multitexture tcl ogl_color_tracking tcl GL_Motionblur tel GL_Primitives tcl Lesson06 tcl Figure 6 1 TclI3D demo hierarchy Tcl3D User Manual Version 0 4 1 August 2009 Page 58 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 7 Release notes Tcl3D Doing 3D with Tcl 7 Release notes This chapter shows the release and feature history of Tcl3D both graphically and in text form It also contains a list of obsolete functions 7 1 Release history Tcl3D Version 0 1 Released 2005 05 29 as TclOgl Basic OpenGL wrapping Tog widget with Tcl callbacks Tcl3D Demos and Applications SWIG generated Tcl interfaces Tcl Interface Tcl3D Version 0 3 Released 2006 02 12 Enhanced font handling in Togl Library FTGL added Mac OS X support supplied by Daniel Steffen Tcl3D Demos and Applications tcl3dGauges Tcl Extension Package SWIG generated Tcl interfaces Tcl Interface Cg Shading Joystick and CD Font Rendering Tcl3D Version 0 3 2 Released 2007 02 25 Demo cleanup and first official Mac OS X support Windowing system specifics incorporated into Togl widget New module tcl3dDemouUtil Tcl3D Demos and Applications tcl3dGauges Tcl Extension Package SWIG generated Tcl interfaces
90. unctions are mapped to Tcl commands e C constants are mapped to Tcl global variables e Some C enumerations are mapped to Tcl global variables and are inserted into a Tcl hash table for lookup by name The mapping described in this chapter is consistently applied to all libraries wrapped with Tcl3D It is optimized to work best with the OpenGL interface 3 1 Wrapping description Conventions used in this chapter e Every type of parameter is explained with a typical example from the OpenGL wrapping e The notation TYPE stands for any scalar value char int float enum etc as well as inherited scalar types like GLboolean GLint GLfloat etc It is not used for type void or GLvoid e The notation struct stands for any C struct e The decision how to map C to Tcl types was mainly inspired to fit the needs of the OpenGL library best The same conventions are used for the optional modules too e Function parameters declared as const pointers are interpreted as input parameters Parameters declared as pointer are interpreted output parameters 3 1 1 Scalar input parameters The mapping of most scalar types is handled by SWIG standard typemaps Scalar types as function input parameter must be supplied as numerical value Input parameter TYPE C declaration void glTranslatef GLfloat x GLfloat y GLfloat z lTranslatef 1 0 2 0 3 0 lTranslatef x y Z tef 1 0 2 0 3 0 tef x Sy z Table 3 1 Wrapping of a
91. xMode GL PROJECTION 7 Select the projection matrix glLoadIdentity Reset the projection matrix Calculate the aspect ratio of the window gluPerspective 45 0 expr double w double h 0 1 100 0 glMatrixMode GL MODELVIEW Select the modelview matrix glLoadIdentity 7 Reset the modelview matrix proc tclDisplayFunc toglwin Clear color and depth buffer glClear expr GL COLOR BUFFER BIT GL DEPTH BUFFER BIT glLoadIdentity Reset the current modelview matrix glTranslatef 0 0 0 0 5 0 Transformations glRotatef xrot 1 0 0 0 0 0 glRotatef yrot 0 0 1 0 0 0 glRotatef zrot 0 0 0 0 1 0 drawGeometry Draw the actual geometry Swap front and back buffer Tcl3D User Manual Version 0 4 1 August 2009 Page 27 of 65 Copyright 2005 2009 by Paul Obermeier All rights reserved 4 Modules in detail Tcl3D Doing 3D with Tcl Create a Togl widget with a depth buffer and doublebuffering enabled togl fr toglwin width 250 height 250 double true depth true createproc tclCreateFunc reshapeproc tclReshapeFunc displayproc tclDisplayFunc grid fr toglwin row 0 column 0 sticky news Note e Option createproc is not effective when specified in the configure subcommand It has to be specified at widget creation time 4 2 tcl3dOgl gt OpenGL Wrapper for OpenGL functionality This module wraps OpenGL functionality up to OpenGL Version 3 0 GLU library fu
Download Pdf Manuals
Related Search
Related Contents
RBK 835 Manuals (Portuguese) Manual Fabricante PDF Job#2878 Hysol 050 LT-4175 MANUAL DEL OPERADOR Canon F-718SGA Emulator Copyright © All rights reserved.
Failed to retrieve file