<div dir="ltr">Sandy,<div>Try this instead. You probably want normalized [0..1] data on the GPU, not [0..255] integers.</div><div><br></div><div> img->setImage(w, h, 1, GL_R8, GL_RED, GL_UNSIGNED_BYTE, data, osg::Image::USE_MALLOC_FREE); </div><div> <br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Glenn Waldron / osgEarth</div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 5, 2019 at 2:14 AM Steve Hardy <<a href="mailto:osgforum@tevs.eu">osgforum@tevs.eu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I am trying to render a monochrome camera image to a 2d texture, but without success unless I first convert it to BGR.<br>
<br>
After reading <br>
<a href="http://forum.openscenegraph.org/viewtopic.php?t=16236" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?t=16236</a><br>
I got closer, but still no cigar as the result is a boring uniform black. Here is some code:<br>
<br>
<br>
Code:<br>
void VSGeode::setImageParameters(bool linear)<br>
{<br>
if (getNumDrawables() < 1)<br>
throw OSGWrapException("No drawables");<br>
quad = dynamic_cast<osg::Geometry*>(getDrawable(0));<br>
if (!quad)<br>
throw OSGWrapException("No geometry");<br>
osg::StateSet* state = quad->getStateSet();<br>
if (!state)<br>
throw OSGWrapException("No state");<br>
tex = state->getTextureAttribute(0, osg::StateAttribute::TEXTURE)->asTexture();<br>
if (!tex)<br>
throw OSGWrapException("No texture");<br>
tex->setFilter(osg::Texture::MIN_FILTER,linear ? osg::Texture::LINEAR : osg::Texture::NEAREST);<br>
tex->setFilter(osg::Texture::MAG_FILTER,linear ? osg::Texture::LINEAR : osg::Texture::NEAREST); // NEAREST for pixelated look, LINEAR for smooth.<br>
img = tex->getImage(0);<br>
}<br>
<br>
void VSGeode::setImageBGR(int w, int h, unsigned char * data)<br>
{<br>
img->setImage(w, h, 1, 3, GL_BGR, GL_UNSIGNED_BYTE, data, osg::Image::USE_MALLOC_FREE);<br>
quad->dirtyDisplayList();<br>
}<br>
<br>
void VSGeode::setImageMono8(int w, int h, unsigned char * data)<br>
{<br>
img->setImage(w, h, 1, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, data, osg::Image::USE_MALLOC_FREE); // black<br>
quad->dirtyDisplayList();<br>
}<br>
<br>
<br>
<br>
SetImageBGR() works fine, but as mentioned, setImageMono8() does not.<br>
<br>
What happens is that the image comes in from a hi-res GigE camera, and it is a monochrome byte array. Because this is already fairly CPU intensive, I wish to avoid another copy to expand into a BGR array. But for the life of me I can't work out a magic combo of parameters that actually works. The data really is there, since I can fake it and just call setImageBGR() and it comes up with something, albeit like a Degas painting.<br>
<br>
So what is the most efficient way of getting a grey-scale image in a texture, from a 2D byte array in memory?<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Steve<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=76871#76871" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=76871#76871</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">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>