[osg-users] Float 32 bit texture map

Wojciech Lewandowski w.p.lewandowski at gmail.com
Wed Jan 20 14:15:09 PST 2016


Hi Paul,

I guess you have one channel float data. Certainly this is wrong:

rImage->setImage(
rawImage.rows(),rawImage.cols(),arrayDepth,
GL_LUMINANCE, GL_RGB32F_ARB, GL_FLOAT,
pData, osg::Image::NO_DELETE );

At least GL_RGB32F_ARB should be swapped with GL_LUMINANCE. First you pass
internal format for GPU storage then you pass pixel format in which image
is stored in CPU mem.

If texture is one channel float luminance I suppose you should just use
with GL_LUMINANCE as internal format too (instead of GL_RGB32F). You later
force GL_LUMINANCE32F when texture is created anyway, so both should work
imho. But passing GL_RGB32F_ARB as pixel format probably causes that
texture is not created correctly (if created at all).

Cheers,
Wojtek

2016-01-20 21:34 GMT+01:00 Paul Leopard <paul.leopard at gmail.com>:

> 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 at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160120/99ebd084/attachment.htm>


More information about the osg-users mailing list