Use vc6.0 to compile the first openscenegraph Program

Source: Internet
Author: User

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.