Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenSceneGraph float Image
    primarykey
    data
    text
    <p>Using C++ and OSG I'm trying to upload a float texture to my shader, but somehow it does not seem to work. At the end I posted some part of my code. Main question is how to create an osg::Image object using data from a float array. In OpenGL the desired code would be</p> <pre><code>glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE32F_ARB, width, height, 0, GL_LUMINANCE, GL_FLOAT, data); </code></pre> <p>but in this case I have to use OSG.</p> <p>The code runs fine when using </p> <pre><code>Image* image = osgDB::readImageFile("someImage.jpg"); </code></pre> <p>instead of </p> <pre><code>image = new Image; </code></pre> <p>but I need to upload generated float data. It's also not possible to switch to unsigned char arrays as I need the GL_LUMINANCE32F_ARB data range in the shader code.</p> <p>I hope someone can help me here as Google couldn't help me with it (googled for eg: osg float image). So here's my code.</p> <pre><code>using namespace std; using namespace osg; //... float* data = new float[width*height]; fill_n(data, size, 1.0); // &lt;&lt; I actually do this for testing purposes Texture2D* texture = new Texture2D; Image* image = new Image; osg::State* state = new osg::State; Uniform* uniform = new Uniform(Uniform::SAMPLER_2D, "texUniform"); texture-&gt;setInternalFormat(GL_LUMINANCE32F_ARB); texture-&gt;setDataVariance(osg::Object::DYNAMIC); texture-&gt;setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture-&gt;setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texture-&gt;setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE); texture-&gt;setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE); if (data == NULL) cout &lt;&lt; "texdata null" &lt;&lt; endl; // &lt;&lt; this is not printed image-&gt;setImage(width, height, 1, GL_LUMINANCE32F_ARB, GL_LUMINANCE, GL_FLOAT, (unsigned char*)data, osg::Image::USE_NEW_DELETE); if (image-&gt;getDataPointer() == NULL) cout &lt;&lt; "datapointernull" &lt;&lt; endl; // &lt;&lt; this is printed if (!image-&gt;valid()) exit(1); // &lt;&lt; here the code exits (hard exit just for testing purposes) osgDB::writeImageFile(*image, "blah.png"); texture-&gt;setInternalFormat(GL_LUMINANCE32F_ARB); texture-&gt;setImage(image); camera-&gt;getOrCreateStateSet()-&gt;setTextureAttributeAndModes(4, texture); state-&gt;setActiveTextureUnit(4); texture-&gt;apply(*state); uniform-&gt;set(4); addProgrammUniform(uniform); </code></pre> <p>I found another way on the web, letting osg::Image create the data and fill it afterwards. But somehow this also does not work. I inserted this just after the new XYZ; lines.</p> <pre><code>image-&gt;setInternalTextureFormat(GL_LUMINANCE32F_ARB); image-&gt;allocateImage(width,height,1,GL_LUMINANCE,GL_FLOAT); if (image-&gt;data() == NULL) cout &lt;&lt; "null here?!" &lt;&lt; endl; // &lt;&lt; this is printed. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload