Insert an image before a text

30 views
Skip to first unread message

marco....@elmansrl.eu

unread,
Dec 16, 2020, 2:30:45 AM12/16/20
to OpenSceneGraph Users
Hi Guys,

I need to create a label, in which to insert a text and an image from .png file.

The label with text ONLY has already been created, as below:

osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setText("Tryyyy text");
osg::ref_ptr<osg::Geode> textBoat = new osg::Geode;
textBoat->addDrawable(text);

Then, since I have few experience with osg::Image and osg::Text, I tried as solution, to implement a texture inside a StateSet to insert into a Geode,

osg::Texture2D* texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
osg::Image* Image=osgDB::readImageFile(std::string(url+"/Images/flags_png/abw.png"));
texture->setImage(image);
osg::StateSet* stateTex = new osg::StateSet();
stateTex->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
textBoat->setStateSet(stateTex);

Then, the text is correctly created, but I don't have the image.....

Can anyone show me the right way to go?

Thanks

Robert Osfield

unread,
Dec 16, 2020, 3:52:11 AM12/16/20
to OpenSceneGraph Users
Images won't render on their own you need to create some geometry to render the texture on.  You don't mentioned anything about creating geometry but it could easily by that you've just not mentioned it.

There is a convenience function for created a quad geometry appropriate for rendering textures on, see:

   osg::createTexturedQuadGeometry()

The OSG examples that use this are:
:~/Dev/OpenSceneGraph/examples$ grep -r "osg::createTexturedQuadGeometry" .
./osgmovie/osgmovie.cpp:        osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos,
./osgmovie/osgmovie.cpp:        osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos,
./osgatomiccounter/osgatomiccounter.cpp:        osg::Geometry * quad = osg::createTexturedQuadGeometry(osg::Vec3f(-2.0f, 0.0f, -2.0f),
./osgcomputeshaders/osgcomputeshaders.cpp:    osg::Geometry* geom = osg::createTexturedQuadGeometry(
./osgtext3D/osgtext3D.cpp:            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) );
./osgcatch/osgcatch.cpp:        osg::Geometry* geometry = osg::createTexturedQuadGeometry(pos,width,height);
./osgcatch/osgcatch.cpp:            osg::Geometry* geometry = osg::createTexturedQuadGeometry(pos,width,height);
./osgcatch/osgcatch.cpp:            osg::Geometry* geometry = osg::createTexturedQuadGeometry(pos,width,height);
./osgcatch/osgcatch.cpp:            osg::Geometry* geometry = osg::createTexturedQuadGeometry(pos,width,height);
./osgcatch/osgcatch.cpp:            osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
./osgcatch/osgcatch.cpp:            osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
./osgcatch/osgcatch.cpp:            osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
./osgcatch/osgcatch.cpp:                    osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
./osgSSBO/osgSSBO.cpp:        geom = osg::createTexturedQuadGeometry(placement, osg::Vec3(1.0f*scale, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, ratio*1.0f*scale));
./osgSSBO/osgSSBO.cpp:        geom = osg::createTexturedQuadGeometry(placement, osg::Vec3(ratio*1.0f*scale, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f*scale));
./osgsampler/osgSampler.cpp:        ((osg::Geode*)geode.get())->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0,0,0),osg::Vec3(1,0,0),osg::Vec3(0,0,1) ));
./osgshadow/osgshadow.cpp:        geode->addDrawable( osg::createTexturedQuadGeometry( centerBase-widthVec*1.5f-depthVec*1.5f,
./osgimagesequence/osgimagesequence.cpp:    geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f)));
./osgblenddrawbuffers/osgblenddrawbuffers.cpp:        osg::Geometry* geom = osg::createTexturedQuadGeometry(
./osgmultiplemovies/osgmultiplemovies.cpp:            geo = osg::createTexturedQuadGeometry(p, osg::Vec3(w, 0, 0), osg::Vec3(0, 0, desired_height), 0, tex_t, tex_s, 0);
./osgmultiplemovies/osgmultiplemovies.cpp:            geo = osg::createTexturedQuadGeometry(p, osg::Vec3(w, 0, 0), osg::Vec3(0, 0, desired_height), 0, 0, tex_s, tex_t);
./osgdeferred/osgdeferred.cpp:    osg::Geometry* geom = osg::createTexturedQuadGeometry(




Reply all
Reply to author
Forward
0 new messages