Yeah, yeah, it helps if I'd actually attach the example file...
Note that for changing the draw mode (key 'd') you need an updated SSM,
the Action changing that was in there didn't work so well.
Dirk
// OpenSG Tutorial Example: Loading
//
// This example shows how to load a scene file using OpenSG.
// The supported formats right now are VRML97, OBJ, OFF and RAW, so just
// calling this program with a scene file as a parameter should load the scene
// file.
//
// Headers
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGAction.h>
#include <OpenSG/OSGSceneFileHandler.h>
#include <OpenSG/OSGSimpleAttachments.h>
#include <OpenSG/OSGVolumeDraw.h>
// Activate the OpenSG namespace
OSG_USING_NAMESPACE
// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;
RenderAction *orig, *wire;
// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );
OSG::Action::ResultE wireDrawGeo( OSG::CNodePtr &, OSG::Action * action )
{
RenderAction *ra = dynamic_cast<RenderAction*>(action);
OSG::NodePtr node = action->getActNode();
const OSG::DynamicVolume& vol = node->getVolume();
Color3f col;
#if 0 // This case can never happen, as the render action validates the
// volumes before drawing them. Just for completeness' sake...
if(!vol.isValid())
{
col.setValuesRGB(1.0f,0.0f,0.0f);
}
else if(vol.isStatic())
{
col.setValuesRGB(0.0f,0.0f,1.0f);
}
else
{
col.setValuesRGB(0.0f,1.0f,0.0f);
}
dropVolume(ra, vol, col);
#else
col.setValuesRGB(0.0f,1.0f,0.0f);
dropVolume(ra, node, col);
#endif
OSG::MaterialDrawablePtr c = OSG::MaterialDrawablePtr::dcast(node->getCore());
return c->renderActionHandler(ra);
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
// load the scene
NodePtr scene;
if(argc < 2)
{
FWARNING(("No file given!\n"));
FWARNING(("Supported file formats:\n"));
std::list<const char*> suffixes;
SceneFileHandler::the().getSuffixList(suffixes);
for(std::list<const char*>::iterator it = suffixes.begin();
it != suffixes.end();
++it)
{
FWARNING(("%s\n", *it));
}
scene = makeTorus(.5, 2, 16, 16);
}
else
{
/*
All scene file loading is handled via the SceneFileHandler.
*/
scene = SceneFileHandler::the().read(argv[1]);
}
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
wire = RenderAction::create();
wire->registerEnterFunction(OSG::Geometry::getClassType(),
osgTypedFunctionFunctor2CPtrRef<
Action::ResultE,
CNodePtr,
Action * >(wireDrawGeo));
mgr->setAction(wire);
// GLUT main loop
glutMainLoop();
return 0;
}
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
mgr->idle();
mgr->redraw();
}
// react to size changes
void reshape(int w, int h)
{
mgr->resize(w, 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 , int )
{
switch(k)
{
case 27:
{
OSG::osgExit();
exit(0);
}
break;
case 'f':
{
mgr->setNavigationMode(Navigator::FLY);
}
break;
case 't':
{
mgr->setNavigationMode(Navigator::TRACKBALL);
}
break;
case 'd':
{
if(mgr->getAction() == wire)
{
mgr->setAction(NULL);
}
else
{
mgr->setAction(wire);
}
}
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);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
return winid;
}