| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | #include <osgDB/ReadFile> |
|---|
| 16 | #include <osgProducer/Viewer> |
|---|
| 17 | |
|---|
| 18 | #include <osg/Material> |
|---|
| 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/BlendFunc> |
|---|
| 21 | #include <osg/Depth> |
|---|
| 22 | #include <osg/Projection> |
|---|
| 23 | #include <osg/MatrixTransform> |
|---|
| 24 | |
|---|
| 25 | #include <osgText/Text> |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | osg::Node* createHUD() |
|---|
| 29 | { |
|---|
| 30 | osg::Geode* geode = new osg::Geode(); |
|---|
| 31 | |
|---|
| 32 | std::string timesFont("fonts/times.ttf"); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
|---|
| 36 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
|---|
| 37 | stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); |
|---|
| 38 | |
|---|
| 39 | osg::Vec3 position(150.0f,800.0f,0.0f); |
|---|
| 40 | osg::Vec3 delta(0.0f,-120.0f,0.0f); |
|---|
| 41 | |
|---|
| 42 | { |
|---|
| 43 | osgText::Text* text = new osgText::Text; |
|---|
| 44 | geode->addDrawable( text ); |
|---|
| 45 | |
|---|
| 46 | text->setFont(timesFont); |
|---|
| 47 | text->setText("Head Up Displays are simple :-)"); |
|---|
| 48 | text->setPosition(position); |
|---|
| 49 | |
|---|
| 50 | position += delta; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | { |
|---|
| 55 | osgText::Text* text = new osgText::Text; |
|---|
| 56 | geode->addDrawable( text ); |
|---|
| 57 | |
|---|
| 58 | text->setFont(timesFont); |
|---|
| 59 | text->setText("All you need to do is create your text in a subgraph."); |
|---|
| 60 | text->setPosition(position); |
|---|
| 61 | |
|---|
| 62 | position += delta; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | { |
|---|
| 67 | osgText::Text* text = new osgText::Text; |
|---|
| 68 | geode->addDrawable( text ); |
|---|
| 69 | |
|---|
| 70 | text->setFont(timesFont); |
|---|
| 71 | text->setText("Disable depth test in this subgraph to ensure its always ontop."); |
|---|
| 72 | text->setPosition(position); |
|---|
| 73 | |
|---|
| 74 | position += delta; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | { |
|---|
| 78 | osgText::Text* text = new osgText::Text; |
|---|
| 79 | geode->addDrawable( text ); |
|---|
| 80 | |
|---|
| 81 | text->setFont(timesFont); |
|---|
| 82 | text->setText("Then place a osg::Projection node above the subgraph\nto create an orthographic projection."); |
|---|
| 83 | text->setPosition(position); |
|---|
| 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->setText("And add an osg::ModelViewMatrix set to ABSOLUTE to ensure\nit remains independent from any external model view matrices."); |
|---|
| 94 | text->setPosition(position); |
|---|
| 95 | |
|---|
| 96 | position += delta; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; |
|---|
| 101 | modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); |
|---|
| 102 | modelview_abs->setMatrix(osg::Matrix::identity()); |
|---|
| 103 | modelview_abs->addChild(geode); |
|---|
| 104 | |
|---|
| 105 | osg::Projection* projection = new osg::Projection; |
|---|
| 106 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
|---|
| 107 | projection->addChild(modelview_abs); |
|---|
| 108 | |
|---|
| 109 | return projection; |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | int main( int argc, char **argv ) |
|---|
| 114 | { |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] [filename] ..."); |
|---|
| 121 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | osgProducer::Viewer viewer(arguments); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 135 | { |
|---|
| 136 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 137 | return 1; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | if (arguments.errors()) |
|---|
| 145 | { |
|---|
| 146 | arguments.writeErrorMessages(std::cout); |
|---|
| 147 | return 1; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); |
|---|
| 153 | |
|---|
| 154 | osg::ref_ptr<osg::Group> group = dynamic_cast<osg::Group*>(scene.get()); |
|---|
| 155 | if (!group) |
|---|
| 156 | { |
|---|
| 157 | group = new osg::Group; |
|---|
| 158 | group->addChild(scene.get()); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | group->addChild(createHUD()); |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | viewer.setSceneData(group.get()); |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 169 | |
|---|
| 170 | while( !viewer.done() ) |
|---|
| 171 | { |
|---|
| 172 | |
|---|
| 173 | viewer.sync(); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | viewer.update(); |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | viewer.frame(); |
|---|
| 181 | |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | return 0; |
|---|
| 185 | } |
|---|