OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Float 32 bit texture map


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
pleopard
User


Joined: 29 Jun 2011
Posts: 47
Location: Huntsville AL

PostPosted: Wed Jan 20, 2016 8:34 pm    Post subject:
Float 32 bit texture map
Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Wojtek
User


Joined: 02 Nov 2011
Posts: 89

PostPosted: Wed Jan 20, 2016 10:20 pm    Post subject:
Float 32 bit texture map
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
pleopard
User


Joined: 29 Jun 2011
Posts: 47
Location: Huntsville AL

PostPosted: Thu Jan 21, 2016 2:06 pm    Post subject:
Reply with quote

The GL_RGB32F_ARB was a dangler ... I tried all sorts of options for that parameter. GL_LUMINANCE and GL_LUMINANCE32F_ARB don't work

_________________
things are more like they are now than they have ever been before
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts EXTERNAL: Re: EXTERNAL: Re: Texture u... Rowley, Marlin R General 1 Thu Mar 14, 2019 5:56 pm View latest post
No new posts EXTERNAL: Re: Texture unit not turni... Rowley, Marlin R General 1 Thu Mar 14, 2019 2:06 pm View latest post
No new posts Texture unit not turning ON Rowley, Marlin R General 1 Wed Mar 13, 2019 6:37 pm View latest post
No new posts Use PNG as texture for terrain in osg... Rodrigo General [3rdparty] 12 Mon Jan 07, 2019 5:13 pm View latest post
No new posts DirectX Texture Stage Sets to OSG sbrkopac General 2 Tue Dec 04, 2018 8:47 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP