<div dir="ltr"><div><div><div>Hi Qingjie,<br><br></div>This is no longer about the OSG, it's about C++.  Your mistake is straight forward C++ issue of not matching the base classes parameters when overidding a method:  The Camera::DrawCallback base class is:<br><br><br>        /** Draw callback for custom operations.*/<br>        struct OSG_EXPORT DrawCallback : virtual public Object<br>        {<br>            DrawCallback() {}<br><br>            DrawCallback(const DrawCallback&,const CopyOp&) {}<br><br>            META_Object(osg, DrawCallback);<br><br>            /** Functor method called by rendering thread. Users will typically override this method to carry tasks such as screen capture.*/<br>            virtual void operator () (osg::RenderInfo& renderInfo) const;<br><br>            /** Functor method, provided for backwards compatibility, called by operator() (osg::RenderInfo& renderInfo) method.*/<br>            virtual void operator () (const osg::Camera& /*camera*/) const {}<br>        };<br><br></div>Please look carefully at your own code to see your mistake.<br><br></div>Robert.<br><div><div><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 September 2015 at 04:42, Qingjie Zhang <span dir="ltr"><<a href="mailto:305479421@qq.com" target="_blank">305479421@qq.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Robert,<br>
To get the handle of opengl texture, I attached a DrawCallback to the main camera, doing like these codes:<br>
struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback<br>
{<br>
        virtual void operator()(const osg::RenderInfo &renderInfo)<br>
        {<br>
                int contextID = renderInfo.getContextID();<br>
                GLuint frontTexHandle = m_frontTex->getTextureObject(contextID)->id();<br>
                GLuint backTexHandle = m_backTex->getTextureObject(contextID)->id();<br>
        }<br>
};<br>
camera->setPostDrawCallback(new MyCameraPostDrawCallback);<br>
<br>
But the function operator() int the callback does not run, I tried setPostDrawCallback() and setFinalDrawCallback(), they were the same.<br>
I was thinking that the DrawCallback would run every frame...<br>
Can you tell me when the callback runs?<br>
And, to get the handle,  is it right to attach DrawCallback to camera? If not, can you tell me the detailed method to get the handle?<br>
<br>
Thank you,<br>
<br>
Qingjie.<br>
<br>
<br>
robertosfield wrote:<br>
> Hi Qingjie,<br>
<span class="">> On 9 September 2015 at 09:27, Qingjie Zhang < ()> wrote:<br>
><br>
> > Do you mean the DrawCallback in the Camera class, which contains<br>
> > virtual void operator () (osg::RenderInfo& renderInfo) ? And here I can use the RenderInfo right?<br>
> ><br>
><br>
><br>
> Yes.  You can attach draw callbacks to Drawables, StateAtttribute and Camera's.<br>
><br>
><br>
>  <br>
><br>
> ><br>
> > As I know, the following code can get a contextID:<br>
> > camera->getGraphicsContext()->getState()->getContextID();<br>
> > Is this contextID same as the upper one?<br>
> ><br>
><br>
><br>
> If you only need the contexID then getting it from the graphics context is perfectly fine.  What route to take depends on when you need to do your queries.<br>
><br>
><br>
> I would add that the TextureObject for each context is only created by the draw thread for each context, so the TextureObject won't exist right away when you create your osg::Texture and assign them to the scene graph.<br>
><br>
><br>
><br>
> Robert.<br>
><br>
>  <br>
><br>
</span><span class="">>  ------------------<br>
> Post generated by Mail2Forum<br>
<br>
<br>
</span><span class="">------------------<br>
Read this topic online here:<br>
</span><a href="http://forum.openscenegraph.org/viewtopic.php?p=65083#65083" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=65083#65083</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">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>
</div></div></blockquote></div><br></div>