[osg-users] SpeedTree example
bino at vrspace.com.au
Sat Sep 6 15:06:11 PDT 2008
My apologizes for the late reply. You've no doubt got something working by
The following is what I did to work out quickly how to get speed tree
working in OSG using a custom drawable. The lead coder has since taken this
and implemented it a much nicer fashion.
First of all, I recommend reading all the documentation. There's not too
much of it to go through. But it will help you plan the best way to
integrate osg for your needs and develop a workflow around it. Also go
through the reference application OpenGL example line by line. Make changes
here and there and see the effect of it.
If you plan on going down the custom drawable route, check out -
It's a good tutorial on custom drawables.
In essence, the implementation can be distilled like so:
- Create a speed tree forest
- Create a custom drawable to draw speed tree forest using the
reference application code
- Add custom drawable to a geode
- Add it to the scene
This implementation is by no means the best way of doing things. I chose
this for the following reasons:
- Easy to implement
- Suited my employer's immediate needs
We anticipate it will have troubles when we start creating scene with a lot
of alpha transparencies on objects. So if anyone reading has solved this
problem, I'd love to hear your method.
Before coding, I recommended creating a simple terrain model, and a
SpeedTree forest for this model in your modeling tool of choice.
Custom Drawable (ignore the dodgy formatting from copy\pasting):
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
//for obvious reasons, IDV code isn't shown.
//Update the forest camera
//Based on Robert's advice. Return a default bounding box so that osg
doesn't cull this forest drawable
//This implementation relies solely on SpeedTree's culling and LODing
virtual osg::BoundingBox computeBound() const
Test Application (will just paste the relevant code):
//Create your osg stuff, root node etc
//Setup terrain model
//I couldn't find a way around this. You have to init glew.
//I can't remember what happens if you don't do this. but I suspect it's
less than ideal.
GLenum err = glewInit( );
if (err != GLEW_OK)
printf("GLEW initialization failed: %s\n",
//create your speed tree forests (again IDV code, so look at the reference
application). Store them in the supplied //vector if you need.
//you could of course do this in the custom drawable. I just happened to do
it here as I was following the reference
//set forest lighting
//populate from forest file
//set fog - horrible looking!
//set lod distances
//I then created an OSG stateset that replicated the reference app. But I
found it wasn't needed using
//the custom drawable code. Experiment.
//Create a Forest Drawable
osg::Geode *fGeode = new osg::Geode();
You'll probably come across weird problems, but that's the probably the
easiest way to get SpeedTree into OSG. But keep in mind it's far from ideal.
So evaluate it to see if it meets your needs. Best of luck!
From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Seppo
Sent: Saturday, August 23, 2008 9:19 PM
To: osg-users at lists.openscenegraph.org
Subject: [osg-users] SpeedTree example
I read from posts that people have been successful to integrate SpeedTree to
OSG at least by "1. alternative: Just use the opengl example from speedtree
and wrap it with a custom drawable.".
Is it possible for someone who have accomplished this to put some short
example etc how to get started?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the osg-users