[osg-users] frame control and callback

Wojciech Lewandowski lewandowski at ai.com.pl
Tue Sep 30 07:27:14 PDT 2008


Hi Matthieu,

Try using --SingleThreded mode with your viewer. I once tried to do similar thing. Although in my case I was dumping color buffer.But very often I was  reading wrong portion of the whole range. It turned out that default multithreading of OSG was runnig two frames concurently and one snapshot was overrriding the other. 

Attached you will find an code excerpt from my app. It was used to dump pseudo aerial photographs for some airport objects. We used these images later for paged terrain.

Code may not compile because I removed few specific parts. But main rendering loops are untouched you may use them as template for your code. 

Cheers,
Wojtek

. 
----- Original Message ----- 
  From: Matthieu DIRRENBERGER 
  To: osg-users at lists.openscenegraph.org 
  Sent: Tuesday, September 30, 2008 3:57 PM
  Subject: [osg-users] frame control and callback


  Hello OSG users,

   

  I am a new on OSG and I have some difficulties to finish an application.

  I am trying to do an application which computes pre-calculated height-maps from a scene.

  Simply, I make a "draughtboard" from the scene; and a camera takes shots from Z-buffer for each square looking downward.

  I have done a callback function to get z-buffer and convert it to my convenience, but I can't control the execution of that callback function.

   

  struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback

  {

        MyCameraPostDrawCallback(osg::Image* image, osg::Image* cimage, osg::Texture2D* t): _image(image), _cimage(cimage), _cTex(t)

      {

      }

      virtual void operator () (const osg::Camera& /*camera*/) const

      {

  .code.

   

  I use this function to init the callback in the camera settings: camera->setPostDrawCallback(new MyCameraPostDrawCallback(test.get(), zImage.get(), tex.get()));

   

  After that, I use loops to modify camera positions and take my shots (I make a code based on the example from OSG user guide using viewer->frame(). 

   

  for(x=0;x<nb_x;x++)

        {

              yd=-TEXT_SIZE/2;

              yf = yd+TEXT_SIZE;

   

              for(y=0;y<nb_y;y++)

              {     

                    camera->setClearColor(osg::Vec4(0.1f,0.3f,0.3f,1.0f));//init buffer de couleur

                    camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//init Z-buffer

                    camera->setProjectionMatrixAsOrtho(xd,xf,yd,yf,0.1,TEXT_SIZE);

   

                    viewer->frame();

                    

                    if(y<nb_y)

                    {

                          yd=yf;

                          yf=yf+TEXT_SIZE;

                    }

              }     

              if(x<nb_x)

              {

                    xd=xf;

                    xf=xf+TEXT_SIZE;

              }

        }     

   

  The problem is to takes a shot using the callback function for each frame with the new camera position.

  I thought that draw a frame should calls the Camera::DrawCallBack function, but it doesn't.

  I always get the last square from the loops in my images buffer (at each position). 

  In fact the callback function is called after the loops in spite of viewer->frame().

   

  Can you help me? I am not sure to use the right method.

   

  Thanks

   

  Matthieu DIRRENBERGER



------------------------------------------------------------------------------


  _______________________________________________
  osg-users mailing list
  osg-users at lists.openscenegraph.org
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080930/12bfa989/attachment-0003.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.cpp
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080930/12bfa989/attachment-0002.asc>


More information about the osg-users mailing list