diff --git a/examples/osgvnc/CMakeLists.txt b/examples/osgvnc/CMakeLists.txt index a6e8092f6..96d337812 100644 --- a/examples/osgvnc/CMakeLists.txt +++ b/examples/osgvnc/CMakeLists.txt @@ -1,9 +1,5 @@ SET(TARGET_SRC osgvnc.cpp) -SET(TARGET_EXTERNAL_LIBRARIES ${LIBVNCCLIENT_LIBRARY} ${ZLIB_LIBRARY} ${JPEG_LIBRARY} ) - -INCLUDE_DIRECTORIES(${LIBVNCCLIENT_INCLUDE_DIR}) - #### end var setup ### SETUP_EXAMPLE(osgvnc) diff --git a/examples/osgvnc/osgvnc.cpp b/examples/osgvnc/osgvnc.cpp index 306bb1c5c..2c54e3ed7 100644 --- a/examples/osgvnc/osgvnc.cpp +++ b/examples/osgvnc/osgvnc.cpp @@ -10,300 +10,18 @@ #include #include -extern "C" { -#include -} +#include -class VncImage : public osg::Image + +osg::Node* createInteractiveQuad(const osg::Vec3& origin, osg::Vec3& widthAxis, osg::Vec3& heightAxis, + osg::Image* image) { - public: - - VncImage(); + bool flip = image->getOrigin()==osg::Image::TOP_LEFT; - bool connect(int* argc, char** argv); - - void close(); - - static rfbBool resizeImage(rfbClient* client); - - static void updateImage(rfbClient* client,int x,int y,int w,int h); - - protected: - - virtual ~VncImage(); - - class RfbThread : public osg::Referenced, public OpenThreads::Thread - { - public: - - RfbThread(rfbClient* client): - _client(client), - _done(false) {} - - virtual ~RfbThread() - { - _done = true; - cancel(); - while(isRunning()) - { - OpenThreads::Thread::YieldCurrentThread(); - } - } - - virtual void run() - { - do - { - int i=WaitForMessage(_client,500); - if(i<0) - return; - if(i) - if(!HandleRFBServerMessage(_client)) - return; - - } while (!_done && !testCancel()); - } - - rfbClient* _client; - bool _done; - - }; - - public: - - rfbClient* _client; - - osg::ref_ptr _rfbThread; - -}; - -VncImage::VncImage() -{ - // setPixelBufferObject(new osg::PixelBufferObject(this); - -} - -VncImage::~VncImage() -{ - close(); -} - -bool VncImage::connect(int* argc, char** argv) -{ - if (_client) close(); - - _client = rfbGetClient(8,3,4); - _client->canHandleNewFBSize = TRUE; - _client->MallocFrameBuffer = resizeImage; - _client->GotFrameBufferUpdate = updateImage; - _client->HandleKeyboardLedState = 0; - _client->HandleTextChat = 0; - - rfbClientSetClientData(_client, 0, this); - - if (rfbInitClient(_client,argc,argv)) - { - _rfbThread = new RfbThread(_client); - _rfbThread->startThread(); - } -} - -void VncImage::close() -{ - if (_rfbThread.valid()) - { - // stop the client thread - _rfbThread = 0; - } - - if (_client) - { - // close the client - rfbClientCleanup(_client); - _client = 0; - } -} - - -rfbBool VncImage::resizeImage(rfbClient* client) -{ - osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0)); - - int width=client->width; - int height=client->height; - int depth=client->format.bitsPerPixel; - - std::cout<<"resize "< image = osgDB::readImageFile(hostname+std::string(".vnc")); + if (image.valid()) images.push_back(image.get()); + } + + if (images.empty()) + { + return 1; + } + + bool xyPlane = false; + + osg::Group* group = new osg::Group; + + osg::Vec3 origin = osg::Vec3(0.0f,0.0f,0.0f); + for(Images::iterator itr = images.begin(); + itr != images.end(); + ++itr) + { + osg::Image* image = itr->get(); + float width = 1.0; + float height = float(image->t())/float(image->s()); + osg::Vec3 widthAxis = osg::Vec3(width,0.0f,0.0f); + osg::Vec3 heightAxis = xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height); + group->addChild(createInteractiveQuad(origin, widthAxis, heightAxis, image)); + + origin += widthAxis*1.1f; + } + + viewer.setSceneData(group); viewer.addEventHandler(new osgViewer::StatsHandler); - viewer.addEventHandler(new RfbEventHandler(image->_client)); + // add a custom escape handler, but disable the standard viewer one to enable the vnc images to handle + // the escape without it getting caught by the viewer. + viewer.addEventHandler(new EscapeHandler); viewer.setKeyEventSetsDone(0); return viewer.run();