[osg-users] SpeedTree example

Albino Rodrigues 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
now.

 

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 -
http://www.openscenegraph.org/projects/osg/attachment/wiki/Support/Tutorials
/Tuto10.zip 

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

{

            float afProjection[16];

            float afModelView[16];

            

            glGetFloatv(GL_PROJECTION_MATRIX, afProjection); 

            glGetFloatv(GL_MODELVIEW_MATRIX, afModelView);

 

            glPushAttrib(GL_ALL_ATTRIB_BITS);

            

//for obvious reasons, IDV code isn't shown. 

//Update the forest camera

//Update time

//Draw

            

            glPopAttrib();

 

            //renderInfo.getState()->apply(); //needed?

 

}

 

//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

{

              osg::BoundingBox b;

              return b;

}

 

Test Application (will just paste the relevant code):

 

int main()

{

 

      //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.

viewer->getCamera()->getGraphicsContext()->makeCurrent(); 

       if (!bGlewInitialized)

       {

             GLenum err = glewInit( );

             if (err != GLEW_OK)

             {

                   printf("GLEW initialization failed: %s\n",
glewGetErrorString(err));

                   exit(-1);

             }

       }

 

//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

//application.

 

//set forest lighting

 

//populate from forest file

 

//set fog - horrible looking!

 

//set lod

 

//set projection

 

//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

forestDrawable->setUseDisplayList(false);

osg::Geode *fGeode = new osg::Geode();

      //fGeode->setStateSet(speedTreeState);

      fGeode->addDrawable(forestDrawable);

root->addChild(fGeode);

 

while(!viewer->done() )

      {           

            viewer->frame();

}

}

 

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!

 

Bino

 

 

From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Seppo
Laukkanen
Sent: Saturday, August 23, 2008 9:19 PM
To: osg-users at lists.openscenegraph.org
Subject: [osg-users] SpeedTree example

 

Hi!

 

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?

 

 

Thanks!

Seppo 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080907/e1cd6a5b/attachment-0002.htm>


More information about the osg-users mailing list