Added very basic osgvnc example that uses the LibVNCServer client libries for implementing a vnc client
as an osg::Image with the vnc data stream going to it.
This commit is contained in:
parent
ae61033a32
commit
bad9854d71
@ -297,6 +297,7 @@ FIND_PACKAGE(GDAL)
|
|||||||
FIND_PACKAGE(CURL)
|
FIND_PACKAGE(CURL)
|
||||||
FIND_PACKAGE(ZLIB)
|
FIND_PACKAGE(ZLIB)
|
||||||
FIND_PACKAGE(ITK)
|
FIND_PACKAGE(ITK)
|
||||||
|
FIND_PACKAGE(LibVNCServer)
|
||||||
FIND_PACKAGE(OurDCMTK)
|
FIND_PACKAGE(OurDCMTK)
|
||||||
|
|
||||||
SET(wxWidgets_USE_LIBS base core gl net)
|
SET(wxWidgets_USE_LIBS base core gl net)
|
||||||
|
76
CMakeModules/FindLibVNCServer.cmake
Normal file
76
CMakeModules/FindLibVNCServer.cmake
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# Locate gdal
|
||||||
|
# This module defines
|
||||||
|
# LIBVNCSERVER_LIBRARY
|
||||||
|
# LIBVNCSERVER_FOUND, if false, do not try to link to gdal
|
||||||
|
# LIBVNCSERVER_INCLUDE_DIR, where to find the headers
|
||||||
|
#
|
||||||
|
# $LIBVNCSERVER_DIR is an environment variable that would
|
||||||
|
# correspond to the ./configure --prefix=$LIBVNCSERVER_DIR
|
||||||
|
# used in building gdal.
|
||||||
|
#
|
||||||
|
# Created by Ulrich Hertlein.
|
||||||
|
|
||||||
|
FIND_PATH(LIBVNCSERVER_INCLUDE_DIR rfb/rfb.h
|
||||||
|
$ENV{LIBVNCSERVER_DIR}/include
|
||||||
|
$ENV{LIBVNCSERVER_DIR}
|
||||||
|
$ENV{OSGDIR}/include
|
||||||
|
$ENV{OSGDIR}
|
||||||
|
$ENV{OSG_ROOT}/include
|
||||||
|
~/Library/Frameworks
|
||||||
|
/Library/Frameworks
|
||||||
|
/usr/local/include
|
||||||
|
/usr/include
|
||||||
|
/sw/include # Fink
|
||||||
|
/opt/local/include # DarwinPorts
|
||||||
|
/opt/csw/include # Blastwave
|
||||||
|
/opt/include
|
||||||
|
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include
|
||||||
|
/usr/freeware/include
|
||||||
|
)
|
||||||
|
|
||||||
|
FIND_LIBRARY(LIBVNCCLIENT_LIBRARY
|
||||||
|
NAMES vncclient
|
||||||
|
PATHS
|
||||||
|
$ENV{LIBVNCSERVER_DIR}/lib
|
||||||
|
$ENV{LIBVNCSERVER_DIR}
|
||||||
|
$ENV{OSGDIR}/lib
|
||||||
|
$ENV{OSGDIR}
|
||||||
|
$ENV{OSG_ROOT}/lib
|
||||||
|
~/Library/Frameworks
|
||||||
|
/Library/Frameworks
|
||||||
|
/usr/local/lib
|
||||||
|
/usr/lib
|
||||||
|
/sw/lib
|
||||||
|
/opt/local/lib
|
||||||
|
/opt/csw/lib
|
||||||
|
/opt/lib
|
||||||
|
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
|
||||||
|
/usr/freeware/lib64
|
||||||
|
)
|
||||||
|
|
||||||
|
FIND_LIBRARY(LIBVNCSERVER_LIBRARY
|
||||||
|
NAMES vncserver
|
||||||
|
PATHS
|
||||||
|
$ENV{LIBVNCSERVER_DIR}/lib
|
||||||
|
$ENV{LIBVNCSERVER_DIR}
|
||||||
|
$ENV{OSGDIR}/lib
|
||||||
|
$ENV{OSGDIR}
|
||||||
|
$ENV{OSG_ROOT}/lib
|
||||||
|
~/Library/Frameworks
|
||||||
|
/Library/Frameworks
|
||||||
|
/usr/local/lib
|
||||||
|
/usr/lib
|
||||||
|
/sw/lib
|
||||||
|
/opt/local/lib
|
||||||
|
/opt/csw/lib
|
||||||
|
/opt/lib
|
||||||
|
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
|
||||||
|
/usr/freeware/lib64
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(LIBVNCSERVER_FOUND "NO")
|
||||||
|
IF(LIBVNCSERVER_LIBRARY AND LIBVNCSERVER_INCLUDE_DIR)
|
||||||
|
SET(LIBVNCSERVER_FOUND "YES")
|
||||||
|
ENDIF(LIBVNCSERVER_LIBRARY AND LIBVNCSERVER_INCLUDE_DIR)
|
||||||
|
|
||||||
|
|
@ -169,8 +169,17 @@ IF(DYNAMIC_OPENSCENEGRAPH)
|
|||||||
ADD_SUBDIRECTORY(osgwidgetwindow)
|
ADD_SUBDIRECTORY(osgwidgetwindow)
|
||||||
ENDIF(BUILD_OSGWIDGET)
|
ENDIF(BUILD_OSGWIDGET)
|
||||||
|
|
||||||
|
IF (GLUT_FOUND)
|
||||||
|
ADD_SUBDIRECTORY(osgviewerGLUT)
|
||||||
|
ENDIF(GLUT_FOUND)
|
||||||
|
|
||||||
|
IF (LIBVNCSERVER_FOUND)
|
||||||
|
ADD_SUBDIRECTORY(osgvnc)
|
||||||
|
ENDIF(LIBVNCSERVER_FOUND)
|
||||||
|
|
||||||
|
|
||||||
#ADD_SUBDIRECTORY(osgcegui)
|
#ADD_SUBDIRECTORY(osgcegui)
|
||||||
|
|
||||||
#to add subject to find socket#ADD_SUBDIRECTORY(osgcluster)
|
#to add subject to find socket#ADD_SUBDIRECTORY(osgcluster)
|
||||||
|
|
||||||
ELSE(DYNAMIC_OPENSCENEGRAPH)
|
ELSE(DYNAMIC_OPENSCENEGRAPH)
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#include <osgText/Text>
|
#include <osgText/Text>
|
||||||
|
|
||||||
#include <osgViewer/Viewer>
|
#include <osgViewer/Viewer>
|
||||||
|
#include <osgViewer/ViewerEventHandlers>
|
||||||
|
|
||||||
#include <osgGA/StateSetManipulator>
|
#include <osgGA/StateSetManipulator>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -1100,6 +1102,9 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
osg::ref_ptr<ForestTechniqueManager> ttm = new ForestTechniqueManager;
|
osg::ref_ptr<ForestTechniqueManager> ttm = new ForestTechniqueManager;
|
||||||
|
|
||||||
|
// add the stats handler
|
||||||
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||||
|
|
||||||
viewer.addEventHandler(new TechniqueEventHandler(ttm.get()));
|
viewer.addEventHandler(new TechniqueEventHandler(ttm.get()));
|
||||||
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
|
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
|
||||||
|
|
||||||
|
9
examples/osgvnc/CMakeLists.txt
Normal file
9
examples/osgvnc/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
SET(TARGET_SRC osgvnc.cpp)
|
||||||
|
|
||||||
|
SET(TARGET_EXTERNAL_LIBRARIES ${LIBVNCCLIENT_LIBRARY} ${SDL_LIBRARY} ${ZLIB_LIBRARY} ${JPEG_LIBRARY} )
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${LIBVNCCLIENT_INCLUDE_DIR} ${SDL_INCLUDE_DIR})
|
||||||
|
|
||||||
|
#### end var setup ###
|
||||||
|
SETUP_EXAMPLE(osgvnc)
|
||||||
|
|
177
examples/osgvnc/osgvnc.cpp
Normal file
177
examples/osgvnc/osgvnc.cpp
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
#include <osg/Image>
|
||||||
|
#include <osg/Geometry>
|
||||||
|
#include <osg/Texture2D>
|
||||||
|
|
||||||
|
#include <osgGA/TrackballManipulator>
|
||||||
|
|
||||||
|
#include <osgViewer/Viewer>
|
||||||
|
#include <osgViewer/ViewerEventHandlers>
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <rfb/rfbclient.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ButtonMapping { int sdl; int rfb; };
|
||||||
|
|
||||||
|
ButtonMapping buttonMapping[]={
|
||||||
|
{1, rfbButton1Mask},
|
||||||
|
{2, rfbButton2Mask},
|
||||||
|
{3, rfbButton3Mask},
|
||||||
|
{0,0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static rfbBool resize(rfbClient* client) {
|
||||||
|
|
||||||
|
static char first=TRUE;
|
||||||
|
|
||||||
|
osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0));
|
||||||
|
|
||||||
|
int width=client->width;
|
||||||
|
int height=client->height;
|
||||||
|
int depth=client->format.bitsPerPixel;
|
||||||
|
|
||||||
|
std::cout<<"resize "<<width<<", "<<height<<", "<<depth<<" image = "<<image<<std::endl;
|
||||||
|
|
||||||
|
image->allocateImage(width,height,1,GL_RGBA,GL_UNSIGNED_BYTE);
|
||||||
|
|
||||||
|
client->frameBuffer= (uint8_t*)(image->data());
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update(rfbClient* client,int x,int y,int w,int h) {
|
||||||
|
|
||||||
|
osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0));
|
||||||
|
image->dirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void kbd_leds(rfbClient* client, int value, int pad) {
|
||||||
|
printf("kbd_leds %d %d\n",value,pad);
|
||||||
|
|
||||||
|
/* note: pad is for future expansion 0=unused */
|
||||||
|
fprintf(stderr,"Led State= 0x%02X\n", value);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* trivial support for textchat */
|
||||||
|
static void text_chat(rfbClient* client, int value, char *text) {
|
||||||
|
switch(value) {
|
||||||
|
case rfbTextChatOpen:
|
||||||
|
fprintf(stderr,"TextChat: We should open a textchat window!\n");
|
||||||
|
TextChatOpen(client);
|
||||||
|
break;
|
||||||
|
case rfbTextChatClose:
|
||||||
|
fprintf(stderr,"TextChat: We should close our window!\n");
|
||||||
|
break;
|
||||||
|
case rfbTextChatFinished:
|
||||||
|
fprintf(stderr,"TextChat: We should close our window!\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr,"TextChat: Received \"%s\"\n", text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
class RfbThread : 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;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc,char** argv)
|
||||||
|
{
|
||||||
|
int i,buttonMask=0;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||||
|
// image->setPixelBufferObject(new osg::PixelBufferObject(image.get()));
|
||||||
|
|
||||||
|
osg::notify(osg::NOTICE)<<"image = "<<image.get()<<std::endl;
|
||||||
|
|
||||||
|
/* 16-bit: client=rfbGetClient(5,3,2); */
|
||||||
|
rfbClient* client=rfbGetClient(8,3,4);
|
||||||
|
client->MallocFrameBuffer=resize;
|
||||||
|
client->canHandleNewFBSize = TRUE;
|
||||||
|
client->GotFrameBufferUpdate=update;
|
||||||
|
client->HandleKeyboardLedState=kbd_leds;
|
||||||
|
client->HandleTextChat=text_chat;
|
||||||
|
|
||||||
|
rfbClientSetClientData(client, 0, image.get());
|
||||||
|
|
||||||
|
osg::notify(osg::NOTICE)<<"Before rfbInitClient"<<std::endl;
|
||||||
|
|
||||||
|
if(!rfbInitClient(client,&argc,argv))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
osg::ArgumentParser arguments(&argc, argv);
|
||||||
|
osgViewer::Viewer viewer;
|
||||||
|
|
||||||
|
|
||||||
|
bool xyPlane = false;
|
||||||
|
bool flip = true;
|
||||||
|
float width = image->s();
|
||||||
|
float height = image->t();
|
||||||
|
|
||||||
|
osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f),
|
||||||
|
osg::Vec3(width,0.0f,0.0f),
|
||||||
|
xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height),
|
||||||
|
0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f);
|
||||||
|
|
||||||
|
osg::Texture2D* texture = new osg::Texture2D(image.get());
|
||||||
|
texture->setResizeNonPowerOfTwoHint(false);
|
||||||
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
||||||
|
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||||
|
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||||
|
|
||||||
|
pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
|
||||||
|
texture,
|
||||||
|
osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
osg::Geode* geode = new osg::Geode;
|
||||||
|
geode->addDrawable(pictureQuad);
|
||||||
|
|
||||||
|
viewer.setSceneData(geode);
|
||||||
|
|
||||||
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||||
|
|
||||||
|
RfbThread rfbThread(client);
|
||||||
|
rfbThread.startThread();
|
||||||
|
|
||||||
|
return viewer.run();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user