Changes between Version 15 and Version 16 of SandBox/FAQ

Show
Ignore:
Timestamp:
05/08/08 00:40:24 (6 years ago)
Author:
osg (IP: 85.145.66.238)
Comment:

Moved to support FAQ

Legend:

Unmodified
Added
Removed
Modified
  • SandBox/FAQ

    v15 v16  
    1 = FAQ = 
    2 [[TracNav(TracNav/SupportTOC)]] 
    3  
    4 Here is a list of Frequently Asked Questions. 
    5  
    6 More FAQs about OSG may be found at [http://www.3drealtimesimulation.com/osg/osg_faq_1.htm 3drealtimesimulation]. 
    7  
    8 [[PageOutline(2-3, Questions, inline)]] 
    9  
    10 ---- 
    11  
    12 == __General__ == 
    13  
    14 === I have no idea what !OpenSceneGraph is, can you give me a short description?  === 
    15  
    16 It is a 3D graphics library for C++ programmers. A [wiki:Support/KnowledgeBase/SceneGraph 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. 
    17  
    18 === What platforms does the OpenSceneGraph support? === 
    19  
    20 Microsoft Windows (2000, XP, Vista), GNU/Linux and MacOS/X are currently the best supported ones. 
    21 Your mileage may vary on Solaris, IRIX, ... 
    22  
    23 === Where can I get more info on !OpenSceneGraph? === 
    24  
    25 Try these: 
    26  
    27  * Look at the official homepage at http://www.openscenegraph.org/ (this FAQ is located there) 
    28  * Join the mailing lists, specifically "osg-users". See [wiki:MailingLists] for more information. 
    29  
    30 === What background knowledge is required/useful if I want to work with the OpenSceneGraph? === 
    31  
    32 As the OSG is written in C++ you'll need to be able to program in that language. 
    33  
    34 One way to look at the OSG is to treat it as an object-oriented wrapper around OpenGL. This is actually a far too simplistic view, as the OSG does a lot more than just issue OpenGL commands for you. However, it does indicate the need to have to knowledge of how OpenGL works in order to use the OpenSceneGraph in a sensible way. Anything you therefore know about OpenGL will be of value when using the OSG. 
    35  
    36  
    37 === What is the difference between OpenSceneGraph and OpenSG/"The one from `www.opensg.org`?"  === 
    38  
    39 They are different scenegraph libraries, although OpenSG also seems to use an "OSG" prefix in their code, which might be source of some confusion. Differences in goals and capabilities between the two are: 
    40  
    41  * OpenSceneGraph has support for reading many 3D and image file formats, while OpenSG supports far fewer 
    42  * OpenSceneGraph is more actively developed (at least, judging by the number of releases of OpenSG) and probably has a more active user community 
    43  * OpenSG has better support for performing multi-threaded scene graph operations, as this was one of the original design goals 
    44  * OpenSG has better support for clustered rendering, although building your own support for OpenSceneGraph isn't terribly difficult 
    45  
    46 The OpenSG website also provides a comparison between the two: http://opensg.vrsource.org/trac/wiki/OSGComparison 
    47  
    48  
    49 == __Documentation__ == 
    50  
    51 === Are there any books available about OSG? === 
    52  
    53 Yes, see http://www.osgbooks.com. 
    54  
    55 The books are constantly under revision to keep up with changes in OSG. Purchasing the books helps fund this effort. More OSG books, not just revisions, are planned for the future. 
    56  
    57 === Are there tutorials available? === 
    58  
    59 Yes, see [wiki:Support/Tutorials here]. 
    60  
    61 === Where is the reference manual for the .osg file format? === 
    62  
    63 There is no documentation (yet) for the scene description language. The OSG source code is the definite reference on the format ([wiki:Support/KnowledgeBase/UseTheSourceLuke! UseTheSourceLuke!]), specifically the files under the src/osgPlugins/osg directory in the source distribution. 
    64  
    65 For anyone with knowledge of OpenGL and the OSG classes the .osg format should be fairly understandable, though. 
    66  
    67  
    68  
    69 == __Wiki__ == 
    70  
    71 === How can I edit a wiki page? === 
    72  
    73 This wiki requires a login (See [wiki:Community/WikiLogIn]).  Note that some pages can only be edited by the Wiki administrator. This includes the main page, project news and all pages in the Downloads section. 
    74  
    75 === How can I add a new wiki-page? === 
    76  
    77 One can add a new page by first creating a wiki link ![wiki:mycategory/mynewpage] to the new page. This can be done in the text of another page or in the menu seen at the top right of the window. There is a separate edit option for the menu available, but don't clutter the menu with many small pages. Select an appropriate category for adding a new page. See links to other pages for existing categories. 
    78  
    79 For wiki formatting see [wiki:WikiFormatting] or  have a look at the examples in the [wiki:SandBox] and experiment there. 
    80  
    81  
    82 == __Building/Installation__ == 
    83  
    84 === Are there binary distributions available? === 
    85  
    86 Yes, but only for Windows. For Linux you will have to build OSG yourself or check if your Linux distribution has packages for OSG. On Mac OS/X you will have to build OSG yourself. 
    87  
    88 === I'm not using MS Visual Studio. Does !OpenSceneGraph support other Compilers, like mingw32?  === 
    89  
    90 There is a build in the distribution for Cygwin and Mingw, but they are primarily supported by folks on the osg-users mailing list. 
    91  
    92 === Help! !VisualStudio won't load the OSG project files === 
    93  
    94 If you're getting the message "This makefile was not generated by Developer Studio", then the .dsp files 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). 
    95  
    96  
    97 === Everything is compiled, but there are linking problems OR When I run my OSG application it crashes === 
    98  
    99 On Linux, try a "make clean", then "make". On Windows do a clean build. 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. 
    100  
    101 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. 
    102  
    103 On Linux you may need to add an entry to `/etc/ld.so.conf.d/` and run `ldconfig`, or set your LD_LIBRARY_PATH to include the location where you installed the OSG libraries. 
    104  
    105  
    106  
    107  
    108 == __Functionality/Features__ == 
    109  
    110  
    111 === Where is the camera class for !OpenSceneGraph? === 
    112  
    113 You have three options: 
    114  
    115  1. (Recommended) Use `osgViewer`. The `osgviewer` application and almost all the example programs demonstrate how to hook up a scene, an `osgViewer` object and a manipulator that controls the camera in response to user input. 
    116  2. Use `osgUtil::SceneView` and `osg::Matrix`. 
    117  3. Make your own class. 
    118  
    119  
    120 === How do I render terrain in OSG? === 
    121  
    122 The !OpenSceneGraph now has the [http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a02213.html osgTerrain] [wiki:Support/KnowledgeBase/NodeKit NodeKit] for generation large paged geospatial databases. 
    123  
    124 If you wish to use a continuous level of details approach to terrain see Demeter (http://www.terrainengine.com/) and the Virtual Terrain Project (http://www.vterrain.org/) for detailed open source approaches. 
    125  
    126  
    127 === I can't get GLUT working OR GLUT doesn't provide feature X === 
    128  
    129 You're better off using wxWidgets (http://www.wxwidgets.org/) or Simple Direct Media Layer (http://www.libsdl.org/). Both are !OpenSource and provide the [wiki:Support/KnowledgeBase/OpenGL OpenGL] renderpanes for OSG to work on. 
    130  
    131 === Is there support for skeletal animation? === 
    132  
    133 Check out osgCal which integrates the OSG with Cal3D, see http://osgcal.sourceforge.net/ 
    134  
    135  
    136 === What file formats are supported by !OpenSceneGraph? === 
    137  
    138 File input and output is supported through the plugins in the src/osgPlugins directory of the source distribution. 
    139  
    140 See [wiki:Support/UserGuides/Plugins] for an overview of available plugins and the file formats they support. Note that some of these plugins depend on external libraries to be installed. 
    141  
    142 Some additional file formats are also supported by Demeter (http://www.terrainengine.com/) or the Virtual Terrain Project (http://www.vterrain.org/). 
    143  
    144  
    145 === Does the OpenSceneGraph have a native file format? === 
    146  
    147 Yes, the OSG actually has two native file formats. The first is a text format and has extension ".osg". The second is a binary representation similar in scope to the .osg format, and has extension ".ive". 
    148  
    149 The .osg format is the most portable as it has no byte-order dependencies and is fully backwards-compatible. It can also be easily hand-edited or generated. 
    150  
    151 The .ive format '''is''' byte-order dependent, meaning that you can't read files on a system with a different byte-order than where they were written. The format is also not backwards compatible. 
    152  
    153 XXX is this correct about the .ive format? 
    154  
    155  
    156 === Are there sample files that OSG can read for me to play with? === 
    157  
    158 Yes, there is a sample dataset. Actually, some of the examples included in the OSG distribution depend on having them installed. See [wiki:Downloads/SampleDatasets]. 
    159  
    160  
    161 === Can I use OpenGL commands directly in OSG ?  === 
    162  
    163 Yes. See, for example, the osgteapot example included in the source distribution. 
    164  
    165 === Is it possible to render a scene in 2D? === 
    166  
    167 For a code sample have a look at examples/osghud/osghud.cpp. This example creates a subgraph for viewing a 3D scene, and a second subgraph which sits along side it with `osg::Projection` & `osg::MatrixTransform` nodes to set up the orthographic views for drawing the 2D scene over the 3D one. 
    168  
    169  
    170 === How do I move models around once they are in the scene? === 
    171  
    172 Add the Node in question to an osg::Transform (as a child). This allows you to move your model around the scene by changing the Transform. Take a look at the osgreflect example, which uses an osg::MatrixTransform to create a mirror image of a model. 
    173  
    174  
    175 === Qt and other GUI frameworks have adapters available in the contribs. Is there one for Gnome/GTK+?  === 
    176  
    177 Take a look into the OSGEdit sources (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). 
    178  
    179  
    180 === How do I insert comments in a .osg file? OR How do I comment out a block within a .osg file? === 
    181  
    182 Due to the nature of the .osg parser, which allows extensions, one can simply insert a comment in a .osg file by doing this: 
    183 {{{ 
    184 Comment { 
    185         This file is proprietary and you shoudn't be reading it. 
    186         Please close your editor now! 
    187         -Microsoft 
    188 } 
    189 }}} 
    190  
    191 You can also use it to comment out a section of a file: 
    192 {{{ 
    193 Comment { 
    194         TexGen { 
    195                 UniqueID TexGen_4 
    196                 DataVariance? STATIC 
    197                 mode SPHERE_MAP=] 
    198         } 
    199 } 
    200 }}} 
    201  
    202  
    203  
    204  
    205  
    206 == __Development - General__ == 
    207  
    208 === Why don't the OSG header files have a .h or .hpp extension? === 
    209  
    210 The short answer is that this is the Standard C++ way of naming headers. For more information see these posts on the osg-users mailing list: 
    211  
    212   http://thread.gmane.org/gmane.comp.graphics.openscenegraph.user/26136 
    213   http://osgcvs.no-ip.com/osgarchiver/archives/July2003/0575.html 
    214  
    215 === What can I do to make my editor recognize OSG headers as C++ files? === 
    216  
    217 The means depends upon your editor and platform: 
    218  * !VisualStudio: The OSG source includes a file called LANGEXT.DAT in the `OSG/VisualStudio` directory. Read the instructions there for how to use it. 
    219  * 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: 
    220 {{{ 
    221 if getline(1) =~ '-*-c++-*-' 
    222 set filetype=cpp 
    223 endif 
    224 }}} 
    225  
    226  * Emacs: should recognize the mode string right out of the box. 
    227  * Nedit: can be told to treat files as C++ based on their location in an include directory 
    228  * 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. 
    229  
    230  
    231 === How do I increase the verbosity of my program for debugging purposes? === 
    232  
    233 You can use the OSG_NOTIFY_LEVEL environment variable to specify a certain level of debug info. Here are the levels, from low to high (taken from include/osg/Notify): 
    234 {{{ 
    235 ALWAYS 
    236 FATAL 
    237 WARN 
    238 NOTICE 
    239 INFO 
    240 DEBUG_INFO 
    241 DEBUG_FP 
    242 }}} 
    243 The default level is NOTICE. Setting OSG_NOTIFY_LEVEL to, for example, INFO will generate more output. 
    244  
    245 === Can I get CVS or Subversion access so I can keep up to date with the latest development sources? === 
    246  
    247 Yes. The OSG sources are available through Subversion. See the documentation on how to set up [wiki:Downloads/SVN SVN] access to the development version of the !OpenSceneGraph. 
    248  
    249 === I don't like using C++. Are there wrappers available for other languages, like Lua? === 
    250  
    251 Yes, see [wiki:Community/LanguageWrappers]. Note that none of these wrappers are part of the official distribution and so are maintained by external parties. They also differ in maturity. 
    252  
    253 === How can I contribute to the !OpenSceneGraph? === 
    254  
    255 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''. 
    256  
    257 Alternatively you can post changes or submissions under the Community section of this website.  This is particularly appropriate for complete new functionality such as [wiki:Support/KnowledgeBase/NodeKit NodeKits] and plugins.  After uploading your things to the website inform the osg-users or osg-submissions list of your entry. 
    258  
    259  
    260 == __Development - Windows-specific__ == 
    261  
    262 === When I try to save a node to file, OSG crashes. I'm using Windows. OR STL is playing up for me in !VisualStudio. === 
    263  
    264 This is a known problem with the Microsoft implementation of STL. The current solution is to use STLport (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 won't need STLport after that. 
    265  
    266 === I get a lot of warnings along the lines of... `warning C4541: 'dynamic_cast' used on polymorphic type 'class osg::Object' with /GR-` === 
    267  
    268 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". 
    269  
    270  
    271  
    272  
    273  
    274 == __Problems__ == 
    275  
    276  
    277 === How come the mountain in the hang glider demo is completely white with no shading? OR My textured objects don't show textures === 
    278  
    279 There are two likely causes: 
    280  
    281   1. The plugin to read necessary image file format can't be found or wasn't compiled. For the hang glider demo this is the .rgb file format (osgdb_rgb). You need to compile the rgb plugin in this case. 
    282  
    283   2. The program can't find the data files 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 this writing they are OSGHOME, OSGDATA and OSG_FILE_PATH. To set the environment variables in Windows go to control panel->system->advanced->environment variables. 
    284  
    285  
    286  
    287 === Why does OSG seem to ignore my near/far clipping planes? === 
    288  
    289 When using `osgUtil::SceneView` (or the newer osgViewer::Viewer), near and far clipping planes are recomputed on-the-fly based on the current eye point and viewable scene. This is by design to optimize the near/far range of the depth buffer, which might otherwise result in "z-fighting" artifacts if near and far are set to unreasonably small or large values. 
    290  
    291 You can override this behavior by calling: 
    292 {{{ 
    293 sceneview->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) 
    294 }}} 
    295 If you are using `osgProducer::viewer` use: 
    296 {{{ 
    297 viewer.getCullSettings().setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); 
    298 }}} 
    299  
    300 For an insightful example of this feature check out the osgthirdpersonview example (which was added in version 2.4). It shows one window containing a normal scene and a second window showing the camera and clipping planes used in the first window. By manipulating the view in the first window you can see the changing clipping planes in the second one. 
    301  
    302  
    303 === If I let !OpenSceneGraph calculate my near and far clipping planes, how do I get the computed values?  === 
    304  
    305 This info is available through the cull visitor (class osgUtil::CullVisitor).  
    306  
    307 When using an osgUtil::SceneView it would be 
    308 {{{ 
    309 sceneView->getCullVisitor()->getCalculatedNearPlane(); 
    310 sceneView->getCullVisitor()->getCalculatedFarPlane(); 
    311 }}} 
    312  
    313 When using osgViewer::Viewer you can get its osg::Camera (which is a subclass osg CullVisitor) with 
    314 {{{ 
    315 viewer->getCamera() 
    316 }}} 
    317  
    318  
    319  
    320 === I am trying to run OpenSceneGraph example programs under Mac OS/X, but no window appears! What can I do?  === 
    321  
    322 You need to set the following environment variable before launching the program: 
    323  
    324  * tcsh: 
    325 {{{ 
    326 setenv DYLD_BIND_AT_LAUNCH 1 
    327 }}} 
    328  
    329  * bash: 
    330 {{{ 
    331 export DYLD_BIND_AT_LAUNCH=1 
    332 }}} 
    333  
    334 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. 
    335  
    336 === Hey, this particle system is cool, but looks strange when I position it in my scene. What's up? === 
    337  
    338 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 [wiki:Community/People/MarcoJez Marco Jez]) 
    339  
    340 There is a diagram, description and source code to do this here: http://faculty.nps.edu/jasullivan/osgTutorials/osgParticleHelper.htm 
    341  
    342  
    343 === I'm having a problem using a !PrimitiveSet to represent a single point OR My geometry seems to dissappear as it gets very far away. What's wrong? === 
    344  
    345 By default the OSG uses small feature culling to cull out objects that occupy less than 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 changing the `cullingMode` on `osgUtil::SceneView` with: 
    346 {{{ 
    347 osg::CullStack::CullingMode cullingMode = sceneview->getCullingMode(); 
    348 cullingMode &= ~(osg::CullStack::SMALL_FEATURE_CULLING); 
    349 sceneview->setCullingMode( cullingMode ); 
    350 }}} 
    351 You can also control the size of the screen space that is used to cull small features with 
    352 {{{ 
    353 sceneview->setSmallFeatureCullingPixelSize( minimumSize ); 
    354 }}} 
    355  
    356 XXX How about osgViewer::Viewer 
    357  
    358 === When I apply a scaling factor in a [wiki:Support/Maths/MatrixTransformations osg::MatrixTransform], my models are displayed washed out or dark. What's up? === 
    359  
    360 The model's normals are probably scaled along with its vertices. To keep normals normalized, set the OpenGL attribute GL_RESCALE_NORMALS on the appropriate stateset: 
    361 {{{ 
    362 stateSet->setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON ); 
    363 }}} 
    364  
    365  
    366  
    367 === Can I use OSG within an existing renderer? === 
    368  
    369 XXX Split off in separate page 
    370  
    371  
    372 It takes a little work, but it is entirely possible to use OSG within a pre-existing rendering system. 
    373  
    374 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. 
    375  
    376 The setup of these two objects will look something like this: 
    377 {{{ 
    378 unsigned int frameNumber = 0; 
    379 osg::Timer timer; 
    380 osg::Timer_t start_tick = timer.tick(); 
    381 osg::ref_ptr<osgUtil::SceneView> sceneViewer = new osgUtil::SceneView(); 
    382 osg::ref_ptr<osg::FrameStamp> frameStamp = new osg::FrameStamp(); 
    383  
    384 sceneViewer->setDefaults(); 
    385 sceneViewer->setComputeNearFarMode( osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR ); 
    386 sceneViewer->setSceneData( rootNode ); 
    387 }}} 
    388 Note, just replace rootNode with your actual root node for you OSG models. 
    389  
    390 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. 
    391  
    392 If you want to use lighting that is different from what the rest of your renderer is using, you might want to call either: 
    393  
    394 {{{ 
    395 sceneViewer->setLightingMode( osgUtil::SceneView::SKY_LIGHT ); 
    396 }}} 
    397  
    398 or 
    399  
    400 {{{ 
    401 sceneViewer->setLightingMode( osgUtil::SceneView::HEADLIGHT ); 
    402 }}} 
    403  
    404 That's basically it for setup. 
    405  
    406 Now you just need to call !SceneView for rendering, and this requires a little extra work. 
    407  
    408 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 [wiki:Support/KnowledgeBase/OpenGL 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: 
    409 {{{ 
    410 glPushAttrib=]( GL_ALL_ATTRIB_BITS ); 
    411 glMatrixMode=](GL_PROJECTION); 
    412 glPushMatrix(); 
    413 glMatrixMode(GL_TEXTURE); 
    414 glPushMatrix(); 
    415 glMatrixMode(GL_MODELVIEW); 
    416 glPushMatrix(); 
    417  
    418 your code here... 
    419  
    420  
    421  
    422  
    423  
    424 glMatrixMode(GL_TEXTURE); 
    425 glPopMatrix(); 
    426 glMatrixMode(GL_PROJECTION); 
    427 glPopMatrix(); 
    428 glMatrixMode(GL_MODELVIEW); 
    429 glPopMatrix(); 
    430 glPopAttrib(); 
    431 }}} 
    432 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: 
    433 {{{ 
    434 GLint viewParams[4]; 
    435 glGetIntegerv( GL_VIEWPORT, viewParams ); 
    436 sceneViewer->setViewport(viewParams[0], viewParams[1], viewParams[2], viewParams[3]); 
    437  
    438 GLfloat glMat[16]; 
    439 osg::Matrix osgMat; 
    440  
    441 glGetFloatv( GL_PROJECTION_MATRIX, glMat ); 
    442 osgMat.set( glMat ); 
    443 sceneViewer->getProjectionMatrix().set( osgMat ); 
    444  
    445 glGetFloatv( GL_MODELVIEW_MATRIX, glMat ); 
    446 osgMat.set( glMat ); 
    447 sceneViewer->getViewMatrix().set( osgMat ); 
    448 }}} 
    449  
    450 The next step is to update your !FrameStamp object (if you are using your own): 
    451 {{{ 
    452 double time_since_start = timer.delta_s( start_tick, timer.tick() ); 
    453 frameStamp->setReferenceTime( time_since_start ); 
    454 frameStamp->setFrameNumber( frameNumber++ ); 
    455 sceneViewer->setFrameStamp( frameStamp.get() ); 
    456 }}} 
    457 Lastly, you need to make the actual calls to the !SceneView object: 
    458 {{{ 
    459 sceneViewer->update (); 
    460 sceneViewer->cull (); 
    461 sceneViewer->draw (); 
    462 }}} 
    463 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. 
    464  
    465  
    466 === I have derived a class from osg::Drawable, but its drawImplementation() method is called only once === 
    467  
    468 Try disabling the use of display lists for this class. 
    469  
    470 {{{ 
    471 drawable->setUseDisplayList( false ); 
    472 }}} 
    473  
    474 Otherwise a display list will be created once and this will be called for drawing your drawable next time instead of your drawImplementation. 
    475  
    476  
    477 === How can I get the !BoundingBox for a loaded Node or 3D model? === 
    478  
    479 For performance reasons the OSG stores `osg::BoundingSphere's` for all internal nodes, and `osg::BoundingBox's` for the Drawable leaves. 
    480  
    481 If you wish to use a !BoundingBox of a node then you can convert the 
    482 !BoundingSphere to a !BoundingBox by doing something like: 
    483 {{{ 
    484  BoundingBox bb; 
    485  bb.expandBy(node->getBound()); 
    486 }}} 
    487  
    488 === When using multiple viewers and/or multiple rendering windows, I get weird results and my textures don't display correctly === 
    489  
    490 Each rendering window has its own OpenGL context which is separate from all other contexts. Since OSG doesn't know how you have 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: 
    491  1. for each window, get the associated `osgUtil::SceneView` object 
    492  2. for each !SceneView object, get the associated `osg::State object` 
    493  3. call `State::setContextID()` on each State, passing a unique number to identify that context. 
    494  
    495 After contracting the SceneView's: 
    496 {{{ 
    497 // this will automatically create the osg::State amoung other operations 
    498  sceneview0->setDefaults(); 
    499 // now set the ID to 0 (this is the default, just set here for clarity 
    500  sceneview0->getState()->setContextID(0); 
    501  
    502  sceneview1->setDefaults(); 
    503  sceneview1->getState()->setContextID(1); 
    504 }}} 
    505 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. 
    506  
    507  
    508 === 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? === 
    509  
    510 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. 
    511  
    512 Like this: 
    513 {{{ 
    514   leftSceneView->getCullVisitor()->setTraversalMask( 0x1); 
    515   rightSceneView->getCullVisitor()->setTraversalMask( 0x2 ); 
    516  
    517  
    518   leftNode->setNodeMask(0x1); 
    519   rightNode->setNodeMask(0x2); 
    520  
    521 }}} 
    522  
    523  
    524 === On previous question - Yeah but.... it didn't work! === 
    525  
    526 XXX references osgProducer::Viewer 
    527  
    528 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): 
    529 {{{ 
    530     osgProducer::Viewer::SceneHandlerList shl = viewer.getSceneHandlerList(); 
    531     osgProducer::Viewer::SceneHandlerList::iterator p; 
    532     unsigned int n = 0; 
    533     for( p = shl.begin(); p != shl.end(); p++ ) 
    534     { 
    535         int inheritanceMask = (*p)->getSceneView()->getInheritanceMask(); 
    536         inheritanceMask &= ~(osg::CullSettings::CULL_MASK); 
    537         (*p)->getSceneView()->setInheritanceMask( inheritanceMask ); 
    538         (*p)->getSceneView()->setCullMask( 1<<(n)); 
    539         n++; 
    540     } 
    541 }}} 
    542  
    543  
    544 === How do I capture a screengrab? === 
    545  
    546 XXX references Producer 
    547 XXX there used to be functionality in osgviewer to do this, but it seems gone? 
    548  
    549 Producer example from `ViewerEventHandler.cpp` `ViewerEventHandler::SnapImageDrawCallback`: 
    550 {{{ 
    551 int x,y; 
    552 unsigned int width,height; 
    553 camera.getProjectionRectangle(x,y,width,height); 
    554 osg::ref_ptr<osg::Image> image = new osg::Image; 
    555 image->readPixels(x,y,width,height, GL_RGB,GL_UNSIGNED_BYTE); 
    556 osgDB::writeImageFile(*image,_filename); 
    557 }}} 
    558  
    559 GLUT example from the [http://www.it.uu.se/research/project/sst/api/d7/d5a/Main_8cpp-source.html SST Project]: 
    560  
    561 {{{ 
    562 osg::ref_ptr<osg::Image>image = new osg::Image; 
    563 unsigned int w = glutGet(GLUT_WINDOW_WIDTH); 
    564 unsigned int h = glutGet(GLUT_WINDOW_HEIGHT); 
    565 image->allocateImage(w, h, 1, GL_RGB, GL_UNSIGNED_BYTE); 
    566 image->readPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE); 
    567 }}} 
    568  
    569  
    570  
    571  
    572 === Why does my framerate drop when rendering point sprites to an FBO/pbuffer? === 
    573  
    574 Short answer: Change the coordinate origin mode of the !PointSprite attribute to LOWER_LEFT: 
    575 {{{ 
    576 osg::PointSprite *ps = new osg::PointSprite; 
    577 ps->setCoordOriginMode(osg::PointSprite::LOWER_LEFT); 
    578 }}} 
    579 Long answer: Read the section on Point Sprites in the nVidia OpenGL 2.0 Support document. It states the following: 
    580  
    581 When rendering to pixel buffers (commonly called pbuffers) or frame buffer objects 
    582 (commonly called FBOs), change the GL_POINT_SPRITE_COORD_ORIGIN state set to 
    583 GL_LOWER_LEFT setting for fully hardware accelerated rendering. Using GL_UPPER_LEFT 
    584 with pbuffer and FBO rendering will force points to be transformed on the CPU. 
    585  
    586 === Why does my geometry renders opaque while I have transparent colors and/or materials attached to it ? === 
    587  
    588 You need to activate OpenGL blending by setting the GL_BLEND mode on the geometry's stateset (or that of a parent node). 
    589 {{{ 
    590 stateSet->setMode( GL_BLEND, osg::StateAttribute::ON ); 
    591 }}} 
    592  
    593 Or in a .osg file: 
    594  
    595 {{{ 
    596 file geom.osg 
    597  
    598   Geometry { 
    599     [...] 
    600     StateSet { 
    601       GL_BLEND ON 
    602     } 
    603     PrimitiveSets 1 
    604     { 
    605     [..] 
    606 }}} 
    607  
    608  
    609 === I wrote a scene containing a particle system to a .ive file, but some nodes/drawables seem to be missing === 
    610  
    611 XXX Is this still valid with 2.4? 
    612  
    613 Some nodes and drawables in the osgParticle nodekit are currently not supported in .ive files. As a workaround you can save to a .osg file instead. 
    614  
    615  
    616 == __Older versions of OpenSceneGraph__ == 
    617  
    618 === During compile I get errors about Producer/*: No such file or directory. Why? - happens with daily builds and 0.9.4-2 official. === 
    619  
    620 First build and install [http://www.andesengineering.com/Producer/index.html OpenProducer]. 
    621  
    622 === Can I use OSG without Producer, and/or with already created MFC or !WxWindow windows ? === 
    623  
    624 You can use OSG with or without Producer, even if you are creating your 
    625 own windows.  See the osgsimple example for an example of using OSG with a 
    626 generic windowing environment.  OSG itself is windowing system agnostic, 
    627 so setting up the window and OpenGL graphics context will be up to your 
    628 application.  osgsimple uses Producer, but is written in a way to provide 
    629 you the skeleton to use your own windowing system. 
    630  
    631 Alternatively, you can use Producer in your own windowing environment as 
    632 well by setting each Camera's !RenderSurface to the window you've created. 
    633 Like this: 
    634 {{{ 
    635 osgProducer::Viewer viewer; 
    636 viewer.getCamera(0)->getRenderSurface()->setWindow( myWindow ); 
    637 }}} 
    638  
    639 The variable 'myWindow' is an X11 Window, or a win32 HWND. 
    640  
    641 See : http://osgcvs.no-ip.org/osgarchiver/archives/November2004/1019.html 
    642 for even more details. 
    643  
    644 === How can I change the Producer icon at run-time? === 
    645  
    646 In Microsoft Windows and Visual Studio 7.x: 
    647  
    648 First add an icon to your solution (Project/Add Recource/Icon). 
    649  
    650 After `viewer->realize()` do the following: 
    651 {{{ 
    652 Producer::Window wnd = viewer->getCamera(0)->getRenderSurface()->getWindow(); 
    653 HICON h1 = LoadIcon(GetModuleHandle(0), "YOUR_ICON"); 
    654 DWORD dw = SetClassLongPtr(wnd, GCL_HICON, (LONG_PTR)h1); 
    655 }}} 
    656  
    657 The string "YOUR_ICON" should refer to the icon name in your resource file(.rc). 
    658  
    659  
    660 == __Other__ == 
    661  
    662 === I have a matrix math question... === 
    663  
    664 Check the Matrix and Quaternion FAQ at http://www.j3d.org/matrix_faq/