OSG draws a sphere

Source: Internet
Author: User
Tags addchild

// 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

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.