Revision: 7546
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7546&view=rev
Author:   natepak
Date:     2009-03-25 22:13:27 +0000 (Wed, 25 Mar 2009)

Log Message:
-----------
Fixed offscreen rendering

Modified Paths:
--------------
    code/branches/federation/gazebo/server/Simulator.cc
    code/branches/federation/gazebo/server/gui/GLWindow.cc
    code/branches/federation/gazebo/server/gui/Gui.cc
    code/branches/federation/gazebo/server/gui/Gui.hh
    code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc
    code/branches/federation/gazebo/server/rendering/OgreCamera.cc
    code/branches/federation/gazebo/server/rendering/OgreCamera.hh
    code/branches/federation/gazebo/server/rendering/OgreCreator.cc
    code/branches/federation/gazebo/server/rendering/OgreCreator.hh
    code/branches/federation/gazebo/server/rendering/UserCamera.cc
    code/branches/federation/gazebo/server/sensors/camera/MonoCameraSensor.cc

Modified: code/branches/federation/gazebo/server/Simulator.cc
===================================================================
--- code/branches/federation/gazebo/server/Simulator.cc 2009-03-25 17:56:06 UTC 
(rev 7545)
+++ code/branches/federation/gazebo/server/Simulator.cc 2009-03-25 22:13:27 UTC 
(rev 7546)
@@ -203,7 +203,9 @@
     }
   }
   else
+  {
     this->gui = NULL;
+  }
 
   //Initialize RenderEngine
   try
@@ -320,30 +322,30 @@
 
   this->physicsThread = new boost::thread( 
boost::bind(&Simulator::PhysicsLoop, this));
 
-  if (this->gui)
+  // Update the gui
+  while (!this->userQuit)
   {
-      // Update the gui
-    while (!this->userQuit)
+    currTime = this->GetWallTime();
+    if ( currTime - lastTime > 1/freq)
     {
-      currTime = this->GetWallTime();
-      if ( currTime - lastTime > 1/freq)
-      {
-        lastTime = this->GetWallTime();
+      lastTime = this->GetWallTime();
+
+      OgreAdaptor::Instance()->UpdateCameras();
+
+      if (this->gui)
         this->gui->Update();
-        currTime = this->GetWallTime();
 
-        //printf("Curr Time[%f] LastTime[%f] Period[%f] %f]\n",currTime, 
lastTime, 1/freq, currTime-lastTime);
-        if (currTime - lastTime < 1/freq)
-        {
-          usleep((1/freq - (currTime - lastTime)) * 1e6);
-        }
-      }
-      else
+      currTime = this->GetWallTime();
+
+      if (currTime - lastTime < 1/freq)
       {
-        //printf("Now Here[%f]\n",1/freq - (currTime - lastTime));
-        usleep((1/freq - currTime - lastTime) * 1e6);
+        usleep((1/freq - (currTime - lastTime)) * 1e6);
       }
     }
+    else
+    {
+      usleep((1/freq - currTime - lastTime) * 1e6);
+    }
   }
 
   this->physicsThread->join();
@@ -554,7 +556,7 @@
 
   double step = world->GetPhysicsEngine()->GetStepTime();
   double physicsUpdateRate = world->GetPhysicsEngine()->GetUpdateRate();
-  double renderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
+  //double renderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
   double physicsUpdatePeriod = 1.0 / physicsUpdateRate;
   //double renderUpdatePeriod = 1.0 / renderUpdateRate;
 
@@ -588,7 +590,6 @@
 
       this->prevPhysicsTime = this->GetRealTime();
 
-
       {
         boost::recursive_mutex::scoped_lock lock(*this->mutex);
         world->Update();

Modified: code/branches/federation/gazebo/server/gui/GLWindow.cc
===================================================================
--- code/branches/federation/gazebo/server/gui/GLWindow.cc      2009-03-25 
17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/gui/GLWindow.cc      2009-03-25 
22:13:27 UTC (rev 7546)
@@ -138,11 +138,6 @@
   }
 
   this->lastUpdateTime = Simulator::Instance()->GetRealTime();
-
-  if (this->userCamera != this->activeCamera)
-    this->activeCamera->UpdateCam();
-  else
-    this->userCamera->Update();
 }
 
 

Modified: code/branches/federation/gazebo/server/gui/Gui.cc
===================================================================
--- code/branches/federation/gazebo/server/gui/Gui.cc   2009-03-25 17:56:06 UTC 
(rev 7545)
+++ code/branches/federation/gazebo/server/gui/Gui.cc   2009-03-25 22:13:27 UTC 
(rev 7546)
@@ -94,7 +94,7 @@
 
   // Create a dummy rendering window. This creates a context, and allows Ogre
   // to initialize properly
-  OgreCreator::CreateWindow(this, 1, 1);
+  OgreCreator::Instance()->CreateWindow(this, 1, 1);
 
   this->hasFocus = true;
 }
@@ -151,8 +151,6 @@
 
   Fl::check();
 
-  OgreAdaptor::Instance()->UpdateCameras();
-
   //Fl::wait(0.3);
 }
 

Modified: code/branches/federation/gazebo/server/gui/Gui.hh
===================================================================
--- code/branches/federation/gazebo/server/gui/Gui.hh   2009-03-25 17:56:06 UTC 
(rev 7545)
+++ code/branches/federation/gazebo/server/gui/Gui.hh   2009-03-25 22:13:27 UTC 
(rev 7546)
@@ -88,6 +88,7 @@
     private: ParamT<Vector2<int> > *sizeP;
     private: ParamT<Vector2<int> > *posP;
     private: std::vector<Param*> parameters;
+
   };
 }
 

Modified: code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc     
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc     
2009-03-25 22:13:27 UTC (rev 7546)
@@ -186,8 +186,9 @@
                                           this->dummyVisual, NULL, 1);
 
     glXMakeCurrent(this->dummyDisplay, this->dummyWindowId, 
this->dummyContext);
-    OgreCreator::CreateWindow((long)this->dummyDisplay, screen, 
-                              (long)this->dummyWindowId,1,1);
+
+    OgreCreator::Instance()->CreateWindow((long)this->dummyDisplay, screen, 
+                                          (long)this->dummyWindowId,1,1);
   }
 
   // Set default mipmap level (NB some APIs ignore this)
@@ -458,18 +459,29 @@
 // Update the user cameras
 void OgreAdaptor::UpdateCameras()
 {
+  UserCamera *userCam;
+
   std::vector<OgreCamera*>::iterator iter;
 
   OgreCreator::Instance()->Update();
 
   this->root->_fireFrameStarted();
 
-  // Draw all the windows
+  // Draw all the non-user cameras
   for (iter = this->cameras.begin(); iter != this->cameras.end(); iter++)
   {
-    (*iter)->Render();
+    if (dynamic_cast<UserCamera*>((*iter)) == NULL)
+      (*iter)->Render();
   }
 
+  // Must update the user camera's last.
+  for (iter = this->cameras.begin(); iter != this->cameras.end(); iter++)
+  {
+    userCam = dynamic_cast<UserCamera*>((*iter));
+    if (userCam)
+      userCam->Update();
+  }
+
   this->root->_fireFrameEnded();
 }
 

Modified: code/branches/federation/gazebo/server/rendering/OgreCamera.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreCamera.cc      
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/rendering/OgreCamera.cc      
2009-03-25 22:13:27 UTC (rev 7546)
@@ -70,7 +70,7 @@
   this->farClipP = new ParamT<double>("farClip",100,0);
   this->saveFramesP = new ParamT<bool>("saveFrames",false,0);
   this->savePathnameP = new ParamT<std::string>("saveFramePath","",0);
-  this->imageSizeP = new ParamT< Vector2<int> >("imageSize", 
Vector2<int>(640,480),0);
+  this->imageSizeP = new ParamT< Vector2<int> >("imageSize", Vector2<int>(320, 
240),0);
   this->visMaskP = new ParamT<std::string>("mask","none",0);
   this->hfovP = new ParamT<Angle>("hfov", Angle(DTOR(60)),0);
   Param::End();
@@ -79,6 +79,8 @@
 
   // This should be last in the constructor
   CameraManager::Instance()->AddCamera(this);
+
+  this->camera = NULL;
 }
 
 
@@ -181,28 +183,36 @@
 // Update the drawing
 void OgreCamera::UpdateCam()
 {
-
-  if (World::Instance()->GetWireframe())
+  if (this->camera)
   {
-    this->camera->setPolygonMode(Ogre::PM_WIREFRAME);
+    if (World::Instance()->GetWireframe())
+    {
+      this->camera->setPolygonMode(Ogre::PM_WIREFRAME);
+    }
+    else
+    {
+      this->camera->setPolygonMode(Ogre::PM_SOLID);
+    }
   }
-  else
+
+  if (this->sceneNode)
   {
-    this->camera->setPolygonMode(Ogre::PM_SOLID);
+    Ogre::Vector3 v = this->sceneNode->_getDerivedPosition();
+
+    this->pose.pos.x = v.x;
+    this->pose.pos.y = v.y;
+    this->pose.pos.z = v.z;
   }
 
-  Ogre::Vector3 v = this->sceneNode->_getDerivedPosition();
+  if (this->pitchNode)
+  {
+    Ogre::Quaternion q = this->pitchNode->_getDerivedOrientation();
 
-  this->pose.pos.x = v.x;
-  this->pose.pos.y = v.y;
-  this->pose.pos.z = v.z;
-
-  Ogre::Quaternion q = this->pitchNode->_getDerivedOrientation();
-
-  this->pose.rot.u = q.w;
-  this->pose.rot.x = q.x;
-  this->pose.rot.y = q.y;
-  this->pose.rot.z = q.z;
+    this->pose.rot.u = q.w;
+    this->pose.rot.x = q.x;
+    this->pose.rot.y = q.y;
+    this->pose.rot.z = q.z;
+  }
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -219,12 +229,15 @@
     // Get access to the buffer and make an image and write it to file
     mBuffer = this->renderTexture->getBuffer(0, 0);
 
+    this->renderTarget->writeContentsToFile("testfile.jpg");
+
     size = this->imageSizeP->GetValue().x * this->imageSizeP->GetValue().y * 3;
 
     // Allocate buffer
     if (!this->saveFrameBuffer)
       this->saveFrameBuffer = new unsigned char[size];
 
+    memset(this->saveFrameBuffer,128,size);
     mBuffer->lock(Ogre::HardwarePixelBuffer::HBL_READ_ONLY);
 
     int top = (int)((mBuffer->getHeight() - this->imageSizeP->GetValue().y) / 
2.0);

Modified: code/branches/federation/gazebo/server/rendering/OgreCamera.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreCamera.hh      
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/rendering/OgreCamera.hh      
2009-03-25 22:13:27 UTC (rev 7546)
@@ -188,7 +188,7 @@
     public: void SetCamName( const std::string &name );
 
     // Save the camera frame
-    private: virtual void SaveFrame();
+    protected: virtual void SaveFrame();
 
 
     private: std::string name;

Modified: code/branches/federation/gazebo/server/rendering/OgreCreator.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreCreator.cc     
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/rendering/OgreCreator.cc     
2009-03-25 22:13:27 UTC (rev 7546)
@@ -269,8 +269,8 @@
     // Setup the viewport to use the texture
     cviewport = renderTarget->addViewport(camera);
     cviewport->setClearEveryFrame(true);
-    cviewport->setBackgroundColour( *OgreAdaptor::Instance()->backgroundColor 
);
-    //cviewport->setOverlaysEnabled(false);
+    //cviewport->setBackgroundColour( 
*OgreAdaptor::Instance()->backgroundColor );
+    cviewport->setBackgroundColour( Ogre::ColourValue::Blue );
 
     double ratio = (double)cviewport->getActualWidth() / 
(double)cviewport->getActualHeight();
     double vfov = 2.0 * atan(tan(hfov / 2.0) / ratio);
@@ -555,11 +555,17 @@
 // Create a window for Ogre
 Ogre::RenderWindow *OgreCreator::CreateWindow(Fl_Window *flWindow, unsigned 
int width, unsigned int height)
 {
+  Ogre::RenderWindow *win = NULL;
+
   if (flWindow)
-    return OgreCreator::CreateWindow( (long)fl_display, fl_visual->screen, 
+  {
+    win = OgreCreator::CreateWindow( (long)fl_display, fl_visual->screen, 
         (long)(Fl_X::i(flWindow)->xid), width, height);
-  else
-    return NULL;
+    if (win)
+      this->windows.push_back(win);
+  }
+
+  return win;
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -568,6 +574,9 @@
                                               long winId, unsigned int width, 
                                               unsigned int height)
 {
+  width = 800;
+  height = 600;
+
   Ogre::StringVector paramsVector;
   Ogre::NameValuePairList params;
   Ogre::RenderWindow *window = NULL;
@@ -611,6 +620,8 @@
   window->setActive(true);
   window->setAutoUpdated(true);
 
+  this->windows.push_back(window);
+
   return window;
 }
 
@@ -674,7 +685,9 @@
 {
   std::list<OgreDynamicLines*>::iterator iter;
   std::list<OgreMovableText*>::iterator titer;
+  std::list<Ogre::RenderWindow*>::iterator witer;
   std::map<std::string, OgreVisual*>::iterator viter;
+
   OgreVisual *vis = NULL;
   Entity *owner = NULL;
 
@@ -709,6 +722,13 @@
 
     }
   }
+
+  /*for (witer = this->windows.begin(); witer != this->windows.end(); witer++)
+  {
+    (*witer)->update();
+  }
+  */
+
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/branches/federation/gazebo/server/rendering/OgreCreator.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreCreator.hh     
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/rendering/OgreCreator.hh     
2009-03-25 22:13:27 UTC (rev 7546)
@@ -103,18 +103,18 @@
     public: static void CreateSky(std::string material);
 
     /// \brief Create a new window
-    public: static Ogre::RenderWindow *CreateWindow(Fl_Window *flWindow, 
+    public: Ogre::RenderWindow *CreateWindow(Fl_Window *flWindow, 
                                                     unsigned int width, 
                                                     unsigned int height);
 
 
     /// \brief Create a window for Ogre
-    public: static Ogre::RenderWindow *CreateWindow(long display, 
-                                                    int screen, 
-                                                    long winId, 
-                                                    unsigned int width, 
-                                                    unsigned int height);
-   
+    public: Ogre::RenderWindow *CreateWindow(long display, 
+                                             int screen, 
+                                             long winId, 
+                                             unsigned int width, 
+                                             unsigned int height);
+  
     /// \brief Draw the uniform grid pattern
     public: static void DrawGrid();
 
@@ -166,6 +166,9 @@
 
     // All the visuals 
     private: std::map<std::string, OgreVisual*> visuals;
+
+    // All the windows
+    private: std::list<Ogre::RenderWindow *> windows;
  
     private: friend class DestroyerT<OgreCreator>;
     private: friend class SingletonT<OgreCreator>;

Modified: code/branches/federation/gazebo/server/rendering/UserCamera.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/UserCamera.cc      
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/rendering/UserCamera.cc      
2009-03-25 22:13:27 UTC (rev 7546)
@@ -45,10 +45,9 @@
 {
   std::stringstream stream;
 
-  this->window = OgreCreator::CreateWindow(parentWindow, 
-                     parentWindow->w(), parentWindow->h());
+  this->window = OgreCreator::Instance()->CreateWindow(parentWindow, 
+                         parentWindow->w(), parentWindow->h());
 
-
   stream << "UserCamera_" << this->count++;
   this->name = stream.str(); 
 }
@@ -75,7 +74,7 @@
 {
   this->SetCameraSceneNode( 
OgreAdaptor::Instance()->sceneMgr->getRootSceneNode()->createChildSceneNode( 
this->GetCameraName() + "_SceneNode") );
 
-  OgreCamera::InitCam();
+  this->InitCam();
 
   this->viewport = this->window->addViewport(this->GetOgreCamera());
   this->viewport->setBackgroundColour(Ogre::ColourValue::Black);
@@ -92,6 +91,7 @@
 void UserCamera::Update()
 {
   OgreCamera::UpdateCam();
+  this->window->update();
 
   if (this->saveFramesP->GetValue())
   {
@@ -132,7 +132,7 @@
 // Set the dimensions of the viewport
 void UserCamera::SetViewportDimensions(float x, float y, float w, float h)
 {
-  this->viewport->setDimensions(0, 0, 0.5, 0.5);
+  this->viewport->setDimensions(x, y, w, h);
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: 
code/branches/federation/gazebo/server/sensors/camera/MonoCameraSensor.cc
===================================================================
--- code/branches/federation/gazebo/server/sensors/camera/MonoCameraSensor.cc   
2009-03-25 17:56:06 UTC (rev 7545)
+++ code/branches/federation/gazebo/server/sensors/camera/MonoCameraSensor.cc   
2009-03-25 22:13:27 UTC (rev 7546)
@@ -75,7 +75,6 @@
     gzthrow("image has zero size");
   }
 
-  this->SetCameraSceneNode( this->GetVisualNode()->GetSceneNode() );
 
   this->ogreTextureName = this->GetName() + "_RttTex";
   this->ogreMaterialName = this->GetName() + "_RttMat";
@@ -83,10 +82,11 @@
   // Create the render texture
   this->renderTexture = Ogre::TextureManager::getSingleton().createManual(
                           this->ogreTextureName,
-                          
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
+                          "General",
                           Ogre::TEX_TYPE_2D,
                           this->imageSizeP->GetValue().x, 
-                          this->imageSizeP->GetValue().y, 0,
+                          this->imageSizeP->GetValue().y,
+                          0,
                           Ogre::PF_R8G8B8,
                           Ogre::TU_RENDERTARGET);
 
@@ -105,23 +105,26 @@
 // Initialize the camera
 void MonoCameraSensor::InitChild()
 {
+  this->SetCameraSceneNode( this->GetVisualNode()->GetSceneNode() );
+
   this->InitCam();
   this->SetCamName(this->GetName());
 
-  Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(
+  /*Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(
                             this->ogreMaterialName,
                             
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
 
 
   
mat->getTechnique(0)->getPass(0)->createTextureUnitState(this->ogreTextureName);
+*/
 
   Ogre::HardwarePixelBufferSharedPtr mBuffer;
-
   // Get access to the buffer and make an image and write it to file
   mBuffer = this->renderTexture->getBuffer(0, 0);
 
   this->textureWidth = mBuffer->getWidth();
   this->textureHeight = mBuffer->getHeight();
+  
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -142,51 +145,6 @@
     return;
 
   this->UpdateCam();
-
-  // NATE
- /* this->renderTarget->update();
-  
-
-  Ogre::HardwarePixelBufferSharedPtr mBuffer;
-  size_t size;
-
-  // Get access to the buffer and make an image and write it to file
-  mBuffer = this->renderTexture->getBuffer(0, 0);
-
-  size = this->imageSizeP->GetValue().x * this->imageSizeP->GetValue().y * 3;
-
-  // Allocate buffer
-  if (!this->saveFrameBuffer)
-    this->saveFrameBuffer = new unsigned char[size];
-
-  mBuffer->lock(Ogre::HardwarePixelBuffer::HBL_READ_ONLY);
-
-  int top = (int)((mBuffer->getHeight() - this->imageSizeP->GetValue().y) / 
2.0);
-  int left = (int)((mBuffer->getWidth() - this->imageSizeP->GetValue().x) / 
2.0);
-  int right = left + this->imageSizeP->GetValue().x;
-  int bottom = top + this->imageSizeP->GetValue().y;
-
-  // Get the center of the texture in RGB 24 bit format
-  mBuffer->blitToMemory(
-    Ogre::Box(left, top, right, bottom),
-
-    Ogre::PixelBox(
-      this->imageSizeP->GetValue().x,
-      this->imageSizeP->GetValue().y,
-      1,
-      Ogre::PF_B8G8R8,
-      this->saveFrameBuffer)
-  );
-
-  mBuffer->unlock();
-
-
-  if (this->saveFramesP->GetValue())
-  {
-    this->SaveFrame();
-  }
-  */
- 
 }
 
 
////////////////////////////////////////////////////////////////////////////////


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to