| | 39 | |
| | 40 | osg::Vec3 position(150.0f,800.0f,0.0f); |
| | 41 | osg::Vec3 delta(0.0f,-120.0f,0.0f); |
| | 42 | |
| | 43 | { |
| | 44 | osgText::Text* text = new osgText::Text; |
| | 45 | geode->addDrawable( text ); |
| | 46 | |
| | 47 | text->setFont(timesFont); |
| | 48 | text->setPosition(position); |
| | 49 | text->setText("Head Up Displays are simple :-)"); |
| | 50 | |
| | 51 | position += delta; |
| | 52 | } |
| | 53 | |
| | 54 | |
| | 55 | { |
| | 56 | osgText::Text* text = new osgText::Text; |
| | 57 | geode->addDrawable( text ); |
| | 58 | |
| | 59 | text->setFont(timesFont); |
| | 60 | text->setPosition(position); |
| | 61 | text->setText("All you need to do is create your text in a subgraph."); |
| | 62 | |
| | 63 | position += delta; |
| | 64 | } |
| | 65 | |
| | 66 | |
| | 67 | { |
| | 68 | osgText::Text* text = new osgText::Text; |
| | 69 | geode->addDrawable( text ); |
| | 70 | |
| | 71 | text->setFont(timesFont); |
| | 72 | text->setPosition(position); |
| | 73 | text->setText("Disable depth test in this subgraph to ensure its always ontop."); |
| | 74 | |
| | 75 | position += delta; |
| | 76 | } |
| | 77 | |
| | 78 | { |
| | 79 | osgText::Text* text = new osgText::Text; |
| | 80 | geode->addDrawable( text ); |
| | 81 | |
| | 82 | text->setFont(timesFont); |
| | 83 | text->setPosition(position); |
| | 84 | text->setText("Then place an osg::Projection node above the subgraph\nto create an orthographic projection."); |
| | 85 | |
| | 86 | position += delta; |
| | 87 | } |
| | 88 | |
| | 89 | { |
| | 90 | osgText::Text* text = new osgText::Text; |
| | 91 | geode->addDrawable( text ); |
| | 92 | |
| | 93 | text->setFont(timesFont); |
| | 94 | text->setPosition(position); |
| | 95 | text->setText("And add an osg::ModelViewMatrix set to ABSOLUTE_RF to ensure\nit remains independent from any external model view matrices."); |
| | 96 | |
| | 97 | position += delta; |
| | 98 | } |
| | 99 | |
| | 100 | |
| | 101 | |
| | 102 | { |
| | 103 | osg::BoundingBox bb; |
| | 104 | for(unsigned int i=0;i<geode->getNumDrawables();++i) |
| | 105 | { |
| | 106 | bb.expandBy(geode->getDrawable(i)->getBound()); |
| | 107 | } |
| | 108 | |
| | 109 | osg::Geometry* geom = new osg::Geometry; |
| | 110 | |
| | 111 | osg::Vec3Array* vertices = new osg::Vec3Array; |
| | 112 | float depth = bb.zMin()-0.1; |
| | 113 | vertices->push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth)); |
| | 114 | vertices->push_back(osg::Vec3(bb.xMin(),bb.yMin(),depth)); |
| | 115 | vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth)); |
| | 116 | vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth)); |
| | 117 | geom->setVertexArray(vertices); |
| | 118 | |
| | 119 | osg::Vec3Array* normals = new osg::Vec3Array; |
| | 120 | normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); |
| | 121 | geom->setNormalArray(normals); |
| | 122 | geom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
| | 123 | |
| | 124 | osg::Vec4Array* colors = new osg::Vec4Array; |
| | 125 | colors->push_back(osg::Vec4(1.0f,1.0,0.8f,0.2f)); |
| | 126 | geom->setColorArray(colors); |
| | 127 | geom->setColorBinding(osg::Geometry::BIND_OVERALL); |
| | 128 | |
| | 129 | geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); |
| | 130 | |
| | 131 | osg::StateSet* stateset = geom->getOrCreateStateSet(); |
| | 132 | stateset->setMode(GL_BLEND,osg::StateAttribute::ON); |
| | 133 | //stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON); |
| | 134 | stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
| | 135 | |
| | 136 | geode->addDrawable(geom); |
| | 137 | } |
| | 138 | |
| | 139 | #if 1 |
| | 140 | |
| | 141 | osg::CameraNode* camera = new osg::CameraNode; |
| | 142 | |
| | 143 | // set the projection matrix |
| | 144 | camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
| | 145 | |
| | 146 | // set the view matrix |
| | 147 | camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); |
| | 148 | camera->setViewMatrix(osg::Matrix::identity()); |
| | 149 | |
| | 150 | // only clear the depth buffer |
| | 151 | camera->setClearMask(GL_DEPTH_BUFFER_BIT); |
| | 152 | |
| | 153 | // draw subgraph after main camera view. |
| | 154 | camera->setRenderOrder(osg::CameraNode::POST_RENDER); |
| | 155 | |
| | 156 | camera->addChild(geode); |
| | 157 | |
| | 158 | return camera; |
| | 159 | |
| | 160 | #else |
| 50 | | osg::Vec3 position(150.0f,800.0f,0.0f); |
| 51 | | osg::Vec3 delta(0.0f,-120.0f,0.0f); |
| 52 | | |
| 53 | | { |
| 54 | | osgText::Text* text = new osgText::Text; |
| 55 | | geode->addDrawable( text ); |
| 56 | | |
| 57 | | text->setFont(timesFont); |
| 58 | | text->setPosition(position); |
| 59 | | text->setText("Head Up Displays are simple :-)"); |
| 60 | | |
| 61 | | position += delta; |
| 62 | | } |
| 63 | | |
| 64 | | |
| 65 | | { |
| 66 | | osgText::Text* text = new osgText::Text; |
| 67 | | geode->addDrawable( text ); |
| 68 | | |
| 69 | | text->setFont(timesFont); |
| 70 | | text->setPosition(position); |
| 71 | | text->setText("All you need to do is create your text in a subgraph."); |
| 72 | | |
| 73 | | position += delta; |
| 74 | | } |
| 75 | | |
| 76 | | |
| 77 | | { |
| 78 | | osgText::Text* text = new osgText::Text; |
| 79 | | geode->addDrawable( text ); |
| 80 | | |
| 81 | | text->setFont(timesFont); |
| 82 | | text->setPosition(position); |
| 83 | | text->setText("Disable depth test in this subgraph to ensure its always ontop."); |
| 84 | | |
| 85 | | position += delta; |
| 86 | | } |
| 87 | | |
| 88 | | { |
| 89 | | osgText::Text* text = new osgText::Text; |
| 90 | | geode->addDrawable( text ); |
| 91 | | |
| 92 | | text->setFont(timesFont); |
| 93 | | text->setPosition(position); |
| 94 | | text->setText("Then place an osg::Projection node above the subgraph\nto create an orthographic projection."); |
| 95 | | |
| 96 | | position += delta; |
| 97 | | } |
| 98 | | |
| 99 | | { |
| 100 | | osgText::Text* text = new osgText::Text; |
| 101 | | geode->addDrawable( text ); |
| 102 | | |
| 103 | | text->setFont(timesFont); |
| 104 | | text->setPosition(position); |
| 105 | | text->setText("And add an osg::ModelViewMatrix set to ABSOLUTE_RF to ensure\nit remains independent from any external model view matrices."); |
| 106 | | |
| 107 | | position += delta; |
| 108 | | } |
| 109 | | |
| 110 | | |
| 111 | | |
| 112 | | { |
| 113 | | osg::BoundingBox bb; |
| 114 | | for(unsigned int i=0;i<geode->getNumDrawables();++i) |
| 115 | | { |
| 116 | | bb.expandBy(geode->getDrawable(i)->getBound()); |
| 117 | | } |
| 118 | | |
| 119 | | osg::Geometry* geom = new osg::Geometry; |
| 120 | | |
| 121 | | osg::Vec3Array* vertices = new osg::Vec3Array; |
| 122 | | float depth = bb.zMin()-0.1; |
| 123 | | vertices->push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth)); |
| 124 | | vertices->push_back(osg::Vec3(bb.xMin(),bb.yMin(),depth)); |
| 125 | | vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth)); |
| 126 | | vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth)); |
| 127 | | geom->setVertexArray(vertices); |
| 128 | | |
| 129 | | osg::Vec3Array* normals = new osg::Vec3Array; |
| 130 | | normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); |
| 131 | | geom->setNormalArray(normals); |
| 132 | | geom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
| 133 | | |
| 134 | | osg::Vec4Array* colors = new osg::Vec4Array; |
| 135 | | colors->push_back(osg::Vec4(1.0f,1.0,0.8f,0.2f)); |
| 136 | | geom->setColorArray(colors); |
| 137 | | geom->setColorBinding(osg::Geometry::BIND_OVERALL); |
| 138 | | |
| 139 | | geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); |
| 140 | | |
| 141 | | osg::StateSet* stateset = geom->getOrCreateStateSet(); |
| 142 | | stateset->setMode(GL_BLEND,osg::StateAttribute::ON); |
| 143 | | //stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON); |
| 144 | | stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
| 145 | | |
| 146 | | geode->addDrawable(geom); |
| 147 | | } |
| | 173 | |