Show
Ignore:
Timestamp:
03/05/03 10:08:11 (12 years ago)
Author:
robert
Message:

Updates to Text for Sun Forte compilers.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgtext/osgtext.cpp

    r1648 r1649  
    1313 
    1414#include <osgUtil/Optimizer> 
     15 
    1516#include <osgDB/ReadFile> 
    16 #include <osgDB/Registry> 
     17#include <osgDB/WriteFile> 
     18 
    1719#include <osgProducer/Viewer> 
    1820 
     
    2022#include <osg/Projection> 
    2123#include <osg/MatrixTransform> 
     24#include <osg/ShapeDrawable> 
     25#include <osg/Sequence> 
    2226 
    2327#include <osgText/Font> 
     
    2832{ 
    2933 
     34    osg::Group* rootNode = new osg::Group; 
     35 
    3036    osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); 
    3137 
    3238    osg::Geode* geode  = new osg::Geode; 
     39    rootNode->addChild(geode); 
    3340 
    3441    float windowHeight = 1024.0f; 
     
    142149        text->setFont(font); 
    143150        text->setColor(characterSizeColor); 
    144         text->setFontSize(15,15); 
    145         text->setPosition(cursor); 
    146          
    147         // use text that 15 units high. 
    148         text->setCharacterSize(15); // tiny 
    149          
    150         text->setText("text->setCharacterSize(15.0f); // tiny"); 
    151         geode->addDrawable(text); 
    152     } 
    153      
    154     cursor.y() -= fontSizeCharacterSize; 
     151        text->setFontSize(20,20); 
     152        text->setPosition(cursor); 
     153         
     154        // use text that 20 units high. 
     155        text->setCharacterSize(20); // small 
     156         
     157        text->setText("text->setCharacterSize(15.0f); // small"); 
     158        geode->addDrawable(text); 
     159    } 
     160     
     161    cursor.y() -= 30.0f; 
    155162    { 
    156163        osgText::Text* text = new osgText::Text; 
     
    160167        text->setPosition(cursor); 
    161168         
    162         // use text that uses 10 by 10 texels as a target resolution for fonts. 
    163         text->setCharacterSize(30.0f); // tiny 
    164          
    165         text->setText("text->setCharacterSize(30.0f); // medium size"); 
    166         geode->addDrawable(text); 
    167     } 
    168      
    169     cursor.y() -= fontSizeCharacterSize; 
     169        // use text that 20 units high. 
     170        text->setCharacterSize(30.0f); // medium 
     171         
     172        text->setText("text->setCharacterSize(30.0f); // medium"); 
     173        geode->addDrawable(text); 
     174    } 
     175     
     176    cursor.y() -= 50.0f; 
    170177    { 
    171178        osgText::Text* text = new osgText::Text; 
     
    176183         
    177184        // use text that uses 10 by 10 texels as a target resolution for fonts. 
    178         text->setCharacterSize(40.0f); // tiny 
    179          
    180         text->setText("text->setCharacterSize(40.0f); // big, but can go much bigger :-)"); 
    181         geode->addDrawable(text); 
    182     } 
    183  
    184  
    185  
    186 if (0) 
    187 { 
    188     osgText::Text* text2 = new osgText::Text; 
    189     text2->setPosition(osg::Vec3(0.0f,50.0f,0.0f)); 
    190     text2->setCharacterSize(12.0f); 
    191     text2->setText("10 PRINT \"Hello World\""); 
    192     geode->addDrawable(text2); 
    193  
    194     osgText::Text* text3 = new osgText::Text; 
    195     text3->setFont(osgText::readFontFile("fonts/arial.ttf")); 
    196     text3->setPosition(osg::Vec3(100.0f,100.0f,0.0f)); 
    197     text3->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/arial.ttf"); 
    198     geode->addDrawable(text3); 
    199  
    200     osgText::Text* text4 = new osgText::Text; 
    201     text4->setFont(osgText::readFontFile("fonts/times.ttf")); 
    202     text4->setFontSize(128,128); 
    203     text4->setPosition(osg::Vec3(200.0f,200.0f,0.0f)); 
    204     text4->setLayout(osgText::Text::RIGHT_TO_LEFT); 
    205     text4->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); 
    206     text4->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/times.ttf"); 
    207     geode->addDrawable(text4); 
    208  
    209     osgText::Text* text5 = new osgText::Text; 
    210     text5->setFont(osgText::readFontFile("fonts/dirtydoz.ttf")); 
    211     text5->setPosition(osg::Vec3(300.0f,300.0f,0.0f)); 
    212     text5->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); 
    213     text5->setLayout(osgText::Text::VERTICAL); 
    214     text5->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); 
    215     text5->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/dirtydoz.ttf"); 
    216     geode->addDrawable(text5); 
    217 } 
    218  
    219 //     osgText::Text::TextString string; 
    220 //     for(int i=0;i<2048;++i) 
    221 //         string.push_back(i); 
    222 //  
    223 //     osgText::Text* text6 = new osgText::Text; 
    224 //     text6->setFont(osgText::readFontFile("/home/robert/Documents/GuopingSun/msmincho.ttc")); 
    225 //     text6->setFontSize(64,64); 
    226 //     text6->setText(string); 
    227 //     text6->setPosition(osg::Vec3(00.0f,400.0f,0.0f)); 
    228 //     geode->addDrawable(text6); 
    229  
    230      
    231  
    232  
    233     osg::Group* rootNode = new osg::Group; 
    234     rootNode->addChild(geode); 
    235  
     185        text->setCharacterSize(60.0f); // large 
     186         
     187        text->setText("text->setCharacterSize(60.0f); // large"); 
     188        geode->addDrawable(text); 
     189    } 
     190 
     191 
     192    cursor.x() = 500; 
     193    cursor.y() = margin; 
     194 
     195    osg::Sequence* sequence = new osg::Sequence; 
     196    
     197    sequence->setMode(osg::Sequence::START); 
     198    sequence->setInterval(osg::Sequence::LOOP, 0, -1); 
     199    sequence->setDuration(1.0f, -1); 
     200     
     201//    osg::Group* sequence = new osg::Group; 
     202//    rootNode->addChild(sequence); 
     203    
     204    { 
     205        for(unsigned int i=osgText::Text::LEFT_TOP;i<=osgText::Text::BASE_LINE;i++) 
     206        { 
     207            osg::Geode* alignmentGeode = new osg::Geode; 
     208            sequence->addChild(alignmentGeode); 
     209            sequence->setTime(i, 1.0f); 
     210 
     211            osgText::Text* text = new osgText::Text; 
     212            text->setFont(font); 
     213            text->setColor(characterSizeColor); 
     214            text->setPosition(cursor); 
     215            text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); 
     216             
     217            text->setAlignment((osgText::Text::AlignmentType)i); 
     218             
     219            text->setText("text->setAlignment();"); 
     220            alignmentGeode->addDrawable(text); 
     221 
     222            cursor.y() += 40.0f; 
     223 
     224 
     225        } 
     226         
     227    } 
     228    rootNode->addChild(sequence); 
     229             
    236230    return rootNode;     
    237231} 
     
    262256    geode->addDrawable(text3); 
    263257 
     258 
     259    osg::Vec3 screenCenter(300.0f,00.0f,00.0f); 
    264260    osgText::Text* text4 = new osgText::Text; 
    265261    text4->setFont("fonts/times.ttf"); 
    266262    text4->setAxisAlignment(osgText::Text::SCREEN); 
    267     text4->setPosition(osg::Vec3(00.0f,00.0f,00.0f)); 
     263    text4->setPosition(screenCenter); 
    268264    text4->setText("SCREEN"); 
    269265    geode->addDrawable(text4); 
     266 
     267    osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(screenCenter),2.0f)); 
     268    shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON); 
     269    geode->addDrawable(shape); 
     270 
    270271 
    271272    osg::Group* rootNode = new osg::Group; 
     
    362363    viewer.setSceneData(rootNode.get()); 
    363364     
     365    osgDB::writeNodeFile(*rootNode,"test.osg"); 
     366 
    364367    // create the windows and run the threads. 
    365368    viewer.realize(Producer::CameraGroup::ThreadPerCamera);