(1) source program
# Include <osgdb/readfile>
# Include <osgproducer/Viewer>
# Include <osgutil/optimizer>
# Include <OSG/texgen>
# Include <OSG/texture2d>
Int main (INT argc, char * argv [])
{
STD: String filename ("cow. OSG ");
// Load the scene.
OSG: ref_ptr <OSG: node> loadedmodel = osgdb: readnodefile (filename );
If (! Loadedmodel)
{
STD: cout <argv [0] <": No data loaded." <STD: Endl;
Return 1;
}
// Construct the viewer.
Osgproducer: viewer;
// Set up the value with sensible default event handlers.
Viewer. setupviewer (osgproducer: Viewer: standard_settings );
// Optimize the scene graph, remove redundant nodes and state etc.
Osgutil: optimizer;
Optimizer. Optimize (loadedmodel. Get ());
// Add a reflection map to the teapot.
OSG: Image * image = osgdb: readimagefile ("images/LZ. RGB ");
If (image)
{
OSG: texture2d * texture = new OSG: texture2d;
Texture-> setimage (image );
OSG: texgen * texgen = new OSG: texgen;
Texgen-> setmode (OSG: texgen: sphere_map );
OSG: stateset * stateset = new OSG: stateset;
Stateset-> settextureattributeandmodes (0, texture, OSG: stateattribute: On );
Stateset-> settextureattributeandmodes (0, texgen, OSG: stateattribute: On );
Loadedmodel. Get ()-> setstateset (stateset );
}
// Add model to viewer.
Viewer. setscenedata (loadedmodel. Get ());
// Create the windows and run the threads.
Viewer. Realize ();
While (! Viewer. Done ())
{
// Wait for all cull and draw threads to complete.
Viewer. Sync ();
// Update the scene by traversing it with the update visitor which will
// Call all node update callbacks and animations.
Viewer. Update ();
// Fire off the cull and draw traversals of the scene.
Viewer. Frame ();
}
// Wait for all the clean up frame to complete.
Viewer. Sync ();
Return 0;
}
(2) Compile
Project/setting-> C/C ++, add/zm200 to the last/C of project options
(3) running error prompt:
Cocould not find plugin to read objects from file "cow. OSG"
This is to compile osgdb_rgbd.dll
Appendix:
Runtime errors appears when compiling osgteapot. solution:
(1) Enable run-time type information (rtti)
(2) debug multithreaded DLL