OSG renders the code to the texture, and renders the read node as the texture to a square.

Source: Internet
Author: User

OSG: Group * Group = new OSG: group;
OSG: node * node = osgdb: readnodefile ("d :\\ cow. OSG ");

OSG: Camera * camera = new OSG: camera;
Camera-> setviewport (0, 0,256,256 );

OSG: Image * IMG = new OSG: image;
IMG-> allocateimage (256,256, 1, gl_rgba, gl_float );
 
OSG: texture2d * texture2d = new OSG: texture2d;

Texture2d-> settexturesize (256,256 );
Texture2d-> setinternalformat (gl_rgba );

// Camera-> attach (Camera: color_buffer, texture2d, 0, 0 );
Camera-> attach (Camera: color_buffer, IMG, 0, 0 );
Texture2d-> setimage (0, IMG );

Const OSG: boundingsphere & BS = node-> getbound (); // OSG: Group = new OSG: Group

Float znear = 1.0f * BS. radius ();
Float zfar = 3.0f * BS. radius ();

Float proj_top = 0.25f * znear;
Float proj_right = 0.5f * znear;

Znear * = 0.9f;
Zfar * = 1.1f;

// Set up projection.
Camera-> setprojectionmatrixasfrustum (-proj_right, proj_right,-proj_top, proj_top, znear, zfar );

// Set view // set up projection
Camera-> setreferenceframe (OSG: Transform: absolute_rf );
Camera-> setviewmatrixaslookat (BS. center ()-OSG: vec3 (0.0f, 2.0f, 0.0f) * BS. radius (), BS. center (), OSG: vec3 (0.0f, 0.0f, 1.0f ));

Camera-> setrenderorder (OSG: Camera: pre_render );
Camera-> setrendertargetimplementation (Camera: frame_buffer_object );

Camera-> addchild (node );

Group-> addchild (CAMERA );

OSG: geometry * geometry = new OSG: geometry;
OSG: vec3array * vertex = new OSG: vec3array;
OSG: vec2array * coord = new OSG: vec2array;

Vertex-> push_back (OSG: vec3 (0.0, 0.0, 0.0 ));
Vertex-> push_back (OSG: vec3 (10.0, 0.0, 0.0 ));
Vertex-> push_back (OSG: vec3 (10.0, 10.0, 0.0 ));
Vertex-> push_back (OSG: vec3 (0.0, 10.0, 0.0 ));

Coord-> push_back (OSG: vec2 (0.0, 0.0 ));
Coord-> push_back (OSG: vec2 (1.0, 0.0 ));
Coord-> push_back (OSG: vec2 (1.0, 1.0 ));
Coord-> push_back (OSG: vec2 (0.0, 1.0 ));

Geometry-> settexcoordarray (0, coord );

Geometry-> setvertexarray (vertex );
Geometry-> addprimitiveset (New OSG: drawarrays (OSG: drawarrays: quads, 0, vertex-> size ()));

OSG: geode * geode = new OSG: geode;
Geode-> adddrawable (geometry );

 

OSG: stateset * statsset = new OSG: stateset;
Statsset-> settextureattributeandmodes (0, texture2d, OSG: stateattribute: On );

Geometry-> setstateset (statsset );

Group-> addchild (geode );

Osgviewer: viewer;
Viewer. setscenedata (group );
Return viewer. Run ();

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.