| 37 | | extern int main_orig(int, char**); |
| 38 | | extern int main_test(int, char**); |
| 39 | | |
| 40 | | |
| 41 | | int main_size(int argc, char** argv) |
| 42 | | { |
| 43 | | osg::ArgumentParser arguments(&argc, argv); |
| 44 | | |
| 45 | | osgViewer::Viewer viewer(arguments); |
| 46 | | |
| 47 | | std::string fontFile("arial.ttf"); |
| 48 | | while(arguments.read("-f",fontFile)) {} |
| 49 | | |
| 50 | | osg::ref_ptr<osgText::Font> font = osgText::readFontFile(fontFile); |
| 51 | | if (!font) return 1; |
| 52 | | OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl; |
| 53 | | |
| 54 | | osg::Geode* geode = new osg::Geode; |
| 55 | | |
| 56 | | geode->addDrawable( osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(1.0f,0.0,0.0),osg::Vec3(0.0f,0.0,1.0), 0.0, 0.0, 1.0, 1.0) ); |
| 57 | | |
| 58 | | osgText::Text3D* text3d = new osgText::Text3D; |
| 59 | | text3d->setPosition(osg::Vec3(1.0f,0.0f,0.0f)); |
| 60 | | text3d->setFont(osgText::readFontFile("arial.ttf")); |
| 61 | | text3d->setCharacterSizeMode(osgText::Text3D::OBJECT_COORDS); |
| 62 | | text3d->setCharacterSize(1.0f); |
| 63 | | text3d->setCharacterDepth(0.1f); |
| 64 | | text3d->setAxisAlignment(osgText::Text3D::XZ_PLANE); |
| 65 | | text3d->setText("This is a size test"); |
| 66 | | |
| 67 | | geode->addDrawable(text3d); |
| 68 | | |
| 69 | | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
| 70 | | viewer.addEventHandler(new osgViewer::StatsHandler); |
| 71 | | |
| 72 | | viewer.setSceneData(geode); |
| 73 | | |
| 74 | | return viewer.run(); |
| 75 | | } |
| 76 | | |
| 77 | | |
| | 119 | group->addChild(geode); |
| | 120 | |
| | 121 | osg::Vec4 color(1.0f, 1.0f, 1.0f, 1.0f); |
| | 122 | while(arguments.read("--color",color.r(),color.g(),color.b(),color.a())) |
| | 123 | { |
| | 124 | OSG_NOTICE<<"--color "<<color<<std::endl; |
| | 125 | text3D->setColor(color); |
| | 126 | } |
| | 127 | |
| | 128 | std::string imageFilename; |
| | 129 | while(arguments.read("--image",imageFilename)) |
| | 130 | { |
| | 131 | OSG_NOTICE<<"--image "<<imageFilename<<std::endl; |
| | 132 | osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageFilename); |
| | 133 | if (image.valid()) |
| | 134 | { |
| | 135 | OSG_NOTICE<<" loaded image "<<imageFilename<<std::endl; |
| | 136 | osg::StateSet* stateset = text3D->getOrCreateStateSet(); |
| | 137 | stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image.get()), osg::StateAttribute::ON); |
| | 138 | } |
| | 139 | } |
| | 140 | |
| | 141 | while(arguments.read("--wall-color",color.r(),color.g(),color.b(),color.a())) |
| | 142 | { |
| | 143 | osg::StateSet* stateset = text3D->getOrCreateWallStateSet(); |
| | 144 | osg::Material* material = new osg::Material; |
| | 145 | material->setDiffuse(osg::Material::FRONT_AND_BACK, color); |
| | 146 | stateset->setAttribute(material); |
| | 147 | } |
| | 148 | |
| | 149 | while(arguments.read("--wall-image",imageFilename)) |
| | 150 | { |
| | 151 | osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageFilename); |
| | 152 | if (image.valid()) |
| | 153 | { |
| | 154 | osg::StateSet* stateset = text3D->getOrCreateWallStateSet(); |
| | 155 | stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image.get()), osg::StateAttribute::ON); |
| | 156 | } |
| | 157 | } |
| | 158 | |
| | 159 | while(arguments.read("--back-color",color.r(),color.g(),color.b(),color.a())) |
| | 160 | { |
| | 161 | osg::StateSet* stateset = text3D->getOrCreateBackStateSet(); |
| | 162 | osg::Material* material = new osg::Material; |
| | 163 | material->setDiffuse(osg::Material::FRONT_AND_BACK, color); |
| | 164 | stateset->setAttribute(material); |
| | 165 | } |
| | 166 | |
| | 167 | while(arguments.read("--back-image",imageFilename)) |
| | 168 | { |
| | 169 | osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageFilename); |
| | 170 | if (image.valid()) |
| | 171 | { |
| | 172 | osg::StateSet* stateset = text3D->getOrCreateBackStateSet(); |
| | 173 | stateset->setTextureAttributeAndModes(0, new osg::Texture2D(image.get()), osg::StateAttribute::ON); |
| | 174 | } |
| | 175 | } |
| | 176 | |
| | 177 | if (arguments.read("--size-quad")) |
| | 178 | { |
| | 179 | geode->addDrawable( osg::createTexturedQuadGeometry(osg::Vec3(0.0f,characterSize*thickness,0.0f),osg::Vec3(characterSize,0.0,0.0),osg::Vec3(0.0f,0.0,characterSize), 0.0, 0.0, 1.0, 1.0) ); |
| | 180 | } |
| 161 | | if (arguments.read("--size-quad")) |
| 162 | | { |
| 163 | | geode->addDrawable( osg::createTexturedQuadGeometry(osg::Vec3(0.0f,characterSize*thickness,0.0f),osg::Vec3(characterSize,0.0,0.0),osg::Vec3(0.0f,0.0,characterSize), 0.0, 0.0, 1.0, 1.0) ); |
| 164 | | } |
| 165 | | |
| 166 | | viewer.setSceneData(geode); |
| 167 | | #else |
| 168 | | osgText::TextNode* text = new osgText::TextNode; |
| 169 | | text->setFont(font.get()); |
| 170 | | text->setStyle(style.get()); |
| 171 | | text->setTextTechnique(new osgText::TextTechnique); |
| 172 | | text->setText(word); |
| 173 | | text->update(); |
| 174 | | viewer.setSceneData(text); |