<div dir="ltr">Werner,<div>I have never switched render targets at runtime before, but I have switched attachments and needed to call camera->dirtyAttachmentMap() after calling attach() or detach(). Maybe that will work.</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Glenn Waldron</div></div></div></div>
<br><div class="gmail_quote">On Thu, Mar 9, 2017 at 9:10 AM, Werner Modenbach <span dir="ltr"><<a href="mailto:Werner.Modenbach@texion.eu" target="_blank">Werner.Modenbach@texion.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hi all.<br>
<br>
Is it possible to redirect the main camera of a view temporarily to
a FBO?<br>
It is my intention to get a snapshot of the scene with a modified
projection matrix.<br>
I think about something like that:<br>
<br>
<span style="color:#800080">osg</span>::<span style="color:#800080">ref_ptr</span><<span style="color:#800080">osg</span>::<span style="color:#800080">Camera</span>> camera =
view->getCamera();<br>
osg::Camera::<wbr>RenderTargetImplementation rti =
camera-><wbr>getRenderTargetImplementation(<wbr>);<br>
<span style="color:#c0c0c0"> </span><span style="color:#800080">osg</span>::<span style="color:#800080">Matrixd</span><span style="color:#c0c0c0"> </span>projectionMatrix<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#800000">view</span>->getCamera()-><wbr>getProjectionMatrix();
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"></pre>
camera-><wbr>setRenderTargetImplementation(<span style="color:#800080"><wbr>osg</span>::<span style="color:#800080">Camera</span>::<span style="color:#800080">FRAME_BUFFER_<wbr>OBJECT</span>);
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"></pre>
<span style="color:#c0c0c0"> </span><span style="color:#800080">osg</span>::<span style="color:#800080">ref_ptr</span><<span style="color:#800080">osg</span>::<span style="color:#800080">Image>
</span>fbImage<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#808000">new</span><span style="color:#c0c0c0"> </span><span style="color:#800080">osg</span>::<span style="color:#800080">Image</span>;
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">fbImage-><span style="font-style:italic;color:#000000">allocateImage</span>(width,<wbr>height,<span style="color:#000080">1</span>,<span style="color:#000080">GL_RGBA</span>,<span style="color:#000080">GL_UNSIGNED_<wbr>BYTE</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">1</span>);
</pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">camera->attach(<span style="color:#c0c0c0"> </span><span style="color:#800080">osg</span>::<span style="color:#800080">Camera</span>::<span style="color:#800080">COLOR_BUFFER</span>,<span style="color:#c0c0c0"> </span>fbImage.get(),<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">camera->setProjectionMatrix(<span style="color:#c0c0c0"> </span>projectionMatrix<span style="color:#c0c0c0"> </span>*<span style="color:#c0c0c0"> </span>offsetMatrix<span style="color:#c0c0c0"> </span>);
</pre>
<span style="color:#c0c0c0"> </span><span style="color:#800000">view</span>-><span style="font-style:italic;color:#000000">frame</span>();<br>
<br>
camera-><wbr>setRenderTargetImplementation(<span style="color:#800080"><wbr>rti</span>);<br>
camera->detach(<span style="color:#800080"> osg</span>::<span style="color:#800080">Camera</span>::<span style="color:#800080">COLOR_BUFFER</span>
);<br>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">camera->setProjectionMatrix(<span style="color:#c0c0c0"> </span>projectionMatrix<span style="color:#c0c0c0"> </span>);
</pre>
I tried it but my screen gets updated on the frame() call with the
modified projection matrix <br>
and the image stays black.<br>
<br>
Thanks for any hints.<span class="HOEnZb"><font color="#888888"><br>
<br>
- Werner -<br>
<div class="m_-3766310451060513262moz-signature"><br>
</div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
<br></blockquote></div><br></div>