// By smells2 at lab 2012-02-21
# Include <OSG/group>
# Include <OSG/geode>
# Include <OSG/shapedrawable>
# Include <OSG/texture2d>
# Include <osgviewer/Viewer>
# Include <osgdb/readfile>
# Include <OSG/positionattitudetransform>
# Include <OSG/texenv>
# Include <OSG/texture2d>
# Include <iostream>
Int main ()
{
OSG: ref_ptr <OSG: group> root = new OSG: group;
Osgviewer: viewer myviewer;
// Declear sphere instance, the constructor takes an OSG: vec3 to define
// Center and a float to define the radius.
// Then we declear the shapdrawable instance that derive from drawable. We shocould
// Initalize it with the shape we create abve.
OSG: ref_ptr <OSG: geode> unitsphere = new OSG: geode;
OSG: ref_ptr <OSG: sphere> sphere = new OSG: sphere (OSG: vec3 (0, 0), 1.0f );
OSG: ref_ptr <OSG: shapedrawable> shapedrawable = new OSG: shapedrawable (sphere. Get ());
Unitsphere-> adddrawable (shapedrawable. Get ());
OSG: ref_ptr <OSG: positionattitudetransform> sphereform = new OSG: positionattitudetransform;
Sphereform-> setposition (OSG: vec3 (2.5, 0.0, 0.0 ));
Sphereform-> addchild (unitsphere. Get ());
Root-> addchild (sphereform. Get ());
// Load image from the file
OSG: ref_ptr <OSG: texture2d> earthtexture = new OSG: texture2d;
Earthtexture-> setdatavariance (OSG: object: Dynamic );
OSG: ref_ptr <OSG: Image> earthimage = osgdb: readimagefile ("D: \ OSG \ osg2.9 \ openscenegraph2.9.5 \ data \ images \ land_shallow_topo_2048.jpg ");
If (! Earthimage. Get ())
{
STD: cout <"load texture failed! "<STD: Endl;
Return-1;
}
// Assign the texture from the image file
Earthtexture-> setimage (earthimage. Get ());
// Set the stateset for decal texture
OSG: ref_ptr <OSG: texenv> texenv = new OSG: texenv;
OSG: ref_ptr <OSG: stateset> stateset = new OSG: stateset;
Texenv-> setmode (OSG: texenv: decal );
Stateset-> settextureattributeandmodes (0, earthtexture. Get (), OSG: stateattribute: On );
Stateset-> settextureattribute (0, texenv. Get ());
// Realize
Root-> setstateset (stateset. Get ());
Myviewer. setscenedata (root. Get ());
Myviewer. Realize ();
Myviewer. Run ();
}
OSG draws a sphere