Re: [osg-users] Convert wxImage to osg:Image
Hi, I updated the code as follows. Code: wxImageHandler * tgaLoader = new wxJPEGHandler(); wxImage::AddHandler(tgaLoader); wxImage wximage; wximage.LoadFile(_T(/home/lahiru/Pictures/IMG_6064.JPG), wxBITMAP_TYPE_JPEG); wxMemoryOutputStream img_data(NULL,0); wximage.SaveFile(img_data,wxBITMAP_TYPE_JPEG); wxStreamBuffer* output_buffer = img_data.GetOutputStreamBuffer(); int length = output_buffer-GetDataLeft(); char buffer[length]; output_buffer-Read(buffer,length); std::stringstream ss; ss.write(buffer,length); osgDB::ReaderWriter* plugin = osgDB::Registry::instance()-getReaderWriterForExtension(JPEG); osgDB::ReaderWriter::ReadResult result = plugin-readImage(ss); osg::Image* klnFace = result.getImage(); However, for some reason, output_buffer-GetDataLeft(); returns 0. In the actual use case, I have to convert a wxBitmap into an osg::Image to apply it as a texture. I will try to save the wxImage as a file and load it into an osg::image for the time being. I really appreciate some help on this. Thank you! Best Regards, Lahiru -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32326#32326 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Convert wxImage to osg:Image
Hi all, After trying for few hours, I was able to convert the wxImage into an osg:Image, and apply it as a texture. I am posting the code below as it might help someone else as well. Code: wxBitmap bmp(wximage); wxNativePixelData data(bmp); wxNativePixelData::Iterator p(data); osg::Image* klnFace = new osg::Image(); int tex_width = data.GetWidth(); int tex_height = data.GetHeight(); klnFace-allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT); float* img_data = (float*)klnFace-data(); for (unsigned i = 0; (i tex_height); i++) { for (unsigned j = 0; (j tex_width); j++) { int ind = i*tex_width + j; img_data[ind*4] = p.Red()/255.0; img_data[ind*4+1] = p.Green()/255.0; img_data[ind*4+2] = p.Blue()/255.0; img_data[ind*4+3] = 1.0; p.MoveTo(data, j, tex_height-1-i); } } I used wxNativePixelData to access the raw image data. Thank you! Cheers, Lahiru -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32330#32330 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Convert wxImage to osg:Image
Hi, I modified the code to convert a wxImage to osg Image as follows. However, for some reason the resulting osg Image is not accurate. When I apply the resulted osg Image as a texture, it shows nothing but a gray colored QUAD. Am I doing something wrong in the code below? I really appreciate your help! Code: wxImageHandler * imgLoader = new wxJPEGHandler(); wxImage::AddHandler(imgLoader); wxImage wximage; wximage.LoadFile(_T(pictures/img.JPG), wxBITMAP_TYPE_JPEG); unsigned char* datachar = wximage.GetData(); std::stringstream ss; size_t len = strlen((const char*)datachar); ss.write((const char*)datachar, len); osgDB::ReaderWriter* plugin = osgDB::Registry::instance()-getReaderWriterForExtension(JPEG); /* tried both ss and ss.str() */ osgDB::ReaderWriter::ReadResult result = plugin-readImage(ss); // osgDB::ReaderWriter::ReadResult result = plugin-readImage(ss.str()); /* Texture */ osg::Texture2D* KLN89FaceTexture = new osg::Texture2D; KLN89FaceTexture-setDataVariance(osg::Object::DYNAMIC); osg::Image* klnFace = result.getImage(); Thank you! Best Regards, Lahiru[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32302#32302 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Convert wxImage to osg:Image
Hi Thibault, Thanks for the sample code! However, it is actually to covert an osg:Image to a wxImage right? Well... in my case, I need to convert a wxImage to an osg:Image. So that I can apply it as a texture on my GL_QUAD. Anyway, I will look more into your sample code... I might find a starting point! Many Thanks! Best Regards, Lahiru -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32239#32239 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Convert wxImage to osg:Image
Hi Thibault, Thanks a lot for the reply! I will check this out. Thanks again! Best Regards, Lahiru -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32135#32135 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Convert wxImage to osg:Image
Hi all, I am trying to create a wxImage (bitmap) in runtime using wxMemoryDC, draw a gradient rect on it and apply the bitmap as a texture on a QUAD. But I still couldn't find a proper way to convert the proceed wxImage (with gradient) into a osg:Image. I really appreciate if you can help me with this. Thank you! Best Regards, Lahiru -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32104#32104 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Convert wxImage to osg:Image
Hi Lahiru I use the attached code when converting from wxImage to osg::Image. The code is slightly modified to be independent from my project, but should be a good starting point. You might very well rethink how wxImageHandlers are created (i.e. if you call wxInitAllImageHandlers() at the beginning of your program, you are guaranteed that you don't need to install them on the fly, and can get rid of the initialization thingy with the mutex) Hope this helps Cheers Thibault On Mon, Sep 27, 2010 at 5:56 PM, Lahiru Lakmal llah...@gmail.com wrote: Hi all, I am trying to create a wxImage (bitmap) in runtime using wxMemoryDC, draw a gradient rect on it and apply the bitmap as a texture on a QUAD. But I still couldn't find a proper way to convert the proceed wxImage (with gradient) into a osg:Image. I really appreciate if you can help me with this. Thank you! Best Regards, Lahiru -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32104#32104 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ImageConverter.h Description: Binary data ImageConverter.cpp Description: Binary data ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org