24 osg::Geometry *geometry =
new osg::Geometry();
25 osg::Vec3Array *vertices =
new osg::Vec3Array();
26 osg::Vec3Array *normals =
new osg::Vec3Array();
27 osg::Vec4Array *colors =
new osg::Vec4Array();
29 vertices->push_back(osg::Vec3(-10.0, -10.0, 0.1));
30 vertices->push_back(osg::Vec3(-10.0, 10.0, 0.1));
31 vertices->push_back(osg::Vec3(10.0, 10.0, 0.1));
32 vertices->push_back(osg::Vec3(10.0, -10.0, 0.1));
33 normals->push_back(osg::Vec3(0.0, 0.0, 1.0));
34 geometry->setVertexArray(vertices);
35 geometry->setNormalArray(normals);
36 colors->push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0));
37 geometry->setColorArray(colors);
38 geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
39 geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
40 geometry->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));
42 osg::Geode *geode =
new osg::Geode();
43 geode->addDrawable(geometry);
44 geode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
49 osg::Transform *trans =
new osg::Transform();
50 trans->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
51 trans->addChild( geode );
53 osg::Projection *proj =
new osg::Projection(osg::Matrix::ortho2D(-1,1,-1,1));
54 proj->addChild( trans );
64 osg::ref_ptr<osg::StateSet> ss =
new osg::StateSet;
65 osg::Stencil *stencil =
new osg::Stencil;
66 stencil->setFunction(osg::Stencil::ALWAYS, 0x0, ~0);
67 stencil->setOperation(osg::Stencil::INVERT, osg::Stencil::INVERT, osg::Stencil::INVERT);
68 ss->setAttributeAndModes(stencil, osg::StateAttribute::ON);
69 ss->setMode(GL_CULL_FACE,osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
74 osg::ref_ptr<osg::StateSet> ss =
new osg::StateSet;
75 osg::Stencil *stencil =
new osg::Stencil;
76 stencil->setFunction(osg::Stencil::NOTEQUAL, 0x0, ~0);
77 stencil->setOperation(osg::Stencil::ZERO, osg::Stencil::ZERO,osg::Stencil::ZERO);
78 ss->setAttributeAndModes(stencil, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
79 ss->setMode(GL_CLIP_PLANE0, osg::StateAttribute::OFF);
80 osg::Depth *depth =
new osg::Depth();
81 depth->setWriteMask(
true);
82 ss->setAttributeAndModes( depth, osg::StateAttribute::ON);
83 ss->setMode(GL_CULL_FACE,osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
84 ss->setAttributeAndModes(
new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL));
85 ss->setMode(GL_CLIP_PLANE0, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);