Hi,
I have a problem to load an image to a texture by using this code.
// create drawable geometry object
osg::Geometry* pGeo = new osg::Geometry;
// add 4 vertices creating a quad
osg::Vec3Array* pVerts = new osg::Vec3Array;
pVerts->push_back( osg::Vec3( 0, 0, 0 ) );
pVerts->push_back( osg::Vec3( 1, 0, 0 ) );
pVerts->push_back( osg::Vec3( 1, 0, 1 ) );
pVerts->push_back( osg::Vec3( 0, 0, 1 ) );
pGeo->setVertexArray( pVerts );
// create a primitive set
osg::DrawElementsUInt* pPrimitiveSet = new osg::DrawElementsUInt(
osg::PrimitiveSet::QUADS, 0 );
pPrimitiveSet->push_back( 3 );
pPrimitiveSet->push_back( 2 );
pPrimitiveSet->push_back( 1 );
pPrimitiveSet->push_back( 0 );
pGeo->addPrimitiveSet( pPrimitiveSet );
// create an arraw for texture coordinates
osg::Vec2Array* pTexCoords = new osg::Vec2Array( 4 );
(*pTexCoords)[0].set( 0.0f, 0.0f );
(*pTexCoords)[1].set( 1.0f, 0.0f );
(*pTexCoords)[2].set( 1.0f, 1.0f );
(*pTexCoords)[3].set( 0.0f, 1.0f );
pGeo->setTexCoordArray( 0, pTexCoords );
// create geometry node that will contain all our drawables
osg::Geode* pGeode = new osg::Geode;
osg::StateSet* pStateSet = pGeode->getOrCreateStateSet();
pStateSet->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
pGeode->addDrawable( pGeo );
// load and set texture attribute and mode
osg::Texture2D* pTex = new osg::Texture2D;
//osg::Image* pImage = osgDB::readImageFile ( "HUD_Maennchen.jpeg" );
osg::Image* pImage = osgDB::readImageFile(
"C:\Programme\ADTF\\2.1.1\lib\OpenSceneGraph-2.6.1\bin\HUD_Maennchen.jpeg" );
if(!pImage)
{
std::cout << "Error: Couldn't find texture!" << std::endl;
}
pTex->setImage( pImage );
pStateSet->setTextureAttributeAndModes( 0, pTex, osg::StateAttribute::ON
);
pGeo->setStateSet(pStateSet);
m_pTransform->addChild(pGeode);
GetRoot()->addChild(m_pTransform.get());
The image can't be found by readNodeFile. Where needs the image-file to be
stored? Must I compile the jpeg-plugin? How can I compile this plugin?
Thank you!
Cheers,
GI Jo
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=17828#17828
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org