| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | |
|---|
| 16 | #include <osgDB/ReadFile> |
|---|
| 17 | #include <osgDB/WriteFile> |
|---|
| 18 | #include <osgDB/Registry> |
|---|
| 19 | |
|---|
| 20 | #include <osgProducer/Viewer> |
|---|
| 21 | |
|---|
| 22 | #include <osg/Geode> |
|---|
| 23 | #include <osg/CameraNode> |
|---|
| 24 | #include <osg/ShapeDrawable> |
|---|
| 25 | #include <osg/Sequence> |
|---|
| 26 | |
|---|
| 27 | #include <osgText/Font> |
|---|
| 28 | #include <osgText/Text> |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | osg::Group* createHUDText() |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | osg::Group* rootNode = new osg::Group; |
|---|
| 35 | |
|---|
| 36 | osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); |
|---|
| 37 | |
|---|
| 38 | osg::Geode* geode = new osg::Geode; |
|---|
| 39 | rootNode->addChild(geode); |
|---|
| 40 | |
|---|
| 41 | float windowHeight = 1024.0f; |
|---|
| 42 | float windowWidth = 1280.0f; |
|---|
| 43 | float margin = 50.0f; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f); |
|---|
| 52 | float layoutCharacterSize = 20.0f; |
|---|
| 53 | |
|---|
| 54 | { |
|---|
| 55 | osgText::Text* text = new osgText::Text; |
|---|
| 56 | text->setFont(font); |
|---|
| 57 | text->setColor(layoutColor); |
|---|
| 58 | text->setCharacterSize(layoutCharacterSize); |
|---|
| 59 | text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f)); |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | text->setLayout(osgText::Text::LEFT_TO_RIGHT); |
|---|
| 64 | |
|---|
| 65 | text->setText("text->setLayout(osgText::Text::LEFT_TO_RIGHT);"); |
|---|
| 66 | geode->addDrawable(text); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | { |
|---|
| 70 | osgText::Text* text = new osgText::Text; |
|---|
| 71 | text->setFont(font); |
|---|
| 72 | text->setColor(layoutColor); |
|---|
| 73 | text->setCharacterSize(layoutCharacterSize); |
|---|
| 74 | text->setPosition(osg::Vec3(windowWidth-margin,windowHeight-margin,0.0f)); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | text->setLayout(osgText::Text::RIGHT_TO_LEFT); |
|---|
| 78 | text->setAlignment(osgText::Text::RIGHT_BASE_LINE); |
|---|
| 79 | |
|---|
| 80 | text->setText("text->setLayout(osgText::Text::RIGHT_TO_LEFT);"); |
|---|
| 81 | geode->addDrawable(text); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | { |
|---|
| 85 | osgText::Text* text = new osgText::Text; |
|---|
| 86 | text->setFont(font); |
|---|
| 87 | text->setColor(layoutColor); |
|---|
| 88 | text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f)); |
|---|
| 89 | text->setCharacterSize(layoutCharacterSize); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | text->setLayout(osgText::Text::VERTICAL); |
|---|
| 93 | |
|---|
| 94 | text->setText("text->setLayout(osgText::Text::VERTICAL);"); |
|---|
| 95 | geode->addDrawable(text); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | osg::Vec4 fontSizeColor(0.0f,1.0f,1.0f,1.0f); |
|---|
| 105 | float fontSizeCharacterSize = 30; |
|---|
| 106 | |
|---|
| 107 | osg::Vec3 cursor = osg::Vec3(margin*2,windowHeight-margin*2,0.0f); |
|---|
| 108 | |
|---|
| 109 | { |
|---|
| 110 | osgText::Text* text = new osgText::Text; |
|---|
| 111 | text->setFont(font); |
|---|
| 112 | text->setColor(fontSizeColor); |
|---|
| 113 | text->setCharacterSize(fontSizeCharacterSize); |
|---|
| 114 | text->setPosition(cursor); |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | text->setFontResolution(10,10); |
|---|
| 118 | |
|---|
| 119 | text->setText("text->setFontResolution(10,10); // blocky but small texture memory usage"); |
|---|
| 120 | geode->addDrawable(text); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | cursor.y() -= fontSizeCharacterSize; |
|---|
| 124 | { |
|---|
| 125 | osgText::Text* text = new osgText::Text; |
|---|
| 126 | text->setFont(font); |
|---|
| 127 | text->setColor(fontSizeColor); |
|---|
| 128 | text->setCharacterSize(fontSizeCharacterSize); |
|---|
| 129 | text->setPosition(cursor); |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | text->setFontResolution(20,20); |
|---|
| 133 | |
|---|
| 134 | text->setText("text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low)."); |
|---|
| 135 | geode->addDrawable(text); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | cursor.y() -= fontSizeCharacterSize; |
|---|
| 139 | { |
|---|
| 140 | osgText::Text* text = new osgText::Text; |
|---|
| 141 | text->setFont(font); |
|---|
| 142 | text->setColor(fontSizeColor); |
|---|
| 143 | text->setCharacterSize(fontSizeCharacterSize); |
|---|
| 144 | text->setPosition(cursor); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | text->setFontResolution(40,40); |
|---|
| 148 | |
|---|
| 149 | text->setText("text->setFontResolution(40,40); // even smoother but again higher texture memory usage."); |
|---|
| 150 | geode->addDrawable(text); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | osg::Vec4 characterSizeColor(1.0f,0.0f,1.0f,1.0f); |
|---|
| 160 | |
|---|
| 161 | cursor.y() -= fontSizeCharacterSize*2.0f; |
|---|
| 162 | |
|---|
| 163 | { |
|---|
| 164 | osgText::Text* text = new osgText::Text; |
|---|
| 165 | text->setFont(font); |
|---|
| 166 | text->setColor(characterSizeColor); |
|---|
| 167 | text->setFontResolution(20,20); |
|---|
| 168 | text->setPosition(cursor); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | text->setCharacterSize(20); |
|---|
| 172 | |
|---|
| 173 | text->setText("text->setCharacterSize(20.0f); // small"); |
|---|
| 174 | geode->addDrawable(text); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | cursor.y() -= 30.0f; |
|---|
| 178 | { |
|---|
| 179 | osgText::Text* text = new osgText::Text; |
|---|
| 180 | text->setFont(font); |
|---|
| 181 | text->setColor(characterSizeColor); |
|---|
| 182 | text->setFontResolution(30,30); |
|---|
| 183 | text->setPosition(cursor); |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | text->setCharacterSize(30.0f); |
|---|
| 187 | |
|---|
| 188 | text->setText("text->setCharacterSize(30.0f); // medium"); |
|---|
| 189 | geode->addDrawable(text); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | cursor.y() -= 50.0f; |
|---|
| 193 | { |
|---|
| 194 | osgText::Text* text = new osgText::Text; |
|---|
| 195 | text->setFont(font); |
|---|
| 196 | text->setColor(characterSizeColor); |
|---|
| 197 | text->setFontResolution(40,40); |
|---|
| 198 | text->setPosition(cursor); |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | text->setCharacterSize(60.0f); |
|---|
| 202 | |
|---|
| 203 | text->setText("text->setCharacterSize(60.0f); // large"); |
|---|
| 204 | geode->addDrawable(text); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | osg::Vec4 alignmentSizeColor(0.0f,1.0f,0.0f,1.0f); |
|---|
| 214 | float alignmentCharacterSize = 25.0f; |
|---|
| 215 | cursor.x() = 640; |
|---|
| 216 | cursor.y() = margin*4.0f; |
|---|
| 217 | |
|---|
| 218 | typedef std::pair<osgText::Text::AlignmentType,std::string> AlignmentPair; |
|---|
| 219 | typedef std::vector<AlignmentPair> AlignmentList; |
|---|
| 220 | AlignmentList alignmentList; |
|---|
| 221 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_TOP,"text->setAlignment(\nosgText::Text::LEFT_TOP);")); |
|---|
| 222 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_CENTER,"text->setAlignment(\nosgText::Text::LEFT_CENTER);")); |
|---|
| 223 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BOTTOM,"text->setAlignment(\nosgText::Text::LEFT_BOTTOM);")); |
|---|
| 224 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_TOP,"text->setAlignment(\nosgText::Text::CENTER_TOP);")); |
|---|
| 225 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_CENTER,"text->setAlignment(\nosgText::Text::CENTER_CENTER);")); |
|---|
| 226 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BOTTOM,"text->setAlignment(\nosgText::Text::CENTER_BOTTOM);")); |
|---|
| 227 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_TOP,"text->setAlignment(\nosgText::Text::RIGHT_TOP);")); |
|---|
| 228 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_CENTER,"text->setAlignment(\nosgText::Text::RIGHT_CENTER);")); |
|---|
| 229 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BOTTOM,"text->setAlignment(\nosgText::Text::RIGHT_BOTTOM);")); |
|---|
| 230 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BASE_LINE,"text->setAlignment(\nosgText::Text::LEFT_BASE_LINE);")); |
|---|
| 231 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BASE_LINE,"text->setAlignment(\nosgText::Text::CENTER_BASE_LINE);")); |
|---|
| 232 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BASE_LINE,"text->setAlignment(\nosgText::Text::RIGHT_BASE_LINE);")); |
|---|
| 233 | alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BOTTOM_BASE_LINE,"text->setAlignment(\nosgText::Text::LEFT_BOTTOM_BASE_LINE);")); |
|---|
| 234 | alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BOTTOM_BASE_LINE,"text->setAlignment(\nosgText::Text::CENTER_BOTTOM_BASE_LINE);")); |
|---|
| 235 | alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BOTTOM_BASE_LINE,"text->setAlignment(\nosgText::Text::RIGHT_BOTTOM_BASE_LINE);")); |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | osg::Sequence* sequence = new osg::Sequence; |
|---|
| 239 | { |
|---|
| 240 | for(AlignmentList::iterator itr=alignmentList.begin(); |
|---|
| 241 | itr!=alignmentList.end(); |
|---|
| 242 | ++itr) |
|---|
| 243 | { |
|---|
| 244 | osg::Geode* alignmentGeode = new osg::Geode; |
|---|
| 245 | sequence->addChild(alignmentGeode); |
|---|
| 246 | sequence->setTime(sequence->getNumChildren(), 1.0f); |
|---|
| 247 | |
|---|
| 248 | osgText::Text* text = new osgText::Text; |
|---|
| 249 | text->setFont(font); |
|---|
| 250 | text->setColor(alignmentSizeColor); |
|---|
| 251 | text->setCharacterSize(alignmentCharacterSize); |
|---|
| 252 | text->setPosition(cursor); |
|---|
| 253 | text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); |
|---|
| 254 | |
|---|
| 255 | text->setAlignment(itr->first); |
|---|
| 256 | text->setText(itr->second); |
|---|
| 257 | |
|---|
| 258 | alignmentGeode->addDrawable(text); |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | sequence->setMode(osg::Sequence::START); |
|---|
| 266 | sequence->setInterval(osg::Sequence::LOOP, 0, -1); |
|---|
| 267 | sequence->setDuration(1.0f, -1); |
|---|
| 268 | |
|---|
| 269 | rootNode->addChild(sequence); |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | cursor.x() = margin*2.0f; |
|---|
| 278 | cursor.y() = margin*2.0f; |
|---|
| 279 | |
|---|
| 280 | osg::Vec4 fontColor(1.0f,0.5f,0.0f,1.0f); |
|---|
| 281 | float fontCharacterSize = 20.0f; |
|---|
| 282 | float spacing = 40.0f; |
|---|
| 283 | |
|---|
| 284 | { |
|---|
| 285 | osgText::Text* text = new osgText::Text; |
|---|
| 286 | text->setColor(fontColor); |
|---|
| 287 | text->setPosition(cursor); |
|---|
| 288 | text->setCharacterSize(fontCharacterSize); |
|---|
| 289 | |
|---|
| 290 | text->setFont(0); |
|---|
| 291 | text->setText("text->setFont(0); // inbuilt font."); |
|---|
| 292 | geode->addDrawable(text); |
|---|
| 293 | |
|---|
| 294 | cursor.x() = text->getBound().xMax() + spacing ; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | { |
|---|
| 298 | osgText::Font* arial = osgText::readFontFile("fonts/arial.ttf"); |
|---|
| 299 | |
|---|
| 300 | osgText::Text* text = new osgText::Text; |
|---|
| 301 | text->setColor(fontColor); |
|---|
| 302 | text->setPosition(cursor); |
|---|
| 303 | text->setCharacterSize(fontCharacterSize); |
|---|
| 304 | |
|---|
| 305 | text->setFont(arial); |
|---|
| 306 | text->setText(arial!=0? |
|---|
| 307 | "text->setFont(\"fonts/arial.ttf\");": |
|---|
| 308 | "unable to load \"fonts/arial.ttf\""); |
|---|
| 309 | geode->addDrawable(text); |
|---|
| 310 | |
|---|
| 311 | cursor.x() = text->getBound().xMax() + spacing ; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | { |
|---|
| 315 | osgText::Font* times = osgText::readFontFile("fonts/times.ttf"); |
|---|
| 316 | |
|---|
| 317 | osgText::Text* text = new osgText::Text; |
|---|
| 318 | text->setColor(fontColor); |
|---|
| 319 | text->setPosition(cursor); |
|---|
| 320 | text->setCharacterSize(fontCharacterSize); |
|---|
| 321 | |
|---|
| 322 | geode->addDrawable(text); |
|---|
| 323 | text->setFont(times); |
|---|
| 324 | text->setText(times!=0? |
|---|
| 325 | "text->setFont(\"fonts/times.ttf\");": |
|---|
| 326 | "unable to load \"fonts/times.ttf\""); |
|---|
| 327 | |
|---|
| 328 | cursor.x() = text->getBound().xMax() + spacing ; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | cursor.x() = margin*2.0f; |
|---|
| 332 | cursor.y() = margin; |
|---|
| 333 | |
|---|
| 334 | { |
|---|
| 335 | osgText::Font* dirtydoz = osgText::readFontFile("fonts/dirtydoz.ttf"); |
|---|
| 336 | |
|---|
| 337 | osgText::Text* text = new osgText::Text; |
|---|
| 338 | text->setColor(fontColor); |
|---|
| 339 | text->setPosition(cursor); |
|---|
| 340 | text->setCharacterSize(fontCharacterSize); |
|---|
| 341 | |
|---|
| 342 | text->setFont(dirtydoz); |
|---|
| 343 | text->setText(dirtydoz!=0? |
|---|
| 344 | "text->setFont(\"fonts/dirtydoz.ttf\");": |
|---|
| 345 | "unable to load \"fonts/dirtydoz.ttf\""); |
|---|
| 346 | geode->addDrawable(text); |
|---|
| 347 | |
|---|
| 348 | cursor.x() = text->getBound().xMax() + spacing ; |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | { |
|---|
| 352 | osgText::Font* fudd = osgText::readFontFile("fonts/fudd.ttf"); |
|---|
| 353 | |
|---|
| 354 | osgText::Text* text = new osgText::Text; |
|---|
| 355 | text->setColor(fontColor); |
|---|
| 356 | text->setPosition(cursor); |
|---|
| 357 | text->setCharacterSize(fontCharacterSize); |
|---|
| 358 | |
|---|
| 359 | text->setFont(fudd); |
|---|
| 360 | text->setText(fudd!=0? |
|---|
| 361 | "text->setFont(\"fonts/fudd.ttf\");": |
|---|
| 362 | "unable to load \"fonts/fudd.ttf\""); |
|---|
| 363 | geode->addDrawable(text); |
|---|
| 364 | |
|---|
| 365 | cursor.x() = text->getBound().xMax() + spacing ; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | return rootNode; |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | osg::Group* create3DText(const osg::Vec3& center,float radius) |
|---|
| 376 | { |
|---|
| 377 | |
|---|
| 378 | osg::Geode* geode = new osg::Geode; |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | float characterSize=radius*0.2f; |
|---|
| 386 | |
|---|
| 387 | osg::Vec3 pos(center.x()-radius*.5f,center.y()-radius*.5f,center.z()-radius*.5f); |
|---|
| 388 | |
|---|
| 389 | osgText::Text* text1 = new osgText::Text; |
|---|
| 390 | text1->setFont("fonts/times.ttf"); |
|---|
| 391 | text1->setCharacterSize(characterSize); |
|---|
| 392 | text1->setPosition(pos); |
|---|
| 393 | text1->setAxisAlignment(osgText::Text::XY_PLANE); |
|---|
| 394 | text1->setText("XY_PLANE"); |
|---|
| 395 | geode->addDrawable(text1); |
|---|
| 396 | |
|---|
| 397 | osgText::Text* text2 = new osgText::Text; |
|---|
| 398 | text2->setFont("fonts/times.ttf"); |
|---|
| 399 | text2->setCharacterSize(characterSize); |
|---|
| 400 | text2->setPosition(pos); |
|---|
| 401 | text2->setAxisAlignment(osgText::Text::YZ_PLANE); |
|---|
| 402 | text2->setText("YZ_PLANE"); |
|---|
| 403 | geode->addDrawable(text2); |
|---|
| 404 | |
|---|
| 405 | osgText::Text* text3 = new osgText::Text; |
|---|
| 406 | text3->setFont("fonts/times.ttf"); |
|---|
| 407 | text3->setCharacterSize(characterSize); |
|---|
| 408 | text3->setPosition(pos); |
|---|
| 409 | text3->setAxisAlignment(osgText::Text::XZ_PLANE); |
|---|
| 410 | text3->setText("XZ_PLANE"); |
|---|
| 411 | geode->addDrawable(text3); |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | osgText::Text* text4 = new osgText::Text; |
|---|
| 415 | text4->setFont("fonts/times.ttf"); |
|---|
| 416 | text4->setCharacterSize(characterSize); |
|---|
| 417 | text4->setPosition(center); |
|---|
| 418 | text4->setAxisAlignment(osgText::Text::SCREEN); |
|---|
| 419 | text4->setText("SCREEN"); |
|---|
| 420 | geode->addDrawable(text4); |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | osg::StateSet *textStateSet = new osg::StateSet(); |
|---|
| 425 | textStateSet->setMode(GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED); |
|---|
| 426 | textStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED); |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | text4->setStateSet(textStateSet); |
|---|
| 431 | |
|---|
| 432 | osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(center,characterSize*0.2f)); |
|---|
| 433 | shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON); |
|---|
| 434 | geode->addDrawable(shape); |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | osg::Group* rootNode = new osg::Group; |
|---|
| 438 | rootNode->addChild(geode); |
|---|
| 439 | |
|---|
| 440 | return rootNode; |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | int main( int argc, char **argv ) |
|---|
| 444 | { |
|---|
| 445 | |
|---|
| 446 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of text."); |
|---|
| 450 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ..."); |
|---|
| 451 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | osgProducer::Viewer viewer(arguments); |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 465 | { |
|---|
| 466 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 467 | return 1; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | if (arguments.errors()) |
|---|
| 475 | { |
|---|
| 476 | arguments.writeErrorMessages(std::cout); |
|---|
| 477 | return 1; |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | osg::ref_ptr<osg::Node> rootNode = osgDB::readNodeFiles(arguments); |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | { |
|---|
| 486 | |
|---|
| 487 | osg::Vec3 center(0.0f,0.0f,0.0f); |
|---|
| 488 | float radius = 1.0f; |
|---|
| 489 | |
|---|
| 490 | if (rootNode.valid()) |
|---|
| 491 | { |
|---|
| 492 | |
|---|
| 493 | osgUtil::Optimizer optimizer; |
|---|
| 494 | optimizer.optimize(rootNode.get()); |
|---|
| 495 | |
|---|
| 496 | const osg::BoundingSphere& bs = rootNode->getBound(); |
|---|
| 497 | center = bs.center(); |
|---|
| 498 | radius = bs.radius(); |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | osg::Group* group = dynamic_cast<osg::Group*>(rootNode.get()); |
|---|
| 503 | if (!group) |
|---|
| 504 | { |
|---|
| 505 | group = new osg::Group; |
|---|
| 506 | |
|---|
| 507 | if (rootNode.valid()) group->addChild(rootNode.get()); |
|---|
| 508 | |
|---|
| 509 | rootNode = group; |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | { |
|---|
| 513 | |
|---|
| 514 | osg::CameraNode* camera = new osg::CameraNode; |
|---|
| 515 | camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); |
|---|
| 516 | camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024); |
|---|
| 517 | camera->setViewMatrix(osg::Matrix::identity()); |
|---|
| 518 | camera->setClearMask(GL_DEPTH_BUFFER_BIT); |
|---|
| 519 | camera->addChild(createHUDText()); |
|---|
| 520 | camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
|---|
| 521 | |
|---|
| 522 | group->addChild(camera); |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | group->addChild(create3DText(center,radius)); |
|---|
| 526 | |
|---|
| 527 | } |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | viewer.setSceneData(rootNode.get()); |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | viewer.realize(); |
|---|
| 535 | |
|---|
| 536 | #if 0 |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | for(unsigned int contextID = 0; |
|---|
| 545 | contextID<viewer.getDisplaySettings()->getMaxNumberOfGraphicsContexts(); |
|---|
| 546 | ++contextID) |
|---|
| 547 | { |
|---|
| 548 | osg::Texture::Extensions* textureExt = osg::Texture::getExtensions(contextID,false); |
|---|
| 549 | if (textureExt) textureExt->setGenerateMipMapSupported(false); |
|---|
| 550 | } |
|---|
| 551 | #endif |
|---|
| 552 | |
|---|
| 553 | while( !viewer.done() ) |
|---|
| 554 | { |
|---|
| 555 | |
|---|
| 556 | viewer.sync(); |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | viewer.update(); |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | viewer.frame(); |
|---|
| 564 | |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | viewer.sync(); |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | viewer.cleanup_frame(); |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | viewer.sync(); |
|---|
| 575 | |
|---|
| 576 | return 0; |
|---|
| 577 | } |
|---|