Hi,
I have got some troubles with a RTT camera and HUD camera.
My scene seems like : 
                      _rootView
                            /  \
                          /      \
               RTTCam     _rootParent
                          \     /
                           root
                          /     \
                    HUDs    scene

I try to take screenshots with a RTT camera, so I use the event "KEYDOWN" of a 
"GUIEventHandler" to handle the beginning of the screenshot (create rtt camera 
etc.) and "FRAME" to wait a frame and register the screenshot. It works without 
HUD, but when I had HUD I have 2 diffrents problem :
-First : The screenshot is taken but without the HUD, Why ?
-Second : The program freeze (only when the CompositeViewer isn't single 
threaded) ! The main thread and the other are lock in cooperativeWait !

Here is the screenshot handler code :

.h

Code:

typedef struct                                  s_rttCameraImage
{
        osg::ref_ptr<osg::Camera>       _rttCamera;
        osg::ref_ptr<osg::Image>        _outputImage;
}                                                               rttCameraImage;

class SnapImageHandler : public osgGA::GUIEventHandler
{
private:
        int                                                     _keyImage;//key 
use to take a screenshot
        int                                                     _keyVideo;//key 
use to start/stop record a video
        rttCameraImage                          *_rtt;//rtt camera and image
        bool                                            _takeSCEnd; 
//screenshot register flag
        VideoRecorder*                          _vr;
        PluginVideo*                            _plugin;
        SnapImage*                                      _si;

        //Create the image and the rtt camera and attach it to the scene
        void                                            screenShotInit();
        //Save the image on the disk and remove the rtt camera to the scene
        void                                            screenShotRecord();

public:
        SnapImageHandler(int keyImage, int keyVideo, VideoRecorder* video, 
PluginVideo * plugin, SnapImage *si) :
    _keyImage(keyImage),
    _keyVideo(keyVideo),
    _vr(video),
        _plugin(plugin),
        _si(si),
        _takeSCEnd(false),
        _rtt(0)
        {}
        ~SnapImageHandler(void){}
        //overload method
        virtual bool                                            handle(const 
osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
};




.cpp

Code:

void    SnapImageHandler::screenShotInit()
{
        _rtt = new rttCameraImage;
        _rtt->_outputImage = new osg::Image;
        if (_vr->getFilenameImage().find(".jpg") != std::string::npos || 
_vr->getFilenameImage().find(".jpeg") != std::string::npos)
                
_rtt->_outputImage->allocateImage(_vr->getOutputImageSize().x(), 
_vr->getOutputImageSize().y(), 1, GL_RGB, GL_UNSIGNED_BYTE);
        else
                
_rtt->_outputImage->allocateImage(_vr->getOutputImageSize().x(), 
_vr->getOutputImageSize().y(), 1, GL_RGBA, GL_UNSIGNED_BYTE);
        _rtt->_rttCamera = new osg::Camera;
        _rtt->_rttCamera->setViewMatrix(_vr->getCurrentViewMatrix());
        
_rtt->_rttCamera->setProjectionMatrix(_vr->getCurrentProjectionMatrix());
        _rtt->_rttCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
        _rtt->_rttCamera->setClearMask(GL_COLOR_BUFFER_BIT | 
GL_DEPTH_BUFFER_BIT);
        _rtt->_rttCamera->setViewport(0, 0, _vr->getOutputImageSize().x(), 
_vr->getOutputImageSize().y());
        
_rtt->_rttCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
        _rtt->_rttCamera->setRenderOrder(osg::Camera::PRE_RENDER);
        _rtt->_rttCamera->setRenderingCache( 0 );
        _rtt->_rttCamera->setCullingActive(false);
        _rtt->_rttCamera->attach( osg::Camera::COLOR_BUFFER, 
_rtt->_outputImage.get(), 0, 0);
        _rtt->_rttCamera->addChild(_vr->getSceneNode());
        _vr->getRootNode()->addChild(_rtt->_rttCamera);
        _vr->takeScreenShot(false);
        _takeSCEnd = true;
}

void    SnapImageHandler::screenShotRecord()
{
        _vr->saveImage(_rtt->_outputImage.get(), 1);
        _vr->getRootNode()->removeChild(_rtt->_rttCamera.get());
        _rtt->_outputImage->releaseGLObjects();
        _rtt->_rttCamera->detach(osg::Camera::COLOR_BUFFER);
        _rtt->_rttCamera = 0;
        _rtt->_outputImage = 0;
        delete (_rtt);
        _rtt = 0;
        _si->_messagePrintPhotoOnHUD = true;
        _si->_messagePrintPhotoOnHUDtick = osg::Timer::instance()->tick();
        _vr->_callFromSocket = false;
        _takeSCEnd = false;
}

bool    SnapImageHandler::handle(const osgGA::GUIEventAdapter& 
ea,osgGA::GUIActionAdapter& aa)
 {
         osgViewer::View *viewer = dynamic_cast<osgViewer::View *>(&aa);

         switch(ea.getEventType())
         {
         case (osgGA::GUIEventAdapter::FRAME):
                 {
                        if (_takeSCEnd)
                                this->screenShotRecord();
                        if (_vr->isTakingAScreenshot())
                                this->screenShotInit();
                 }
         case (osgGA::GUIEventAdapter::KEYDOWN):
                 {
                         if (ea.getKey() == this->_keyImage)
                         {
                                 if (!_vr->isTakingAScreenshot() && !_takeSCEnd)
                                 {
                                         if (_vr->getRootNode() == 0 || 
_vr->getSceneNode() == 0)
                                                 return (false);
                                         
_vr->setCurrentViewMatrix(viewer->getCamera()->getViewMatrix());
                                         
_vr->setCurrentProjectionMatrix(viewer->getCamera()->getProjectionMatrix());
                                         _vr->takeScreenShot(true);
                                        return (true);
                                 }
                         }
                         else if (ea.getKey() == _keyVideo)
                        {
                                if(_plugin->isVideoFromHandlerFeatureEnabled())
                                        _vr->switchRecordingState();
                                return (true);
                        }
                         return (false);
                 }
        default:
                return (false);
         }
         return (false);
}




And the call stack :

Main thread :
        ntdll.dll!7d61c846()    
        [Frames below may be incorrect and/or missing, no symbols loaded for 
ntdll.dll] 
        kernel32.dll!7d4d8c9e()         
        kernel32.dll!7d4d8c0d()         
>       ot11-OpenThreadsd.dll!OpenThreads::cooperativeWait(void * 
> waitHandle=0x00001c94, unsigned long timeout=4294967295)  Line 55 + 0x10 
> bytes        C++
        
ot11-OpenThreadsd.dll!OpenThreads::Win32ConditionPrivateData::wait(OpenThreads::Mutex
 & external_mutex={...}, long timeout_ms=-1)  Line 109 + 0x1d bytes        C++
        ot11-OpenThreadsd.dll!OpenThreads::Condition::wait(OpenThreads::Mutex * 
mutex=0x08b8797c)  Line 63      C++
        osg55-osgViewerd.dll!OpenThreads::BlockCount::block()  Line 133 + 0x17 
bytes    C++
        osg55-osgViewerd.dll!osgViewer::ViewerBase::renderingTraversals()  Line 
815     C++
        osg55-osgViewerd.dll!osgViewer::ViewerBase::frame(double 
simulationTime=1.7976931348623157e+308)  Line 609 + 0xf bytes  C++
        3DEMd.dll!EM_Modules::run()  Line 475 + 0x39 bytes      C++
        3DEMd.dll!EM_Modules::init(HWND__ * hWnd=0x00000000)  Line 179 + 0x8 
bytes      C++
        
3DEMd.dll!EM_Modules::launch(std::basic_string<char,std::char_traits<char>,std::allocator<char>
 > configpath="config/config.prp", 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > 
libpath="lib/win32/", 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > 
flexservername="")  Line 136 + 0xa bytes      C++
        Launcherd.exe!main(int argc=1, char * * argv=0x039cd590)  Line 81 + 
0x9e bytes  C++
        Launcherd.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes        C
        Launcherd.exe!mainCRTStartup()  Line 403        C
        kernel32.dll!7d4e7d42()         

Thread 2 : 
>       ot11-OpenThreadsd.dll!OpenThreads::cooperativeWait(void * 
> waitHandle=0x00001e7c, unsigned long timeout=4294967295)  Line 50     C++
        
ot11-OpenThreadsd.dll!OpenThreads::Win32ConditionPrivateData::wait(OpenThreads::Mutex
 & external_mutex={...}, long timeout_ms=-1)  Line 109 + 0x1d bytes        C++
        ot11-OpenThreadsd.dll!OpenThreads::Condition::wait(OpenThreads::Mutex * 
mutex=0x03a33c64)  Line 63      C++
        osg55-osgViewerd.dll!OpenThreads::Block::block()  Line 42 + 0x17 bytes  
C++
        osg55-osgViewerd.dll!osgViewer::Renderer::ThreadSafeQueue::takeFront()  
Line 140        C++
        osg55-osgViewerd.dll!osgViewer::Renderer::draw()  Line 380 + 0xe bytes  
C++
        
osg55-osgViewerd.dll!osgViewer::Renderer::operator()(osg::GraphicsContext * 
context=0x03a39528)  Line 695 + 0xf bytes   C++
        osg55-osgd.dll!osg::GraphicsContext::runOperations()  Line 688 + 0x33 
bytes     C++
        osg55-osgd.dll!osg::RunOperations::operator()(osg::GraphicsContext * 
context=0x03a39528)  Line 138      C++
        osg55-osgd.dll!osg::GraphicsOperation::operator()(osg::Object * 
object=0x03a39528)  Line 53 + 0x19 bytes        C++
        osg55-osgd.dll!osg::OperationThread::run()  Line 413 + 0x26 bytes       
C++
        osg55-osgd.dll!osg::GraphicsThread::run()  Line 41      C++
        
ot11-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void * 
data=0x08b87f5c)  Line 116 + 0xf bytes      C++
        msvcr90d.dll!_callthreadstartex()  Line 348 + 0xf bytes C
        msvcr90d.dll!_threadstartex(void * ptd=0x08b88860)  Line 331    C
        kernel32.dll!7d4dfe37()         
        [Frames below may be incorrect and/or missing, no symbols loaded for 
kernel32.dll]

Thanks ! =)

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27528#27528





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to