Hi,

i am some kind of newbie in OSG and i am building a 3D game with it 
i am using the osgTimer to get the time and each 1 second i increment a counter 
then i convert this int -the counter- to a string 
and set the text->setText() method to that string 

the problem is i do have a problem with that ... it always give me a failed 
debug assertion 

the weired thing is that it gives this error in different places each time 
some times after the 30 second and sometimes after 5 seconds and some times 
after 120 seconds

i am using VS 2008 and i made a testing project out of my real project to 
isolate the function for testing issues 

here is my code 
and hope that any one can tell me what is the problem with it 

Code:
#include <osg/PositionAttitudeTransform>
#include <osg/Group>
#include <osg/Node>
#include <osgDB/ReadFile> 
#include <osgViewer/Viewer>

#include <osgText/Font>
#include <osgText/Text>
#include <osg/MatrixTransform>
#include <osg/Geode>
#include <osg/Projection>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
#include <osgGA/TrackballManipulator>


osgText::Text* textOneOne =NULL;

void drawText(char* text , osg::Group* root , osg::Vec3 place , osg::Vec4 color 
,int  size)
{
        osg::Geode* HUDGeode = new osg::Geode() ;
        osgText::Text* textOne = new osgText::Text();
        textOneOne = textOne ;
        osg::Projection* HUDProjectionMatrix = new osg::Projection;

        HUDProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,1366,0,768));
        osg::MatrixTransform* HUDModelViewMatrix = new osg::MatrixTransform;
        HUDModelViewMatrix->setMatrix(osg::Matrix::identity());
        HUDModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);

        root->addChild(HUDProjectionMatrix);
    HUDProjectionMatrix->addChild(HUDModelViewMatrix);

        HUDModelViewMatrix->addChild( HUDGeode );

   // Create and set up a state set using the texture from above:
   osg::StateSet* HUDStateSet = new osg::StateSet();
   HUDGeode->setStateSet(HUDStateSet);

   // For this state set, turn blending on (so alpha texture looks right)
   HUDStateSet->setMode(GL_BLEND,osg::StateAttribute::ON);

   // Disable depth testing so geometry is draw regardless of depth values
   // of geometry already draw.
   HUDStateSet->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
   HUDStateSet->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

   // Add the text (Text class is derived from drawable) to the geode:
   HUDGeode->addDrawable( textOne );

   // Set up the parameters for the text we'll add to the HUD:
   textOne->setCharacterSize(size);
   textOne->setFont("C:/WINDOWS/Fonts/impact.ttf");
   textOne->setText(text);
   textOne->setAxisAlignment(osgText::Text::SCREEN);
   textOne->setPosition( place );
   textOne->setColor( color );
   textOne->setLayout(osgText::Text::LEFT_TO_RIGHT) ;
   textOne->setFontResolution(100 , 100 ) ;
}
           char buffer [33];
int main()
{
        osg::Group* root = NULL ; 
        osgViewer::Viewer viewer ; 
        int size = 40;
        
        osg::Vec3 place(400,400,0);
        osg::Vec4 color(1.0f, 1.0f, 0.0f, 1.0) ;

        root = new osg::Group() ;

        
        drawText("testing " , root , place , color , size);
        viewer.setSceneData( root );
        viewer.setCameraManipulator(new osgGA::TrackballManipulator());

   viewer.realize();

   int i = 0 ;
   while( !viewer.done() )
   {
           i++ ;
           itoa (i,buffer,10);
           textOneOne->setText(buffer) ;
           viewer.frame();
   }
}




Thank you!

Cheers,
Islam

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35392#35392




Attachments: 
http://forum.openscenegraph.org//files/again_testing_113.cpp


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to