<div dir="ltr"><div>Hi Paul, </div><div><br></div><span style="font-size:12.8px">I guess you have one channel float data. </span>Certainly this is wrong:<div><br><div><span style="font-size:12.8px">rImage->setImage(</span><br style="font-size:12.8px"><span style="font-size:12.8px">rawImage.rows(),</span><span style="font-size:12.8px">rawImage.cols(),</span><span style="font-size:12.8px">arrayDepth,</span><br style="font-size:12.8px"><span style="font-size:12.8px">GL_LUMINANCE, </span><span style="font-size:12.8px">GL_RGB32F_ARB, </span><span style="font-size:12.8px">GL_FLOAT,</span><br style="font-size:12.8px"><span style="font-size:12.8px">pData, </span><span style="font-size:12.8px">osg::Image::NO_DELETE </span><span style="font-size:12.8px">);</span><br style="font-size:12.8px"></div></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">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. </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">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).</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Cheers,</span></div><div><span style="font-size:12.8px">Wojtek</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-20 21:34 GMT+01:00 Paul Leopard <span dir="ltr"><<a href="mailto:paul.leopard@gmail.com" target="_blank">paul.leopard@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
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.<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Paul<br>
<br>
<br>
<br>
Code:<br>
<br>
<br>
#include "sgp_core/TArrayAlgo.h"<br>
<br>
#include <osgViewer/Viewer><br>
#include <osg/Texture2D><br>
<br>
#include <string><br>
<br>
// Imply namespaces<br>
<br>
using namespace sgp_core;<br>
using namespace std;<br>
<br>
// Scene graph root and HUD<br>
osg::ref_ptr<osg::Group> SceneGraph = new osg::Group();<br>
<br>
/**<br>
* Create an OSG Image given a float data array<br>
*/<br>
osg::ref_ptr<osg::Image> CreateImage( TScalarArray<float>& rawImage )<br>
{<br>
osg::ref_ptr<osg::Image> rImage = new osg::Image();<br>
unsigned char* pData = reinterpret_cast<unsigned char*>( rawImage.c_data() );<br>
<br>
size_t arrayDepth = 1;<br>
<br>
rImage->setImage(<br>
rawImage.rows(),<br>
rawImage.cols(),<br>
arrayDepth,<br>
GL_LUMINANCE,<br>
GL_RGB32F_ARB,<br>
GL_FLOAT,<br>
pData,<br>
osg::Image::NO_DELETE<br>
);<br>
<br>
return rImage;<br>
<br>
} // end CreateImage() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
<br>
/**<br>
* Create a unit textured quad (Geometry) given it's position, size, and an image<br>
*/<br>
osg::ref_ptr<osg::Geometry> CreateTexturedQuad( osg::Image* pImage )<br>
{<br>
float xDim = pImage->t();<br>
float yDim = pImage->s();<br>
<br>
float32 xLrc = -xDim*0.5f;<br>
float32 yLrc = -yDim*0.5f;<br>
float32 zLrc = 0;<br>
osg::ref_ptr<osg::Geometry> rQuad =<br>
osg::createTexturedQuadGeometry(<br>
osg::Vec3( xLrc, yLrc, zLrc ),<br>
osg::Vec3( xDim, 0.0f, 0.0f ),<br>
osg::Vec3( 0.0f, yDim, 0.0f )<br>
);<br>
<br>
osg::Texture2D* pTex = new osg::Texture2D();<br>
pTex->setInternalFormat( GL_LUMINANCE32F_ARB );<br>
pTex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR );<br>
pTex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );<br>
pTex->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE );<br>
pTex->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE );<br>
pTex->setImage( pImage );<br>
<br>
osg::StateSet* pSS = rQuad->getOrCreateStateSet();<br>
pSS->setTextureAttributeAndModes( 0, pTex );<br>
<br>
return rQuad;<br>
} // CreateTexturedQuad() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
<br>
// ________________________________________________________________________________________________<br>
// Main program<br>
<br>
int main( int argc, const char** pArgv )<br>
{<br>
// Parse parameters<br>
osg::ArgumentParser arguments( &argc,const_cast<char**>( pArgv ) );<br>
string description("Scratch Program for Apache DFT Task");<br>
<br>
try<br>
{<br>
// Create image array and load image data from disk<br>
string imageFileName( "512x432_FLIR.float" );<br>
TScalarArray<float> rawImage;<br>
readFrom( rawImage, imageFileName );<br>
cout << "IMAGE : " << imageFileName << endl;<br>
cout << "SIZE : " << rawImage.rows() << "x" << rawImage.cols() << endl;<br>
<br>
// Create OSG image with the raw data<br>
osg::ref_ptr<osg::Image> rImage = CreateImage( rawImage );<br>
<br>
// Create a quad and map the image as a texture on it<br>
osg::ref_ptr<osg::Geometry> rGeom = CreateTexturedQuad( rImage );<br>
<br>
osg::ref_ptr<osg::Geode> rQuadGeode = new osg::Geode();<br>
rQuadGeode->addDrawable( rGeom );<br>
<br>
SceneGraph->addChild( rQuadGeode );<br>
}<br>
catch( Exception& e )<br>
{<br>
cerr << "ERROR: " << e.what() << endl;<br>
return 1;<br>
}<br>
<br>
// Setup viewer<br>
osgViewer::Viewer viewer(arguments);<br>
viewer.setSceneData( SceneGraph.get() );<br>
<br>
return viewer.run();<br>
}<br>
<br>
// EOF<br>
<br>
<br>
<br>
<br>
<br>
<br>
------------------------<br>
things are more like they are now than they have ever been before<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=66064#66064" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=66064#66064</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div>