I have attached OpenSG 2 ports of the 1.x tutorial applications 12ClusterServer, 12ClusterServerX, and 13ClusterClient. To get these to link, I had to make some modifications to Tutorials/SConstruct. I wasn't sure about the best way to do this, so I added some matching code to the loop that tells SCons to build the tutorial programs. For the case when the application name contains the substring "Cluster", the OSGCluster library gets added to the library list. For the case when the application name ends with "X", the OSGWindowX library gets added.
-Patrick -- Patrick L. Hartling | VP Engineering, Infiscape Corp. PGP: http://tinyurl.com/2msw3 | http://www.infiscape.com/
// OpenSG Tutorial Example: Hello World
//
// Minimalistic OpenSG cluster client program
//
// To test it, run
// ./12ClusterServer -geometry 300x300+200+100 -m -w test1 &
// ./12ClusterServer -geometry 300x300+500+100 -m -w test2 &
// ./13ClusterClient -m -fData/tie.wrl test1 test2
//
// If you have trouble with multicasting, you can alternatively try
// ./12ClusterServer -geometry 300x300+200+100 -w 127.0.0.1:30000 &
// ./12ClusterServer -geometry 300x300+500+100 -w 127.0.0.1:30001 &
// ./13ClusterClient -m -fData/tie.wrl 127.0.0.1:30000 127.0.0.1:30001
//
// The client will open an emoty window that you can use to navigate. The
// display is shown in the server windows.
//
// This will run all three on the same machine, but you can also start the
// servers anywhere else, as long as you can reach them via multicast.
//
// Note: This will run two VERY active OpenGL programs on one screen. Not all
// OpenGL drivers are happy with that, so if it crashes your X, it's not our
// fault! ;)
// GLUT is used for window handling
#include <OpenSG/OSGGLUT.h>
// General OpenSG configuration, needed everywhere
#include <OpenSG/OSGConfig.h>
// Methods to create simple geometry: boxes, spheres, tori etc.
#include <OpenSG/OSGSimpleGeometry.h>
// The GLUT-OpenSG connection class
#include <OpenSG/OSGGLUTWindow.h>
// A little helper to simplify scene management and interaction
#include <OpenSG/OSGSimpleSceneManager.h>
// A little helper to simplify scene management and interaction
#include <OpenSG/OSGMultiDisplayWindow.h>
// Scene file handler for loading geometry files
#include <OpenSG/OSGSceneFileHandler.h>
// Activate the OpenSG namespace
OSG_USING_NAMESPACE
using namespace std;
// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;
// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
char *opt;
NodePtr scene=NullFC;
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between this client and the servers
MultiDisplayWindowPtr mwin= MultiDisplayWindow::create();
// evaluate params
for(int a=1 ; a<argc ; ++a)
{
if(argv[a][0] == '-')
{
switch(argv[a][1])
{
case 'm': mwin->setConnectionType("Multicast");
cout << "Connection type set to Multicast" << endl;
break;
case 'p': mwin->setConnectionType("SockPipeline");
cout << "Connection type set to SockPipeline" << endl;
break;
case 'i': opt = argv[a][2] ? argv[a]+2 : argv[++a];
if(opt != argv[argc])
mwin->setConnectionInterface(opt);
break;
case 'a': opt = argv[a][2] ? argv[a]+2 : argv[++a];
if(opt != argv[argc])
mwin->setServiceAddress(opt);
break;
case 'f': opt = argv[a][2] ? argv[a]+2 : argv[++a];
if(opt != argv[argc])
scene = SceneFileHandler::the()->read(
opt,0);
break;
case 'x': opt = argv[a][2] ? argv[a]+2 : argv[++a];
if(opt != argv[argc])
mwin->setHServers(atoi(opt));
break;
case 'y': opt = argv[a][2] ? argv[a]+2 : argv[++a];
if(opt != argv[argc])
mwin->setVServers(atoi(opt));
break;
default: std::cout << argv[0]
<< " -m"
<< " -p"
<< " -i interface"
<< " -f file"
<< " -x horizontal server cnt"
<< " -y vertical server cnt"
<< endLog;
return 0;
}
}
else
{
printf("%s\n",argv[a]);
mwin->editServers().push_back(argv[a]);
}
}
// dummy size for navigator
mwin->setSize(300,300);
// create default scene
if(scene == NullFC)
scene = makeTorus(.5, 2, 16, 16);
commitChanges();
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(mwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
// initialize window
mwin->init();
// GLUT main loop
glutMainLoop();
return 0;
}
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
// redraw the cluster window
mgr->redraw();
// clear change list. If you don't clear the changelist,
// then the same changes will be transmitted a second time
// in the next frame.
OSG::Thread::getCurrentChangeList()->clear();
// clear local navigation window
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
// react to size changes
void reshape(int w, int h)
{
glutPostRedisplay();
}
// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
// react to mouse motions with pressed buttons
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
// react to keys
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 27:
{
OSG::osgExit();
exit(0);
}
break;
}
}
// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
return winid;
}
// OpenSG Tutorial Example: Cluster Server
//
// This is a full functional OpenSG cluster server. In OpenSG
// the terms server and client are used similar to X11. The
// application is the client. Instances that are used for
// rendering are called server.
//
// See the ClusterClient.cpp for an example of how to use them.
#ifndef WIN32
#include <iostream>
// General OpenSG configuration, needed everywhere
#include <OpenSG/OSGConfig.h>
// The Cluster server definition
#include <OpenSG/OSGClusterServer.h>
// The GLUT-OpenSG connection class
#include <OpenSG/OSGXWindow.h>
// Render action definition.
#include <OpenSG/OSGRenderAction.h>
OSG_USING_NAMESPACE
// local glut window
XWindowPtr window;
// render action
RenderAction *ract;
// pointer the the cluster server instance
ClusterServer *server;
bool exitOnError = false;
// forward declaration so we can have the interesting stuff upfront
void display();
void reshape( int width, int height );
int wait_for_map_notify(Display *, XEvent *event, char *arg)
{
return( event->type == MapNotify && event->xmap.window == (::Window)arg );
}
// Initialize GLUT & OpenSG and start the cluster server
int main(int argc,char **argv)
{
int winid;
char *name = "ClusterServer";
char *connectionType = "StreamSock";
bool fullscreen = true;
std::string address = "";
char *opt;
bool doStereo = false;
UInt32 servicePort = 8437;
std::string serviceGroup = "224.245.211.234";
// evaluate params
for(int a=1 ; a<argc ; ++a)
{
if(argv[a][0] == '-')
{
switch(argv[a][1])
{
case 'm':
connectionType="Multicast";
break;
case 's':
doStereo=true;
break;
case 'w':
fullscreen=false;
break;
case 'e':
exitOnError=true;
break;
case 'a': address = argv[a][2] ? argv[a]+2 : argv[++a];
if(address == argv[argc])
{
SLOG << "address missing" << endLog;
return 0;
}
std::cout << address << endLog;
break;
case 'p':
if(argv[a][2] != '\0')
servicePort=atoi(argv[a]+2);
else
servicePort=atoi(argv[++a]);
break;
case 'j':
if(argv[a][2] != '\0')
serviceGroup=argv[a]+2;
else
serviceGroup=argv[++a];
break;
case 'h':
default:
std::cout << argv[0]
<< "-m "
<< "-s "
<< "-w "
<< "-e "
<< "-a Address "
<< "-j group "
<< "-p servicePort "
<< std::endl;
std::cout << "-m use multicast" << std::endl;
std::cout << "-s enable stereo" << std::endl;
std::cout << "-w no fullscreen" << std::endl;
std::cout << "-e exit after closed connection"
<< std::endl;
std::cout << "-a Address Server network address"
<< std::endl;
std::cout << "-m Address wait for requests on "
<< "multicast group" << std::endl;
std::cout << "-p port wait for requests on port"
<< std::endl;
return 0;
}
}
else
{
name=argv[a];
}
}
try
{
// init OpenSG
osgInit(argc, argv);
int snglBuf[] = {GLX_RGBA,
GLX_DEPTH_SIZE, 16,
None};
int dblBuf[16];
dblBuf[0] = GLX_RGBA;
dblBuf[1] = GLX_DEPTH_SIZE;
dblBuf[2] = 16;
dblBuf[3] = GLX_DOUBLEBUFFER;
dblBuf[4] = (doStereo == true) ? GLX_STEREO : None;
dblBuf[5] = None;
GLboolean doubleBuffer = GL_FALSE;
// X init
DisplayP dpy = XOpenDisplay(NULL);
if(dpy == NULL)
{
std::cerr << "Error: Could not open display!" << std::endl;
}
int dummy;
if(!glXQueryExtension( dpy, &dummy, &dummy))
{
std::cerr << "Error: X server has no OpenGL GLX extension"
<< std::endl;
}
XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf);
if(vi == NULL)
{
vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf);
if(vi == NULL)
{
std::cerr << "no RGB visual with depth buffer" << std::endl;
}
doubleBuffer = GL_FALSE;
}
if(vi->c_class != TrueColor)
{
std::cerr << "TrueColor visual required for this program"
<< std::endl;
}
Colormap cmap = XCreateColormap(dpy,
RootWindow(dpy, vi->screen),
vi->visual,
AllocNone);
XSetWindowAttributes swa;
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask =
ExposureMask |
ButtonPressMask |
ButtonReleaseMask |
KeyPressMask |
Button1MotionMask |
Button2MotionMask |
Button3MotionMask |
StructureNotifyMask;
// Create Window
// Create a Window and connect it to the main display dpy
X11Window hwin = XCreateWindow(dpy,
RootWindow(dpy, vi->screen),
0, 0, 300, 300,
0,
vi->depth,
InputOutput,
vi->visual,
CWBorderPixel |
CWColormap |
CWEventMask,
&swa );
XSetStandardProperties(dpy, hwin, "testWindowX", "testWindowX",
None, argv, argc, NULL);
if(fullscreen == true)
{
Atom noDecorAtom = XInternAtom(dpy,
"_MOTIF_WM_HINTS",
0);
if(noDecorAtom == None)
{
fprintf(stderr,
"Could not intern X atom for _MOTIF_WM_HINTS.\n");
}
struct NoDecorHints
{
long flags;
long functions;
long decorations;
long input_mode;
};
NoDecorHints oHints;
oHints.flags = 2;
oHints.decorations = 0;
XChangeProperty(dpy,
hwin,
noDecorAtom,
noDecorAtom,
32,
PropModeReplace,
(unsigned char *) &oHints, 4);
}
// create the render action
ract=RenderAction::create();
// setup the OpenSG Glut window
window = XWindow::create();
window->setDisplay ( dpy );
window->setWindow ( hwin );
window->init();
XEvent event;
XMapWindow(dpy, hwin);
XIfEvent(dpy, &event, wait_for_map_notify, (char *)hwin);
if(fullscreen == true)
{
XMoveWindow (dpy, hwin, 0, 0);
XResizeWindow(dpy, hwin,
DisplayWidth (dpy, vi->screen),
DisplayHeight(dpy, vi->screen));
static char data[1] = {0};
Cursor cursor;
Pixmap blank;
XColor dummyCol;
blank = XCreateBitmapFromData(dpy,
hwin,
data, 1, 1);
cursor = XCreatePixmapCursor(dpy,
blank,
blank,
&dummyCol, &dummyCol, 0, 0);
XFreePixmap(dpy, blank);
XDefineCursor(dpy,
hwin,
cursor);
XFlush(dpy);
}
window->activate();
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_NORMALIZE );
// create the cluster server
server = new ClusterServer(window,name,connectionType,address);
// start the server
server->start();
Real32 w,h,a,b,c,d;
bool stopIt = false;
int ip;
while(!stopIt)
{
while(ip = XPending(dpy))
{
XNextEvent(dpy, &event);
switch (event.type)
{
case ConfigureNotify:
{
reshape(event.xconfigure.width,
event.xconfigure.height);
}
break;
case Expose:
display();
break;
}
}
display();
}
}
catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
{
SLOG << e.what() << endLog;
delete server;
osgExit();
}
return 0;
}
/* render loop */
void display()
{
try
{
// receive scenegraph and do rendering
server->render(ract);
// clear changelist
OSG::Thread::getCurrentChangeList()->clear();
}
catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
{
if(exitOnError)
{
SLOG << e.what() << std::endl;
try
{
delete server;
}
catch(...)
{
}
printf("Exit on error %s",e.what());
osgExit();
exit(0);
}
else
{
SLOG << e.what() << endLog;
// try to restart server
server->stop();
// start server, wait for client to connect
server->start();
}
}
}
/* window reshape */
void reshape( int width, int height )
{
// set new window size
window->resize( width, height );
}
#else
#include <iostream>
int main(int argc,char **argv)
{
std::cerr << "Not supported on windows platform!" << std::endl;
}
#endif // WIN32
// OpenSG Tutorial Example: Cluster Server
//
// This is a full functional OpenSG cluster server. In OpenSG
// the terms server and client are used similar to X11. The
// application is the client. Instances that are used for
// rendering are called server.
//
// See the ClusterClient.cpp for an example of how to use them.
#include <iostream>
// GLUT is used for window handling
#include <OpenSG/OSGGLUT.h>
// General OpenSG configuration, needed everywhere
#include <OpenSG/OSGConfig.h>
// The Cluster server definition
#include <OpenSG/OSGClusterServer.h>
// The GLUT-OpenSG connection class
#include <OpenSG/OSGGLUTWindow.h>
// Render action definition.
#include <OpenSG/OSGRenderAction.h>
OSG_USING_NAMESPACE
// local glut window
GLUTWindowPtr window;
// render action
RenderAction *ract;
// pointer the the cluster server instance
ClusterServer *server;
// forward declaration so we can have the interesting stuff upfront
void display();
void update();
void reshape( int width, int height );
// Initialize GLUT & OpenSG and start the cluster server
int main(int argc,char **argv)
{
int winid;
char *name ="ClusterServer";
char *connectionType="StreamSock";
bool fullscreen =true;
std::string address ="";
char *opt;
// initialize Glut
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB |
GLUT_DEPTH |
GLUT_DOUBLE);
// evaluate params
for(int a=1 ; a<argc ; ++a)
{
if(argv[a][0] == '-')
{
switch(argv[a][1])
{
case 'm': connectionType="Multicast";
break;
case 'p': connectionType="SockPipeline";
break;
case 'w': fullscreen=false;
break;
case 'a': address = argv[a][2] ? argv[a]+2 : argv[++a];
if(address == argv[argc])
{
SLOG << "address missing" << endLog;
return 0;
}
std::cout << address << endLog;
break;
default: std::cout << argv[0]
<< "-m "
<< "-p "
<< "-w "
<< "-a address "
<< endLog;
return 0;
}
}
else
{
name=argv[a];
}
}
try
{
// init OpenSG
osgInit(argc, argv);
winid = glutCreateWindow(name);
if(fullscreen)
glutFullScreen();
glutDisplayFunc(display);
glutIdleFunc(update);
glutReshapeFunc(reshape);
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_NORMALIZE );
glutSetCursor(GLUT_CURSOR_NONE);
// create the render action
ract=RenderAction::create();
// setup the OpenSG Glut window
window = GLUTWindow::create();
window->setId(winid);
window->init();
// create the cluster server
server = new ClusterServer(window,name,connectionType,address);
// start the server
server->start();
// enter glut main loop
glutMainLoop();
}
catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
{
SLOG << e.what() << endLog;
delete server;
osgExit();
}
return 0;
}
/* render loop */
void display()
{
try
{
// receive scenegraph and do rendering
server->render(ract);
// clear changelist
OSG::Thread::getCurrentChangeList()->clear();
}
catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
{
SLOG << e.what() << endLog;
// try to restart server
server->stop();
// start server, wait for client to connect
server->start();
}
}
void update(void)
{
glutPostRedisplay();
}
/* window reshape */
void reshape( int width, int height )
{
// set new window size
window->resize( width, height );
}
Index: Tutorials/SConstruct
===================================================================
--- Tutorials/SConstruct (revision 562)
+++ Tutorials/SConstruct (working copy)
@@ -141,7 +141,14 @@
for file in tutorials:
name = file.split('.')[0]
+ extra_libs = base_env['LIBS']
+ if name.find('Cluster') != -1:
+ extra_libs.insert(0, 'OSGCluster')
+ if name.endswith('X'):
+ extra_libs.insert(0, 'OSGWindowX')
+
# Build the test program and install into tree
- loader = base_env.Program(name+runtime_suffix, file)
+ loader = base_env.Program(name+runtime_suffix, file,
+ LIBS = extra_libs)
Default(".")
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Opensg-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensg-users
