Re: [osg-users] Float 32 bit texture map

2016-01-21 Thread Paul Leopard
The GL_RGB32F_ARB was a dangler ... I tried all sorts of options for that 
parameter. GL_LUMINANCE16F_ARB doesn't work


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=66082#66082





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Float 32 bit texture map

2016-01-20 Thread Paul Leopard
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 
#include 

#include 

// Imply namespaces

using namespace sgp_core;
using namespace std;

// Scene graph root and HUD
osg::ref_ptr SceneGraph = new osg::Group();

/**
* Create an OSG Image given a float data array
*/
osg::ref_ptr CreateImage( TScalarArray& rawImage )
{
osg::ref_ptr rImage = new osg::Image();
unsigned char* pData = reinterpret_cast( 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 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 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( ,const_cast( 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 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 rImage = CreateImage( rawImage );

// Create a quad and map the image as a texture on it
osg::ref_ptr rGeom = CreateTexturedQuad( rImage );

osg::ref_ptr 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


Re: [osg-users] Float 32 bit texture map

2016-01-20 Thread Wojciech Lewandowski
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 :

> 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 
> #include 
>
> #include 
>
> // Imply namespaces
>
> using namespace sgp_core;
> using namespace std;
>
> // Scene graph root and HUD
> osg::ref_ptr SceneGraph = new osg::Group();
>
> /**
> * Create an OSG Image given a float data array
> */
> osg::ref_ptr CreateImage( TScalarArray& rawImage )
> {
> osg::ref_ptr rImage = new osg::Image();
> unsigned char* pData = reinterpret_cast( 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 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 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( ,const_cast( 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 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 rImage = CreateImage( rawImage );
>
> // Create a quad and map the image as a texture on it
> osg::ref_ptr rGeom = CreateTexturedQuad( rImage );
>
> osg::ref_ptr 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
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org