Scenegraphs
I’ve been working with opengl since 2001, when I switched from Flash/Director to writing C/C++ with OpenGL. It didn’t take too long to get the basics of OpenGL, find some demos similar to what I wanted to do and then code something up. But I found the C/C++ hard to tinker with, to add bits onto and experiment. It’s ok if you know exactly what you want to make, but not great for exploration.
I then looked around and found Python a very rich scripting language with hundreds of add on projects. The more I use Python the more I like it, its what programming should be like for artists. Python has an OpenGL interface and so I was quite quickly about to develop some projects, but again I ran into some snags. I’d been unhappy with how my software was dealing with transparency, and I was trying to implement an order independent transparency algorithim developed by Cass Everitt of Nvidia in 2001 with Python.
OpenGL is a developing low level computer graphics language origninally developed by Silicon Graphics in the 1980’s for their workstations. In the past few years it has developed rapidly with many extensions added to the language by 3D graphics cards manufacturers to take advantage of new hardware capability and conceptual advances such as vertex and fragment shaders. The Python interface is built on top of the C/C++ one which requires wrapping code to make it accessible, and many of these extensions had not yet been wrapped. After several days work I stopped and took stock, and considered what I really wanted:
- I really wanted to continue working with Python, the flexibility and power was what expressive programming should be like
- State management in OpenGL was painful in complex projects, keeping track of matrix transformation, lighting models, blending modes etc
- I wanted things like transparency to be managed for me, and I wanted to be able to use things like shaders if I wanted
- Ideally I wanted multi pipe rendering, to be able to render onto multiple screens, even multiple computers across a network.
- I didn’t want a game engine, because usually they are too restrictive in what type of graphics takes place, but I wanted something more high performance that a visualisation toolkit.
I started looking around, and came across Coin3D which had an implementation of order independent transparency, Coin is an open source project built upon the OpenInventor code. Inventor was a toolkit developed by SGI in the 1990’s as an accessible toolkit for developing graphical applications for visualisation. It is a mature toolkit with good documentation and lots of example code, and also has good python bindings through a project called pivy. Coin/Pivy give good low level access to OpenGL. I quite quickly found though that the order independent transparency technique doesn’t work with textures (which I use to place type on surfaces). So it really wasn’t much use to me anyway. Coin at that time didn’t seem to have support for shaders in the distribution and the age of the design made me question the suitability for what I wanted. Time to take stock again.
I had been looking at scenegraphs on and off since mid 2003, but had never had the time to try them out, and had always been a bit concerned about the restrictions they would place on the way that ideas and forms were used in OpenGL. But I had begun to realise that if I didn’t use an existing scenegraph I would wind up writing my own, which would not be that productive. Based on this ongoing investigation I got this down to three opensource projects with python bindings:
- Ogre3D - has a good reputation as a well designed graphics engine, it is cross platform and uses either OpenGL or Direct3D, it seems more orientated towards Game type applications. I’d looked at this project many times and had seriously considered using it. It has good documentation and examples, but seemed kind of heavy and abstracted which had put me off.
- Coin3D - as previously mentioned.
- OpenSceneGraph - Again I had looked at this project several times, but had always been put off by the web site, which looks daggy and is not terribly well organised.
I decided to look at OpenSceneGraph more closely, I found that it was a development from ideas of the earlier SGI Performer toolkit, which while a relative of Inventor, the emphasis of Performer was on simulation rather than visualisation. OpenSceneGraph (OSG) had an impressive range of features:
- Was based around OpenGL and so was tightly coupled to it (not too abstracted).
- Had an active community of developers
- Had high quality code
- Support for latest OpenGL extensions and methods, FBO’s VBO’s, shaders etc
- Powerful built in functionality (truetype font support, multipipe rendering, transparency, shadows etc)
- A good range of sample code
On the downsides though, the documentation isn’t great, no tutorials, or much general documentation, just api docs generated from the source code. Also the Python interface was a bit out of date and incomplete. At the moment it feels like the most powerful available and suitable option.
Note - several months later: I’ve continued to work with OpenSceneGraph, and am now committed to it, it has worked well for just about everything I have tried with it. I did have to spend quite some time in updating the python bindings, and in learning far more C++ that I really wanted to, at times I because quite stressed that I was having to spend all this time on learning an arcane software language and the intricacies of the boost.python interface api.