Version 2 (modified by martin, 7 years ago)

--

[#top] Follows are Fequently asked questions.

More FAQs about OSG may be found at [3drealtimesimulation].

Note at the bottom of page there links to the previous two Wiki FAQ's which have now been ported across to this FAQ.


Q: I have no idea what [=OpenSceneGraph=? is, can you give me a short description?] \\ [[{{FAQ}}#faq_02 Q: Where can I get info on [=OpenSceneGraph=]?]] \\ [[{{FAQ}}#faq_03 Q: Whats the difference beween your Open Scene Graph and the one from [=www.opensg.org=]?]] \\ [[{{FAQ}}#faq_04 Q: I've heard that there will be a book published about OSG. When will it be available?]] \\ [[{{FAQ}}#faq_05 Q: I'm not using MS Visual Studio. Does [=OpenSceneGraph=] support other Compilers, like mingw32?]] \\ [[{{FAQ}}#faq_06 Q: Where is the reference manual for the .osg language? I searched all the project's "documentation" folders.]] \\ [[{{FAQ}}#faq_07 Q: Can I get CVS access so I can keep up to date with the latest source easily?]] \\ [[{{FAQ}}#faq_08 Q: Help! [=VisualStudio?=] won't load the OSG project files.]] \\ [[{{FAQ}}#faq_09 Q: Where is the camera class for [=OpenSceneGraph=]?]] \\ [[{{FAQ}}#faq_10 Q: When I try to save a node to file, osg crashes. I'm using Windows. Or, STL is playing up for me in [=VisualStudio?=].]] \\ [[{{FAQ}}#faq_11 Q: How do I render terrain in OSG?]] \\ [[{{FAQ}}#faq_12 Q: I can't get GLUT working, or GLUT doesn't provide feature X]] \\ [[{{FAQ}}#faq_13 Q: Is it possible to render a scene in 2D?]] \\ [[{{FAQ}}#faq_14 Q: How do I move models around once they are in the scene?]] \\ [[{{FAQ}}#faq_15 Q: How come the mountain in the hanglider demo is completely white with no shading?]] \\ [[{{FAQ}}#faq_16 Q: Everything is compiled, but there are linking problems, or when I run it crashes.]] \\ [[{{FAQ}}#faq_17 Q: I get a lot of warnings along the lines of...]] \\ [[{{FAQ}}#faq_18 Q: I have a matrix math question...]] \\ [[{{FAQ}}#faq_19 Q: How do I do skeletal animation?]] \\ [[{{FAQ}}#faq_20 Q: Why does osg seem to ignore my near/far clipping planes?]] \\ [[{{FAQ}}#faq_21 Q: If I let [=OpenSceneGraph=] calculate my near and far clipping planes, how do I get them?]] \\ [[{{FAQ}}#faq_22 Q: Is there a tutorial available?]] \\ [[{{FAQ}}#faq_23 Q: During compile I get errors about Producer/*: No such file or directory. Why? - happens with daily builds and 0.9.4-2 official.]] \\ [[{{FAQ}}#faq_24 Q: What file formats are supported by [=OpenSceneGraph=]?]] \\ [[{{FAQ}}#faq_25 Q: Why do the OSG header files not have a .h or .hpp extension?]] \\ [[{{FAQ}}#faq_26 Q: What can I do to make my editor recognize OSG headers as C++ files?]] \\ [[{{FAQ}}#faq_27 Q: I am trying to run Open Scene Graph example programs under Mac OSX, but no window appears! What can I do?]] \\ [[{{FAQ}}#faq_28 Q: How do I increase the verbosity of my program for debugging purposes?]] \\ [[{{FAQ}}#faq_29 Q: Qt and other GUI frameworks have adapters available in the contribs. Is there one for Gnome/GTK+?]] \\ [[{{FAQ}}#faq_30 Q: Hey, this particle system is cool, but looks strange when I position it in my scene. What's up?]] \\ [[{{FAQ}}#faq_31 Q: I'm having a problem using a [=PrimitiveSet?=] to represent a single point, OR my geometry seems to dissapear as it gets very far away. What's wrong?]] \\ [[{{FAQ}}#faq_32 Q: When I apply a scaling factor in a [=MatrixTransform?=], my models are washed out or dark. What's up?]] \\ [[{{FAQ}}#faq_33 Q: How do i insert comments in a .osg data file? Or, how do I comment out a block within a .osg file?]] \\ [[{{FAQ}}#faq_34 Q: Can I use OSG within an existing renderer?]] \\ [[{{FAQ}}#faq_35 Q: I have a class derived of off osg::Drawable, but the drawImplementation is called only once!]] \\ [[{{FAQ}}#faq_36 Q: Can I use opengl commands directly in OSG ?]] \\ [[{{FAQ}}#faq_37 Q: Can I use OSG without Producer, and/or with already created MFC or [=WxWindow?=] windows ?]] \\ [[{{FAQ}}#faq_38 Q: How can I contribue to the [=OpenSceneGraph=]?]] \\ [[{{FAQ}}#faq_39 Q: How can I get the [=BoundingBox?=] for a loaded Node or 3D model?]] \\ [[{{FAQ}}#faq_40 Q: When using multiple viewers and/or multiple rendering windows, I get weird results and my textures don't display correctly.]] \\ [[{{FAQ}}#faq_41 Q: I have two or more views sharing a scene graph, but I want to limit what part of the scene graph is shown in one or more of the views. How do I do that?]] \\ [[{{FAQ}}#faq_42 Q: On previous question - Yeah but.... it didn't work!]] \\ [[{{FAQ}}#faq_43 Q: How do I capture a screengrab?]] \\ [[{{FAQ}}#faq_44 Q: How can I change the Producer icon at run-time?]] \\ [[{{FAQ}}#faq_45 Q: How can I add a new wiki-page?]] \\ [[{{FAQ}}#faq_46 Q: Why does my framerate drop when rendering point sprites to an FBO/pbuffer?]] \\


#faq_01 !!!Q: I have no idea what [=OpenSceneGraph=] is, can you give me a short description? [=A:=] It is a 3D graphics library for C++ programmers. A KnowledgeBase/SceneGraph? library allows you to represent objects in a scene with a graph data structure which allows you to group related objects that share some properties together so you can specify common properties for the whole group in one place. [=OpenSceneGraph=] can then be used to automatically manage things like the level of detail necessary to draw the scene faithfully but without unnecessary detail which slows down the graphics hardware drawing the scene. [[<<]][...top]

[#faq_02] !!!Q: Where can I get info on [=OpenSceneGraph=]? [=A:=] Try these locations: ->The official homepage %newwin%http://openscenegraph.org/ ->The news mailing list %newwin%http://openscenegraph.org/mailman/listinfo/osg-news ->The users' mailing list %newwin%http://openscenegraph.org/mailman/listinfo/osg-users [[<<]][...top]

[#faq_03] !!!Q: Whats the difference beween your Open Scene Graph and the one from [=www.opensg.org=]? [=A:=] Try these comments:

->%newwin%http://donburns.net/osgarchiver/archives/June2004/0615.html ->%newwin%http://donburns.net/osgarchiver/archives/August2003/0410.html [[<<]][...top]

[#faq_04] !!!Q: I've heard that there will be a book published about OSG. When will it be available? [=A:=] Available now http://www.osgbooks.com and constantly under revision to kep up with changes in OSG. Purchasing the books helps fund this effort. More OSG books, not just revisions, are planned for the future. [[<<]][...top]

[#faq_05] !!!Q: I'm not using MS Visual Studio. Does [=OpenSceneGraph=] support other Compilers, like mingw32? [=A:=] There is a build in the distribution for Cygwin and Mingw, but they are primarily supported by folks on the mailing list. [[<<]][...top]

[#faq_06] !!!Q. Where is the reference manual for the .osg language? I searched all the project's "documentation" folders. [=A:=] KnowledgeBase/UseTheSourceLuke?! There is no documentation yet for the scene description language. [[<<]][...top]

[#faq_07] !!!Q: Can I get CVS access so I can keep up to date with the latest source easily? [=A:=] Yes! See the documentation on how to set up CVS/{{CVS}} access to the development version of the [=OpenSceneGraph=] [[<<]][...top]

[#faq_08] !!!Q: Help! [=VisualStudio?=] won't load the OSG project files. [=A:=] If you're getting the message "This makefile was not generated by Developer Studio", the .dsp's were somehow saved with Unix style endlines. You can fix this any number of ways. Suggestions include: Open and Save the dsp in Wordpad, use the cygwin utility unix2dos, or open the daily tarball in Winzip (after checking "TAR File Smart CR/LF conversion" in Options->Configuration->Miscellaneous). [[<<]][...top]

[#faq_09] !!!Q: Where is the camera class for [=OpenSceneGraph=]? [=A:=] You have three options:

#(Recommended) Use Producer. See %newwin%http://www.andesengineering.com/Producer/index.html .

#Use osgUtil::[=SceneView?=] and osg::Matrix. #Make your own class. [[<<]][...top]

[#faq_10] !!!Q: When I try to save a node to file, osg crashes. I'm using Windows. Or, STL is playing up for me in [=VisualStudio?=]. [=A:=] This is a known problem with the MS implementation of STL. The current solution is to use [=STLport=] (%newwin%http://www.stlport.org/) and make sure you have the latest service pack for VS. If problems persist, make sure you clean your original [=OpenSceneGraph=] build and recompile from scratch. The next version of VC++ (dot net, version 7) has a fixed STL implementation, so you wont need [=STLport=] after that. [[<<]][...top]

[#faq_11] !!!Q: How do I render terrain in OSG? [=A:=] The [=OpenSceneGraph=] now has the [[Documentation/ReferenceGuidesOsgTerrain osgTerrain]] KnowledgeBase/NodeKit? for generation large paged geospatial databases.

If you wish to use a continous level of details approach to terrain see Demeter (%newwin%http://www.terrainengine.com/) and Virtual Terrain Project (%newwin%http://www.vterrain.org/) for detailed open source approaches. [[<<]][...top]

[#faq_12] !!!Q: I can't get GLUT working, or GLUT doesn't provide feature X [=A:=] You're better off using [=wxWidgets=] (%newwin%http://www.wxwidgets.org/) or Simple Direct Media Layer (http://www.libsdl.org/). Both are KnowledgeBase/OpenSource? and provide the KnowledgeBase?/OpenGL renderpanes for OSG to work on. [[<<]][...top]

[#faq_13] !!!Q: Is it possible to render a scene in 2D? [=A:=] For a code sample have a look at examples/osghud.cpp. This creates a subgraph for viewing the 3D scene, and a second subgraph which sits along side it with a [=osg::Projection & osg::MatrixTransform?=] nodes to set up the orthographic views for drawing the 2D scene over the top. [[<<]][...top]

[#faq_14] !!!Q: How do I move models around once they are in the scene? [=A:=] Add the Node in question to a Transform. This allows you to move your model around the scene by changing the Transform. Take a look at the osgreflect example, which uses Transform to create a mirror image of a model. [[<<]][...top]

[#faq_15] !!!Q: How come the mountain in the hanglider demo is completely white with no shading? [=A:=] There are two likely causes: The program is not linking to osgdb_rgb. You need to compile the rgb plugin.

#The program is not picking up the datafiles it requires (textures). #Make sure that you have downloaded the demo datafiles archive and extracted them. Make sure that the environment variables in the INSTALL file are set correctly, as these tell the viewer where to find the data. As of writing they were OSGHOME, OSGDATA and OSGFILEPATH. To set the environment variables in Windows go to control panel->system->advanced->environment variables. [[<<]][...top]

[#faq_16] !!!Q: Everything is compiled, but there are linking problems, or when I run it crashes. [=A:=] Try a make clean, then make. This problem is sometimes caused by a change in the api or a project setting/library has been changed. Doing a clean recompile of everything from scratch can fix the problem.

Linking errors are also often caused by omitting libraries in Visual Studio. Go to Project->Settings and under the Link tab check to see that for every .dll you want to use, the equivalent .lib file is listed under [="Object/library Modules"=]. For example, in order to link to the core debug library osgd.dll, osgd.lib should be listed. The search path for these libraries is under Tools->Options->Directories. [[<<]][...top]

[#faq_17] !!!Q: I get a lot of warnings along the lines of... \\ ->warning C4541: 'dynamic_cast' used on polymorphic type 'class osg::Object' with /GR- [=A:=] You need to enable run-time type identification. For [=VisualStudio?=], you can put /GR in the project options. Or find this option in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click C++ Language in the Category box. There's a checkbox right there for "Enable RTTI". [[<<]][...top]

[#faq_18] !!!Q: I have a matrix math question... [=A:=] First check: %newwin%http://www.j3d.org/matrix_faq/ [[<<]][...top]

[#faq_19] !!!Q: How do I do skeletal animation? [=A:=] Check out osgCal which integrates the OSG with [=Cal3D=] - %newwin%http://osgcal.sourceforge.net/ [[<<]][...top]

[#faq_20] !!!Q. Why does osg seem to ignore my near/far clipping planes? [=A:=] When using [=osgUtil::SceneView?=], near and far clipping planes are recomputed on the fly based on eyepoint and viewable scene. This is designed to optimize the near/far range of the depth buffer, which might otherwise contain "z-fighting" artifacts if near and far are set to unreasonably small or large values.

You can override this behavior by calling:

->@@[=sceneview->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR)=]@@

If you are using [=osgProducer::viewer=] use:

->@@[=viewer.getCullSettings().setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR);=]@@ [[<<]][...top]

[#faq_21] !!!Q. If I let [=OpenSceneGraph=] calculate my near and far clipping planes, how do I get them? [=A:=] This info is available through the cull visitor, so:

->@@[=sceneView->getCullVisitor()->getCalculatedNearPlane();=]@@ ->@@[=sceneView->getCullVisitor()->getCalculatedFarPlane();=]@@ [[<<]][...top]

[#faq_22] !!!Q: Is there a tutorial available? [=A:=] There are a number of tutorials available at Documentation Documentation/Tutorials. [[<<]][...top]

[#faq_23] !!!Q: During compile I get errors about Producer/*: No such file or directory. Why? - happens with daily builds and 0.9.4-2 official. [=A:=] First build and install %newwin%[OpenProducer]. [[<<]][...top]

[#faq_24] !!!Q: What file formats are supported by [=OpenSceneGraph=]? [=A:=] File input and output is supported through the plugins in the src/osgPlugins directory of the source distribution. Here is the listing of this directory as of 17 July 2003:

->@@\3dc@@ ->@@ac3d@@ ->@@bmp@@ ->@@dds@@ ->@@directx@@ ->@@dw@@ ->@@dx@@ ->@@flt@@ ->@@fly@@ ->@@freetype@@ ->@@geo@@ ->@@gif@@ ->@@iv@@ ->@@ive@@ ->@@jpeg@@ ->@@lib3ds@@ ->@@logo@@ ->@@logos@@ ->@@lwo@@ ->@@md2@@ ->@@obj@@ ->@@osg@@ ->@@osgParticle@@ ->@@osgText@@ ->@@osgtgz@@ ->@@out@@ ->@@pfb@@ ->@@pic@@ ->@@png@@ ->@@pnm@@ ->@@quicktime@@ ->@@rgb@@ ->@@tga@@ ->@@tgz@@ ->@@tiff@@ ->@@txp@@ ->@@zip@@

See the individual plugin directories for explainations of what they do.

Some additional file formats are also supported by Demeter (%newwin%http://www.terrainengine.com/) or the Virtual Terrain Project (%newwin%http://www.vterrain.org/). [[<<]][...top]

[#faq_25] !!!Q: Why do the OSG header files not have a .h or .hpp extension? [=A:=] Robert Osfield posted a message explaining the reasoning in detail, July 16, 2003. The archived message is:

->%newwin%http://sourceforge.net/mailarchive/message.php?msg_id=5544675 ->%newwin%http://osgcvs.no-ip.com/osgarchiver/archives/July2003/0575.html [[<<]][...top]

[#faq_26] !!!Q: What can I do to make my editor recognize OSG headers as C++ files? [=A:=] The means depends upon your editor and platform: *[=VisualStudio?=]: The OSG source includes a file called LANGEXT.DAT in the [=OSG/VisualStudio=] directory. Read the instructions there for how to use it. *[=VIm=]: can be made to recognize the mode string, "-*-c++-*-", at the beginning of each header file. Start vim. type ":set runtimepath" to see where vim looks for scripts. You can make a file in any of these directories (for example, ~/.vim on Linux). Make the directory if it doesn't already exist, and make a file called scripts.vim in that directory. Here are the contents of that file:

->@@if getline(1) =~ '-*-c++-*-'@@ ->@@set filetype=cpp@@ ->@@endif@@

*Emacs: should recognize the mode string right out of the box. *Nedit: can be told to treat files as C++ based on their location in an include directory *Dev-C++: In Tools/Editor Options/General there is an option "Use Syntax Highlighting". In the box below add @@;;@@. The final line will look like this: @@c;cpp;h;hpp;;@@. This will enable syntax highlighting in all files without extension. [[<<]][...top]

[#faq_27] !!!Q: I am trying to run Open Scene Graph example programs under Mac OSX, but no window appears! What can I do? [=A:=] You need to set the following environment variable before launching the program:

*tcsh: ->@@setenv DYLD_BIND_AT_LAUNCH 1@@

*bash: ->@@export DYLD_BIND_AT_LAUNCH=1@@

If you get dyld "can't open library" errors when running OSG programs under OSX, you may also need to set your DYLD_LIBRARY_PATH environment variable to point to the OSG libraries and/or plugins. [[<<]][...top]

[#faq_28] !!!Q: How do I increase the verbosity of my program for debugging purposes? [=A:=] You need to set the OSG_NOTIFY_LEVEL environment variable to a higher level. Here are the levels, from low to high (taken from include/osg/Notify):

->@@ALWAYS@@ ->@@FATAL@@ ->@@WARN@@ ->@@NOTICE@@ ->@@INFO@@ ->@@DEBUG_INFO@@ ->@@DEBUG_FP@@ [[<<]][...top]

[#faq_29] !!!Q: Qt and other GUI frameworks have adapters available in the contribs. Is there one for Gnome/GTK+? [=A:=] Take a look into the [=OSGEdit=] sources (%newwin%http://www.sf.net/projects/osgedit). It contains a GTK Event Adaptor (a C++ class implemented within the [=OSGEdit=] application source code that adapts events from GTK+ to the [=osgGA=] generic event framework). [[<<]][...top]

[#faq_30] !!!Q: Hey, this particle system is cool, but looks strange when I position it in my scene. What's up? [=A:=] You are probably rotating both the particle systems and the particle emitters. The tranform above the particle system(s) should match your world's (absolute) coordinate frame, or the reference frame that "contains" the particles (for example, an airplane or a car). To transform a particle system inside this reference frame you should transform only the emitters, not the [=ParticleSystem?=] drawables. If you apply a transform above "fountain.osg" you actually apply a [=translation/rotation=] to both emitters and particle systems; to get a correct behavior you should traverse the scene graph and avoid applying the transform to any geodes containing [=ParticleSystem?=] drawables. (answer courtesy People/MarcoJez)

There is a diagram, description and source code to do this here: %newwin%http://www.nps.navy.mil/cs/sullivan/osgTutorials/osgParticleHelper.htm [[<<]][...top]

[#faq_31] !!!Q: I'm having a problem using a [=PrimitiveSet?=] to represent a single point, OR my geometry seems to dissapear as it gets very far away. What's wrong? [=A:=] By default the OSG uses small feature culling to cull out objects that occupy a predetermined screen size. This is a valuable feature for models with many details which do not contribute to the visual quality of the model when viewed from a distance. You can completely disable small feature culling by defining the [=cullingMode=] on [=osgUtil::SceneView?=] with:

->@@[=osg::CullStack::CullingMode? cullingMode = sceneview->getCullingMode();=]@@ ->@@[=cullingMode &= ~(osg::CullStack::SMALL_FEATURE_CULLING);=]@@ ->@@[=sceneview->setCullingMode( cullingMode );=]@@

You can also control the size of the screen space that is used to cull small features with

->@@[=sceneview->setSmallFeatureCullingPixelSize( minimumSize );=]@@ [[<<]][...top]

[#faq_32] !!!Q: When I apply a scaling factor in a [[Maths/MatrixTransformations MatrixTransform?]], my models are washed out or dark. What's up? [=A:=] Normals are scaled along with vertices. To keep normals normalized, set this attribute in an appropriate stateset:

->@@[=stateSet->setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON );=]@@ [[<<]][...top]

[#faq_33] !!!Q: How do i insert comments in a .osg data file? Or, how do I comment out a block within a .osg file? [=A:=] Due to the nature of the .osg parser, which allows extensions, one can simply insert a comment in a .osg file by doing this:

->@@Comment {@@ -->@@This file is proprietary and you shoudn't be reading it.@@ -->@@Please close your editor now!@@ -->@@-Microsoft@@ ->@@}@@

Also, if you want to comment out a section of a file, just:

->@@Comment {@@ -->@@[=TexGen?=] {@@ --->@@[=UniqueID TexGen?_4=]@@ --->@@[=DataVariance?? STATIC=]@@ --->@@[=mode SPHERE_MAP=]@@ -->@@}@@ ->@@}@@ [[<<]][...top]

[#faq_34] !!!Q: Can I use OSG within an existing renderer? [=A:=] It takes a little work, but it is entirely possible to use OSG within a pre-existing rendering system.

First of all, the central object you should know about is [=osgUtil::SceneView?=]. This class will manage the OSG specific rendering tasks. If you want to take advantage of OSG's animation capabilities, you will also want to maintain your own [=FrameStamp?=] object.

The setup of these two objects will look something like this:

->@@unsigned int frameNumber = 0;@@ ->@@osg::Timer timer;@@ ->@@osg::Timer_t start_tick = timer.tick();@@ ->@@[=osg::ref_ptr<osgUtil::SceneView?> sceneViewer = new osgUtil::SceneView?();=]@@ ->@@[=osg::ref_ptr<osg::FrameStamp?> frameStamp = new osg::FrameStamp?();=]@@

->@@[=sceneViewer->setDefaults();=]@@ ->@@[=sceneViewer->setComputeNearFarMode( osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR );=]@@ ->@@[=sceneViewer->setSceneData( rootNode );=]@@

Note, just replace rootNode with your actual root node for you OSG models.

NOTE: The call to [=setComputeNearFarMode=] is very important. If you don't do this, then OSG will use a different near and far plane when rendering its objects, and they will have different values in the depth-buffer than the rest of your scene. This can lead to very odd effects.

If you want to use lighting that is different from what the rest of your renderer is using, you might want to call either:

->@@[=sceneViewer->setLightingMode( osgUtil::SceneView::SKY_LIGHT );=]@@

or

->@@[=sceneViewer->setLightingMode( osgUtil::SceneView::HEADLIGHT );=]@@

That's basically it for setup.

Now you just need to call [=SceneView?=] for rendering, and this requires a little extra work.

First off, it is recommended that you call [=glPushAttribs=]( GL_ALL_ATTRIB_BITS ) and [=glPushMatrix=] for each of the modelview, projection and texture matrices before calling your other KnowledgeBase?/OpenGL code, and the corresponding pop fuctions afterwards, and do the same with OSG. This prevents OSG and your other [=OpenGL=] code from interfering with each other. For example:

->@@[=glPushAttrib=]( GL_ALL_ATTRIB_BITS );@@ ->@@[=glMatrixMode=](GL_PROJECTION);@@ ->@@[=glPushMatrix();=]@@ ->@@[=glMatrixMode(GL_TEXTURE);=]@@ ->@@[=glPushMatrix();=]@@ ->@@[=glMatrixMode(GL_MODELVIEW);=]@@ ->@@[=glPushMatrix();=]@@

->@@your code here...@@

->@@[=glMatrixMode(GL_TEXTURE);=]@@ ->@@[=glPopMatrix();=]@@ ->@@[=glMatrixMode(GL_PROJECTION);=]@@ ->@@[=glPopMatrix();=]@@ ->@@[=glMatrixMode(GL_MODELVIEW);=]@@ ->@@[=glPopMatrix();=]@@ ->@@[=glPopAttrib();=]@@

The next important thing for using [=SceneView?=] is that you need to tell it about your pre-existing viewport and projection and modelview matrices. The code to do that looks like this:

->@@[=GLint=] viewParams[4];@@ ->@@[=glGetIntegerv( GL_VIEWPORT, viewParams );=]@@ ->@@[=sceneViewer->setViewport(viewParams[0], viewParams[1], viewParams[2], viewParams[3]);=]@@

->@@[=GLfloat glMat[16];=]@@ ->@@[=osg::Matrix osgMat;=]@@

->@@[=glGetFloatv( GL_PROJECTION_MATRIX, glMat )=];@@ ->@@[=osgMat.set( glMat )=];@@ ->@@[=sceneViewer->getProjectionMatrix().set( osgMat );=]@@

->@@[=glGetFloatv( GL_MODELVIEW_MATRIX, glMat );=]@@ ->@@[=osgMat.set( glMat );=]@@ ->@@[=sceneViewer->getViewMatrix().set( osgMat );=]@@

The next step is to update your [=FrameStamp?=] object (if you are using your own):

->@@double time_since_start = timer.delta_s( start_tick, timer.tick() );@@ ->@@[=frameStamp->setReferenceTime( time_since_start );=]@@ ->@@[=frameStamp->setFrameNumber( frameNumber++ );=]@@ ->@@[=sceneViewer->setFrameStamp( frameStamp.get() );=]@@

Lastly, you need to make the actual calls to the [=SceneView?=] object:

->@@[=sceneViewer->update ();=]@@ ->@@[=sceneViewer->cull ();=]@@ ->@@[=sceneViewer->draw ();=]@@

If you do all of that, you should be able to successfully use OSG within your pre-existing rendering system, thereby gaining many of the advantages of OSG, without having to scrap your existing system. [[<<]][...top]

[#faq_35] !!!Q: I have a class derived of off osg::Drawable, but the drawImplementation is called only once! [=A:=] Try disabling the use of display list for this class.

->@@[=drawable->setUseDisplayList( false );=]@@

Otherwise a display list will be created and this will be called for drawing your drawable next time instead of your [=drawImplementation=]. [[<<]][...top]

[#faq_36] !!!Q: Can I use opengl commands directly in OSG ? [=A:=] Yes. See osgteapot example. [[<<]][...top]

[#faq_37] !!!Q: Can I use OSG without Producer, and/or with already created MFC or WxWindow? windows ? [=A:=] You can use OSG with or with out Producer, even if you are creating your own windows. See the osgsimple example for an example of using OSG with a generic windowing environment. OSG itself is windowing system agnostic, so setting up the window and OpenGL graphics context will be up to your application. osgsimple uses Producer, but is written in a way to provide you the skeleton to use your own windowing system.

Alternatively, you can use Producer in your own windowing environment as well by setting each Camera's RenderSurface? to the window you've created. Like this: ->@@osgProducer::Viewer viewer;@@ ->@@viewer.getCamera(0)->getRenderSurface()->setWindow( myWindow );@@

The variable 'myWindow' is an X11 Window, or a win32 HWND.

See : http://osgcvs.no-ip.org/osgarchiver/archives/November2004/1019.html for even more details. [[<<]][...top]

[#faq_38] !!!Q: How can I contribue to the [=OpenSceneGraph=]? [=A:=] Send changes as whole files to the osg-submissions mailing list along with an explanation of the changes. Do not send diffs or copy and paste extracts in emails, these will be simply disgarded, as they are too unreliable for review and merging.

Alternatively you can post changes or submissions under the Community section of the this website. This is particular appropriate for complete new functionality such as KnowledgeBase/NodeKits? and plugins. Then inform the osg-users or osg-submissions list of this entry. [[<<]][...top]

[#faq_39] !!!Q: How can I get the [=BoundingBox?=] for a loaded Node or 3D model? [=A:=] For peformance reasons the OSG stores [=osg::BoundingSphere?'s=] for all internal nodes, and [=osg::BoundingBox?'s=] for the Drawable leaves.

If you wish to use a [=BoundingBox?=] of a node then you'll convert the [=BoundingSphere?=] to a [=BoundingBox?=] by doing something like:

[=BoundingBox?=] bb; bb.expandBy(node->getBound());

[[<<]][...top]

[#faq_40] !!!Q: When using multiple viewers and/or multiple rendering windows, I get weird results and my textures don't display correctly. [=A:=] Each rendering window has its own [=OpenGL=] context which is separate from all other contexts. Since OSG doesn't know how you set up your windowing environment, you need to ensure that each osg::State object is tied to a unique [=OpenGL=] context. To do that you should: # for each window, get the associated [=osgUtil::SceneView?=] object # for each [=SceneView?=] object, get the associated osg::State object # call [=State::setContextID()=] on each State, passing a unique number to identify that context.

After contracting the [=SceneView?=]'s:[[<<]][[<<]] // this will automatically create the osg::State amoung other operations [[<<]]

sceneview0->setDefaults(); [[<<]]

// now set the ID to 0 (this is the default, just set here for clarity[[<<]]

sceneview0->getState()->setContextID(0);

[[<<]]

sceneview1->setDefaults(); sceneview1->getState()->setContextID(1);

[[<<]] NOTE: context [=IDs=] are used as indices in vectors that grow automatically, so please avoid setting large numbers. Start counting from 0 and then increment by one each time. [[<<]][...top]

[#faq_41] !!!Q: I have two or more views sharing a scene graph, but I want to limit what part of the scene graph is shown in one or more of the views. How do I do that? [=A:=] What is drawn in a view depends on the results of the Cull Traversal. Each view will have a unique [=osgUtil::SceneView?=] and a each [=osgUtil::SceneView?=] will have a unique [=CullVisitor?=]. You can set a traversal mask on each [=CullVisitor?=] (or sceneView's cullSettings), which it will apply (as a bitwise AND) to each of the nodes it traverses. On each node, then, you can set a [=CullMask?=] that corresponds to the view you want that sub-graph to be displayed in.

Like this:

leftSceneView->getCullVisitor()->setTraversalMask( 0x1); rightSceneView->getCullVisitor()->setTraversalMask( 0x2 );

leftNode->setNodeMask(0x1); rightNode->setNodeMask(0x2);

[[<<]][...top]

[#faq_42] !!!Q: On previous question - Yeah but.... it didn't work! [=A:=] When using osgProducer::Viewer, convenience functions are set up to allow attributes to be set globally for all Cameras and [=SceneHandler?=] (including [=SceneViews?=]) in an [=OsgCameraGroup?=]. This includes traversal masks for [=CullVisitors?=], which will all be set to 0xFFFFFFFF by default. Before setting the [=TraversalMask?=] on the unique [=CullVisitors?=], you need to make them immune to imposition of global settings with this ([=CullSettings?=] are applied to [=CullVisitors?=] on traversal):

[=osgProducer::Viewer::SceneHandlerList?=] shl = viewer.getSceneHandlerList(); [=osgProducer::Viewer::SceneHandlerList?=]::iterator p; unsigned int n = 0; for( p = shl.begin(); p != shl.end(); p++ ) {

int inheritanceMask = (*p)->getSceneView()->getInheritanceMask(); inheritanceMask &= ~(osg::[=CullSettings?=]::CULL_MASK); (*p)->getSceneView()->set[=InheritanceMask?=]( inheritanceMask ); (*p)->getSceneView()->setCullMask( 1<<(n)); n++;

}

[[<<]][...top]

[#faq_43] !!!Q: How do I capture a screengrab? [=A:=] [[<<]]

[=Producer example from ViewerEventHandler?.cpp ViewerEventHandler::SnapImageDrawCallback:=]

->@@[=int x,y;=]@@ ->@@[=unsigned int width,height;=]@@ ->@@[=camera.getProjectionRectangle(x,y,width,height);=]@@ ->@@[=osg::ref_ptr<osg::Image> image = new osg::Image;=]@@ ->@@[=image->readPixels(x,y,width,height, GL_RGB,GL_UNSIGNED_BYTE);=]@@ ->@@[=osgDB::writeImageFile(*image,_filename);=]@@

GLUT example from the [SST Project]:

->@@[=osg::ref_ptr<osg::Image>image = new osg::Image;=]@@ ->@@[=unsigned int w = glutGet(GLUT_WINDOW_WIDTH);=]@@ ->@@[=unsigned int h = glutGet(GLUT_WINDOW_HEIGHT);=]@@ ->@@[=image->allocateImage(w, h, 1, GL_RGB, GL_UNSIGNED_BYTE);=]@@ ->@@[=image->readPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE);=]@@

[[<<]][...top]

[#faq_44] !!!Q: How can I change the Producer icon at run-time?? [=A:=] In Microsoft Windows and Visual Studio 7.x:

First add an icon to your solution (Project/Add Recource/Icon).

After viewer->realize() do the following:

->@@[=Producer::Window wnd = viewer->getCamera(0)->getRenderSurface()->getWindow();=]@@ ->@@[=HICON h1 = LoadIcon?(GetModuleHandle?(0), "YOUR_ICON");=]@@ ->@@[=DWORD dw = SetClassLongPtr?(wnd, GCL_HICON, (LONG_PTR)h1);=]@@

The string "YOUR_ICON" should refer to the icon name in your resource file(.rc).

[[<<]][...top]

[#faq_45] !!!Q: How can I add a new wiki-page? [=A:=] Have a look at the examples in the Community/WikiSandbox! [[<<]][...top]

[#faq_46] !!!Q: Why does my framerate drop when rendering point sprites to an FBO/pbuffer?? [=A:=] Short answer: Change the coordinate origin mode of the PointSprite? attribute to LOWER_LEFT:

->@@[=osg::PointSprite? *ps = new osg::PointSprite?;=]@@ ->@@[=ps->setCoordOriginMode(osg::PointSprite::LOWER_LEFT);=]@@

Long answer: Read the section on Point Sprites in the nVidia OpenGL 2.0 Support document. It states the following:

When rendering to pixel buffers (commonly called pbuffers) or frame buffer objects (commonly called FBOs), change the GL_POINT_SPRITE_COORD_ORIGIN state set to GL_LOWER_LEFT setting for fully hardware accelerated rendering. Using GL_UPPER_LEFT with pbuffer and FBO rendering will force points to be transformed on the CPU.

[[<<]][...top]