| | 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(64,64); |
| | 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 | // osgText::Text::TextString string; |
| | 71 | // for(int i=0;i<2048;++i) |
| | 72 | // string.push_back(i); |
| | 73 | // |
| | 74 | // osgText::Text* text6 = new osgText::Text; |
| | 75 | // text6->setFont(osgText::readFontFile("/home/robert/Documents/GuopingSun/msmincho.ttc")); |
| | 76 | // text6->setFontSize(64,64); |
| | 77 | // text6->setText(string); |
| | 78 | // text6->setPosition(osg::Vec3(00.0f,400.0f,0.0f)); |
| | 79 | // geode->addDrawable(text6); |
| | 80 | |
| | 81 | |
| | 82 | |
| | 83 | |
| 51 | | |
| 52 | | osgText::Text* text; |
| 53 | | osg::Geode* geode; |
| 54 | | osg::Material* textMaterial; |
| 55 | | osg::StateSet* textState; |
| 56 | | double xOffset=150; |
| 57 | | double yOffset=gFontSize+10; |
| 58 | | |
| 59 | | /////////////////////////////////////////////////////////////////////////// |
| 60 | | // setup the texts |
| 61 | | |
| 62 | | /////////////////////////////////////////////////////////////////////////// |
| 63 | | // BitmapFont |
| 64 | | osgText::BitmapFont* bitmapFont= new osgText::BitmapFont(ttfPath, |
| 65 | | gFontSize1); |
| 66 | | text= new osgText::Text(bitmapFont); |
| 67 | | gTextList.push_back(text); |
| 68 | | text->setText(std::string("2d ")+std::string(TEXT_BITMAP)); |
| 69 | | text->setPosition(osg::Vec3(xOffset,yOffset,0)); |
| 70 | | text->setDrawMode( osgText::Text::TEXT | |
| 71 | | osgText::Text::BOUNDINGBOX | |
| 72 | | osgText::Text::ALIGNMENT ); |
| 73 | | text->setAlignment(gAlignment); |
| 74 | | geode = new osg::Geode(); |
| 75 | | geode->setName("BitmapFont"); |
| 76 | | geode->addDrawable( text ); |
| 77 | | |
| 78 | | textMaterial = new osg::Material(); |
| 79 | | textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); |
| 80 | | textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); |
| 81 | | textState = new osg::StateSet(); |
| 82 | | textState->setAttribute(textMaterial ); |
| 83 | | geode->setStateSet( textState ); |
| 84 | | |
| 86 | | |
| 87 | | xOffset+=90; |
| 88 | | yOffset+=120; |
| 89 | | |
| 90 | | /////////////////////////////////////////////////////////////////////////// |
| 91 | | // PixmapFont |
| 92 | | osgText::PixmapFont* pixmapFont= new osgText::PixmapFont(ttfPath, |
| 93 | | gFontSize1); |
| 94 | | text= new osgText::Text(pixmapFont); |
| 95 | | gTextList.push_back(text); |
| 96 | | text->setText(std::string("2d ")+std::string(TEXT_PIXMAP)); |
| 97 | | text->setPosition(osg::Vec3(xOffset,yOffset,0)); |
| 98 | | text->setDrawMode( osgText::Text::TEXT | |
| 99 | | osgText::Text::BOUNDINGBOX | |
| 100 | | osgText::Text::ALIGNMENT ); |
| 101 | | text->setAlignment(gAlignment); |
| 102 | | geode = new osg::Geode(); |
| 103 | | geode->setName("PixmapFont"); |
| 104 | | geode->addDrawable( text ); |
| 105 | | |
| 106 | | textMaterial = new osg::Material(); |
| 107 | | textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); |
| 108 | | textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK,TEXT_COL_2D); |
| 109 | | // to get antiaA pixmapFonts we have to draw them with blending |
| 110 | | osg::BlendFunc *transp= new osg::BlendFunc(); |
| 111 | | transp->setFunction(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
| 112 | | |
| 113 | | |
| 114 | | |
| 115 | | |
| 116 | | textState = new osg::StateSet(); |
| 117 | | textState->setAttribute(textMaterial ); |
| 118 | | textState->setAttribute(transp); |
| 119 | | textState->setMode(GL_BLEND,osg::StateAttribute::ON); |
| 120 | | textState->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
| 121 | | |
| 122 | | |
| 123 | | geode->setStateSet( textState ); |
| 124 | | |
| 125 | | rootNode->addChild(geode); |
| 126 | | |
| 127 | | xOffset+=90; |
| 128 | | yOffset+=120; |
| 129 | | |
| 130 | | /////////////////////////////////////////////////////////////////////////// |
| 131 | | // TextureFont |
| 132 | | osgText::TextureFont* textureFont= new osgText::TextureFont(ttfPath1, |
| 133 | | gFontSize1); |
| 134 | | text= new osgText::Text(textureFont); |
| 135 | | gTextList.push_back(text); |
| 136 | | text->setText(std::string("2d ")+std::string(TEXT_TEXTURE)); |
| 137 | | text->setPosition(osg::Vec3(xOffset,yOffset,0)); |
| 138 | | text->setDrawMode( osgText::Text::TEXT | |
| 139 | | osgText::Text::BOUNDINGBOX | |
| 140 | | osgText::Text::ALIGNMENT ); |
| 141 | | text->setAlignment(gAlignment); |
| 142 | | geode = new osg::Geode(); |
| 143 | | geode->setName("TextureFont"); |
| 144 | | geode->addDrawable( text ); |
| 145 | | |
| 146 | | textMaterial = new osg::Material(); |
| 147 | | textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); |
| 148 | | textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); |
| 149 | | // to get antiaA pixmapFonts we have to draw them with blending |
| 150 | | transp= new osg::BlendFunc(); |
| 151 | | transp->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 152 | | |
| 153 | | textState = new osg::StateSet(); |
| 154 | | textState->setAttribute(textMaterial ); |
| 155 | | textState->setAttribute(transp); |
| 156 | | |
| 157 | | textState->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::ON); |
| 158 | | textState->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
| 159 | | geode->setStateSet( textState ); |
| 160 | | |
| 161 | | rootNode->addChild(geode); |
| 162 | | |
| 163 | | xOffset+=90; |
| 164 | | yOffset+=120; |
| 165 | | |
| 166 | | /////////////////////////////////////////////////////////////////////////// |
| 167 | | // PolygonFont |
| 168 | | osgText::PolygonFont* polygonFont= new osgText::PolygonFont(ttfPath, |
| 169 | | gFontSize1, |
| 170 | | 3); |
| 171 | | text= new osgText::Text(polygonFont); |
| 172 | | gTextList.push_back(text); |
| 173 | | text->setText(std::string("2d ")+std::string("TEXT_POLYGON")); |
| 174 | | text->setPosition(osg::Vec3(xOffset,yOffset,0)); |
| 175 | | text->setDrawMode( osgText::Text::TEXT | |
| 176 | | osgText::Text::BOUNDINGBOX | |
| 177 | | osgText::Text::ALIGNMENT ); |
| 178 | | text->setAlignment(gAlignment); |
| 179 | | geode = new osg::Geode(); |
| 180 | | geode->setName("PolygonFont"); |
| 181 | | geode->addDrawable( text ); |
| 182 | | |
| 183 | | textMaterial = new osg::Material(); |
| 184 | | textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); |
| 185 | | textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); |
| 186 | | textState = new osg::StateSet(); |
| 187 | | textState->setAttribute(textMaterial ); |
| 188 | | geode->setStateSet( textState ); |
| 189 | | |
| 190 | | rootNode->addChild(geode); |
| 191 | | |
| 192 | | xOffset+=90; |
| 193 | | yOffset+=120; |
| 194 | | |
| 195 | | /////////////////////////////////////////////////////////////////////////// |
| 196 | | // OutlineFont |
| 197 | | osgText::OutlineFont* outlineFont= new osgText::OutlineFont(ttfPath, |
| 198 | | gFontSize1, |
| 199 | | 3); |
| 200 | | |
| 201 | | text= new osgText::Text(outlineFont); |
| 202 | | gTextList.push_back(text); |
| 203 | | text->setText(std::string("2d ")+std::string(TEXT_OUTLINE)); |
| 204 | | text->setPosition(osg::Vec3(xOffset,yOffset,0)); |
| 205 | | text->setDrawMode( osgText::Text::TEXT | |
| 206 | | osgText::Text::BOUNDINGBOX | |
| 207 | | osgText::Text::ALIGNMENT ); |
| 208 | | text->setAlignment(gAlignment); |
| 209 | | geode = new osg::Geode(); |
| 210 | | geode->setName("OutlineFont"); |
| 211 | | geode->addDrawable( text ); |
| 212 | | |
| 213 | | textMaterial = new osg::Material(); |
| 214 | | textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); |
| 215 | | textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); |
| 216 | | textState = new osg::StateSet(); |
| 217 | | textState->setAttribute(textMaterial ); |
| 218 | | geode->setStateSet( textState ); |
| 219 | | |
| 220 | | rootNode->addChild(geode); |
| 221 | | |
| 222 | | |
| 223 | | // now add a depth attribute to the scene to force it to draw on top. |
| 224 | | osg::Depth* depth = new osg::Depth; |
| 225 | | depth->setRange(0.0,0.0); |
| 226 | | |
| 227 | | osg::StateSet* rootState = new osg::StateSet(); |
| 228 | | rootState->setAttribute(depth); |
| 229 | | rootState->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
| 230 | | |
| 231 | | rootNode->setStateSet(rootState); |
| | 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 | } |
| 299 | | // create the hud. |
| 300 | | osg::Projection* projection = new osg::Projection; |
| 301 | | projection->setMatrix(osg::Matrix::ortho2D(0,1024,0,768)); |
| 302 | | |
| 303 | | osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; |
| 304 | | modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); |
| 305 | | modelview_abs->setMatrix(osg::Matrix::identity()); |
| 306 | | |
| 307 | | modelview_abs->addChild(createText()); |
| 308 | | |
| 309 | | projection->addChild(modelview_abs); |
| 310 | | |
| 311 | | group->addChild(projection); |
| | 190 | { |
| | 191 | // create the hud. |
| | 192 | osg::Projection* projection = new osg::Projection; |
| | 193 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
| | 194 | |
| | 195 | osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; |
| | 196 | modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); |
| | 197 | modelview_abs->setMatrix(osg::Matrix::identity()); |
| | 198 | |
| | 199 | modelview_abs->addChild(createHUDText()); |
| | 200 | |
| | 201 | projection->addChild(modelview_abs); |
| | 202 | |
| | 203 | group->addChild(projection); |
| | 204 | } |
| | 205 | |
| | 206 | osg::MatrixTransform* scale = new osg::MatrixTransform; |
| | 207 | scale->setMatrix(osg::Matrix::scale(1.0f,1.0f,1.0f)); |
| | 208 | scale->addChild(create3DText()); |
| | 209 | group->addChild(scale); |