Hi, I've been trying to map a 32 bit float texture onto a quad for a while without success. Below is my code, can anyone tell me what I am doing wrong? This code opens a float32 image file, reads it into an array, creates an osg::Image with the array data, creates an osg::Texture2D with the image, then maps that texture onto a quad.
Thank you! Cheers, Paul Code: #include "sgp_core/TArrayAlgo.h" #include <osgViewer/Viewer> #include <osg/Texture2D> #include <string> // Imply namespaces using namespace sgp_core; using namespace std; // Scene graph root and HUD osg::ref_ptr<osg::Group> SceneGraph = new osg::Group(); /** * Create an OSG Image given a float data array */ osg::ref_ptr<osg::Image> CreateImage( TScalarArray<float>& rawImage ) { osg::ref_ptr<osg::Image> rImage = new osg::Image(); unsigned char* pData = reinterpret_cast<unsigned char*>( rawImage.c_data() ); size_t arrayDepth = 1; rImage->setImage( rawImage.rows(), rawImage.cols(), arrayDepth, GL_LUMINANCE, GL_RGB32F_ARB, GL_FLOAT, pData, osg::Image::NO_DELETE ); return rImage; } // end CreateImage() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** * Create a unit textured quad (Geometry) given it's position, size, and an image */ osg::ref_ptr<osg::Geometry> CreateTexturedQuad( osg::Image* pImage ) { float xDim = pImage->t(); float yDim = pImage->s(); float32 xLrc = -xDim*0.5f; float32 yLrc = -yDim*0.5f; float32 zLrc = 0; osg::ref_ptr<osg::Geometry> rQuad = osg::createTexturedQuadGeometry( osg::Vec3( xLrc, yLrc, zLrc ), osg::Vec3( xDim, 0.0f, 0.0f ), osg::Vec3( 0.0f, yDim, 0.0f ) ); osg::Texture2D* pTex = new osg::Texture2D(); pTex->setInternalFormat( GL_LUMINANCE32F_ARB ); pTex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR ); pTex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR ); pTex->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE ); pTex->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE ); pTex->setImage( pImage ); osg::StateSet* pSS = rQuad->getOrCreateStateSet(); pSS->setTextureAttributeAndModes( 0, pTex ); return rQuad; } // CreateTexturedQuad() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ________________________________________________________________________________________________ // Main program int main( int argc, const char** pArgv ) { // Parse parameters osg::ArgumentParser arguments( &argc,const_cast<char**>( pArgv ) ); string description("Scratch Program for Apache DFT Task"); try { // Create image array and load image data from disk string imageFileName( "512x432_FLIR.float" ); TScalarArray<float> rawImage; readFrom( rawImage, imageFileName ); cout << "IMAGE : " << imageFileName << endl; cout << "SIZE : " << rawImage.rows() << "x" << rawImage.cols() << endl; // Create OSG image with the raw data osg::ref_ptr<osg::Image> rImage = CreateImage( rawImage ); // Create a quad and map the image as a texture on it osg::ref_ptr<osg::Geometry> rGeom = CreateTexturedQuad( rImage ); osg::ref_ptr<osg::Geode> rQuadGeode = new osg::Geode(); rQuadGeode->addDrawable( rGeom ); SceneGraph->addChild( rQuadGeode ); } catch( Exception& e ) { cerr << "ERROR: " << e.what() << endl; return 1; } // Setup viewer osgViewer::Viewer viewer(arguments); viewer.setSceneData( SceneGraph.get() ); return viewer.run(); } // EOF ------------------------ things are more like they are now than they have ever been before ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66064#66064 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org