| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | #include <osgDB/ReadFile> |
|---|
| 16 | #include <osgDB/Registry> |
|---|
| 17 | #include <osgProducer/Viewer> |
|---|
| 18 | |
|---|
| 19 | #include <osg/Material> |
|---|
| 20 | #include <osg/Geode> |
|---|
| 21 | #include <osg/BlendFunc> |
|---|
| 22 | #include <osg/Depth> |
|---|
| 23 | #include <osg/Projection> |
|---|
| 24 | #include <osg/MatrixTransform> |
|---|
| 25 | |
|---|
| 26 | #include <osgText/Text> |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | osg::Group* createHUDText() |
|---|
| 30 | { |
|---|
| 31 | |
|---|
| 32 | osg::Geode* geode = new osg::Geode; |
|---|
| 33 | |
|---|
| 34 | osgText::Text* text1 = new osgText::Text; |
|---|
| 35 | text1->setCharacterSize(12.0f); |
|---|
| 36 | text1->setText("20 GOTO 10"); |
|---|
| 37 | geode->addDrawable(text1); |
|---|
| 38 | |
|---|
| 39 | osgText::Text* text2 = new osgText::Text; |
|---|
| 40 | text2->setPosition(osg::Vec3(0.0f,50.0f,0.0f)); |
|---|
| 41 | text2->setCharacterSize(12.0f); |
|---|
| 42 | text2->setText("10 PRINT \"Hello World\""); |
|---|
| 43 | geode->addDrawable(text2); |
|---|
| 44 | |
|---|
| 45 | osgText::Text* text3 = new osgText::Text; |
|---|
| 46 | text3->setFont(osgText::readFontFile("fonts/arial.ttf")); |
|---|
| 47 | text3->setPosition(osg::Vec3(100.0f,100.0f,0.0f)); |
|---|
| 48 | text3->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/arial.ttf"); |
|---|
| 49 | geode->addDrawable(text3); |
|---|
| 50 | |
|---|
| 51 | osgText::Text* text4 = new osgText::Text; |
|---|
| 52 | text4->setFont(osgText::readFontFile("fonts/times.ttf")); |
|---|
| 53 | text4->setFontSize(128,128); |
|---|
| 54 | text4->setPosition(osg::Vec3(200.0f,200.0f,0.0f)); |
|---|
| 55 | text4->setLayout(osgText::Text::RIGHT_TO_LEFT); |
|---|
| 56 | text4->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); |
|---|
| 57 | text4->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/times.ttf"); |
|---|
| 58 | geode->addDrawable(text4); |
|---|
| 59 | |
|---|
| 60 | osgText::Text* text5 = new osgText::Text; |
|---|
| 61 | text5->setFont(osgText::readFontFile("fonts/dirtydoz.ttf")); |
|---|
| 62 | text5->setPosition(osg::Vec3(300.0f,300.0f,0.0f)); |
|---|
| 63 | text5->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); |
|---|
| 64 | text5->setLayout(osgText::Text::VERTICAL); |
|---|
| 65 | text5->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); |
|---|
| 66 | text5->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/dirtydoz.ttf"); |
|---|
| 67 | geode->addDrawable(text5); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | osg::Group* rootNode = new osg::Group; |
|---|
| 85 | rootNode->addChild(geode); |
|---|
| 86 | |
|---|
| 87 | return rootNode; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | osg::Group* create3DText() |
|---|
| 91 | { |
|---|
| 92 | |
|---|
| 93 | osg::Geode* geode = new osg::Geode; |
|---|
| 94 | |
|---|
| 95 | osgText::Text* text1 = new osgText::Text; |
|---|
| 96 | text1->setFont("fonts/times.ttf"); |
|---|
| 97 | text1->setAxisAlignment(osgText::Text::XY_PLANE); |
|---|
| 98 | text1->setText("XY_PLANE"); |
|---|
| 99 | geode->addDrawable(text1); |
|---|
| 100 | |
|---|
| 101 | osgText::Text* text2 = new osgText::Text; |
|---|
| 102 | text2->setFont("fonts/times.ttf"); |
|---|
| 103 | text2->setPosition(osg::Vec3(0.0f,0.0f,0.0f)); |
|---|
| 104 | text2->setAxisAlignment(osgText::Text::YZ_PLANE); |
|---|
| 105 | text2->setText("YZ_PLANE"); |
|---|
| 106 | geode->addDrawable(text2); |
|---|
| 107 | |
|---|
| 108 | osgText::Text* text3 = new osgText::Text; |
|---|
| 109 | text3->setFont("fonts/times.ttf"); |
|---|
| 110 | text3->setPosition(osg::Vec3(00.0f,00.0f,00.0f)); |
|---|
| 111 | text3->setAxisAlignment(osgText::Text::XZ_PLANE); |
|---|
| 112 | text3->setText("XZ_PLANE"); |
|---|
| 113 | geode->addDrawable(text3); |
|---|
| 114 | |
|---|
| 115 | osgText::Text* text4 = new osgText::Text; |
|---|
| 116 | text4->setFont("fonts/times.ttf"); |
|---|
| 117 | text4->setAxisAlignment(osgText::Text::SCREEN); |
|---|
| 118 | text4->setPosition(osg::Vec3(00.0f,00.0f,00.0f)); |
|---|
| 119 | text4->setText("SCREEN"); |
|---|
| 120 | geode->addDrawable(text4); |
|---|
| 121 | |
|---|
| 122 | osg::Group* rootNode = new osg::Group; |
|---|
| 123 | rootNode->addChild(geode); |
|---|
| 124 | |
|---|
| 125 | return rootNode; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | int main( int argc, char **argv ) |
|---|
| 129 | { |
|---|
| 130 | |
|---|
| 131 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] [filename] ..."); |
|---|
| 135 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | osgProducer::Viewer viewer(arguments); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 149 | { |
|---|
| 150 | arguments.getApplicationUsage()->write(cout); |
|---|
| 151 | return 1; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | if (arguments.errors()) |
|---|
| 159 | { |
|---|
| 160 | arguments.writeErrorMessages(cout); |
|---|
| 161 | return 1; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | osg::ref_ptr<osg::Node> rootNode = osgDB::readNodeFiles(arguments); |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | { |
|---|
| 170 | |
|---|
| 171 | if (rootNode.valid()) |
|---|
| 172 | { |
|---|
| 173 | |
|---|
| 174 | osgUtil::Optimizer optimizer; |
|---|
| 175 | optimizer.optimize(rootNode.get()); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | osg::Group* group = dynamic_cast<osg::Group*>(rootNode.get()); |
|---|
| 180 | if (!group) |
|---|
| 181 | { |
|---|
| 182 | group = new osg::Group; |
|---|
| 183 | |
|---|
| 184 | if (rootNode.valid()) group->addChild(rootNode.get()); |
|---|
| 185 | |
|---|
| 186 | rootNode = group; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | { |
|---|
| 190 | |
|---|
| 191 | osg::Projection* projection = new osg::Projection; |
|---|
| 192 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
|---|
| 193 | |
|---|
| 194 | osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; |
|---|
| 195 | modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); |
|---|
| 196 | modelview_abs->setMatrix(osg::Matrix::identity()); |
|---|
| 197 | |
|---|
| 198 | modelview_abs->addChild(createHUDText()); |
|---|
| 199 | |
|---|
| 200 | projection->addChild(modelview_abs); |
|---|
| 201 | |
|---|
| 202 | group->addChild(projection); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | osg::MatrixTransform* scale = new osg::MatrixTransform; |
|---|
| 206 | scale->setMatrix(osg::Matrix::scale(1.0f,1.0f,1.0f)); |
|---|
| 207 | scale->addChild(create3DText()); |
|---|
| 208 | group->addChild(scale); |
|---|
| 209 | |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | viewer.setSceneData(rootNode.get()); |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 217 | |
|---|
| 218 | while( !viewer.done() ) |
|---|
| 219 | { |
|---|
| 220 | |
|---|
| 221 | viewer.sync(); |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | viewer.update(); |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | viewer.frame(); |
|---|
| 229 | |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | return 0; |
|---|
| 233 | } |
|---|