[osg-users] Render to Texture

Robert Osfield robert.osfield at gmail.com
Mon Jul 21 04:10:44 PDT 2008


Hi Gareth,

There isn't anyway that we can say exactly what is up give the code
extract you have given - its the rest of the setup code and usage code
in your app that would tell us this.  Render To Texture support in OSG
2.x is far more mature and flexible than that on the OSG 1.x series,
and copy to image still works, as does adding your own OpenGL code.

My guess is that your code is probably relying upon undocumented
behaviour of the OSG 1.x when running single threaded, single context
- the behaviour being that the main frame loop has the graphics
context current so you can do OpenGL calls directly in it.

With OSG 2.x the osgViewer::Viewer is more multi-threaded than the
osgProducer::Viewer, even when running single with a context it'll be
multi-threaded on multi-core machines, with the graphics being done in
its own dedicated thread.  This is where you may well be coming
unstuck, you reliance on the main loop having the graphics context
current just doesn't work, and you most likely are just lucky it's not
crashing.

Solutions would be, to run the viewer single threaded, or just fix
your code so that the OpenGL ops are do in a camera post draw
callback.

Robert.

On Mon, Jul 21, 2008 at 10:41 AM, Roberts, Gareth
<Gareth.Roberts at mbda-systems.com> wrote:
> I used this code...
>
>   const int TEX_WIDTH = 512;
>   const int TEX_HEIGHT = 512;
>   osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D());
>   texture->setTextureSize (TEX_WIDTH, TEX_HEIGHT);
>   osg::Image* image = new osg::Image;
>   image->allocateImage(TEX_WIDTH, TEX_HEIGHT, 1, GL_RGBA,
> GL_UNSIGNED_BYTE);
>   texture->setImage(0, image);
>   osg::ref_ptr<osg::Image> zim = texture->getImage();
>   unsigned char* imptr = zim->data();
>
> With OSG 1.0 and was able to readback the image via the pointer imptr.
> The same code fails with OSG 2.0 and 2.4
>
> I have also used an openGL read with osg 1.0, this also fails with osg 2.
>
>
> -----Original Message-----
> From: paul1492 at yahoo.com [mailto:paul1492 at yahoo.com]
> Sent: 16 July 2008 14:48
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] Render to Texture
>
>               *** WARNING ***
>
> This mail has originated outside your organization, either from an external
> partner or the Global Internet.
>     Keep this in mind if you answer this message.
>
> I'm not sure what is going on but I switched to dumping a "png" file and
> still see the banding (see attached)...
> Are you sure the PNG plugin can handle dumping an RGBA GL_FLOAT image?
> All I did was add a osgDB::writeImageFile(*_image,
> "somefilename.png") at the end of the GL_FLOAT/RGBA if statement in
>  MyCameraPostDrawCallback::operator() in the osgprerender.cpp example and
> then ran this example using "--image cow.osg".
>
> Paul P.
>
>
> ----- Original Message ----
> From: J.P. Delport <jpdelport at csir.co.za>
> To: OpenSceneGraph Users <osg-users at lists.openscenegraph.org>
> Sent: Tuesday, July 15, 2008 8:11:14 AM
> Subject: Re: [osg-users] Render to Texture
>
> Hi,
>
> make sure the image writer can handle your image format. Bands usually mean
> an alignment error in the data the writer expects. E.g. expects binary input
> data to be RGB, but the data is RGBA.
>
> .jpg does not support alpha I think.
>
> Try .png
>
> jp
>
> paul1492 at yahoo.com wrote:
>> I'm attempting to render to a texture and then dump the rendered texture
> to a file (every frame), but I'm having trouble.
>> I've attempted to use the osgprerender example (using the --image
>>option), and replaced the MyCameraPostDrawCallback::operator() to have
>>a
>>    osgDB::writeImageFile(*_image, fileName);  where fileName is a
>>".tif" file (or .jpg file).
>> When I look at the .tif file using the Linux "display" program, I get some
> funny banded image. What am I doing wrong?
>> Is there a more efficient way to get access to the rendered image? Must I
> allocate an "image" array to the texture to access the image?
>> Paul P.
>>
>>
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
>> org
>
> --
> This message is subject to the CSIR's copyright terms and conditions, e-mail
> legal notice, and implemented Open Document Format (ODF) standard.
> The full disclaimer details can be found at
> http://www.csir.co.za/disclaimer.html.
>
> This message has been scanned for viruses and dangerous content by
> MailScanner, and is believed to be clean.  MailScanner thanks Transtec
> Computers for their support.
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
>
> ********************************************************************
> This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person.
>
> MBDA UK Limited, a company registered in England and Wales, registration number 3144919 whose registered office is at Six Hills Way, Stevenage, Hertfordshire, SG1 2DA, England.
> ********************************************************************
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list