Hi OpenSG-Users,
I want to setup the Tutorial - "Without Simple Scene Manager" from
OpenSG 1.8 with OpenSG 2.0, but it doesn't work.
The Backgrounds and Viewports seem to be, what I expect it to be, but
the Torus is missing in the scene.
Perhaps someone of you guys could tell me, what I missed.
thanks,
Constantin
PS: I just want the basic function, not the Screenshot-functionality.
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGRenderAction.h>
#include <OpenSG/OSGSolidBackground.h>
#include <OpenSG/OSGColor.h>
#include <OpenSG/OSGPerspectiveCamera.h>
#include <OpenSG/OSGGradientBackground.h>
#include <OpenSG/OSGDirectionalLight.h>
#include <OpenSG/OSGTransform.h>
#include <OpenSG/OSGViewport.h>
OSG::NodeRecPtr scene;
OSG::ViewportRecPtr leftViewport;
OSG::ViewportRecPtr rightViewport;
OSG::PerspectiveCameraRecPtr leftCamera;
OSG::PerspectiveCameraRecPtr rightCamera;
OSG::WindowRecPtr window;
OSG::RenderAction *renderAction;
OSG::NodeRecPtr leftCamBeacon, rightCamBeacon, lightBeacon, lightNode;
int setupGLUT( int *argc, char *argv[] );
OSG::NodeTransitPtr createScenegraph()
{
OSG::NodeRecPtr torus = OSG::makeTorus(1,5,8,16);
leftCamBeacon = OSG::Node::create();
rightCamBeacon = OSG::Node::create();
lightBeacon = OSG::Node::create();
OSG::TransformRecPtr leftCamTrans, rightCamTrans, lightTrans;
leftCamTrans = OSG::Transform::create();
rightCamTrans = OSG::Transform::create();
lightTrans = OSG::Transform::create();
OSG::Matrix leftM, rightM, lightM;
leftM.setTransform(OSG::Vec3f(-5,6,10));
rightM.setTransform(OSG::Vec3f(5,-6,10));
lightM.setTransform(OSG::Vec3f(1,10,2));
leftCamTrans->setMatrix(leftM);
rightCamTrans->setMatrix(rightM);
lightTrans->setMatrix(lightM);
OSG::DirectionalLightRecPtr dLight = OSG::DirectionalLight::create();
dLight->setDirection(0,1,2);
dLight->setDiffuse(OSG::Color4f(1,1,1,1));
dLight->setAmbient(OSG::Color4f(0.2,0.2,0.2,0.2));
dLight->setSpecular(OSG::Color4f(1,1,1,1));
dLight->setBeacon(lightBeacon);
lightNode = OSG::Node::create();
lightNode->setCore(dLight);
lightNode->addChild(torus);
OSG::NodeRecPtr root = OSG::Node::create();
root->setCore(OSG::Group::create());
root->addChild(lightNode);
root->addChild(leftCamBeacon);
root->addChild(rightCamBeacon);
root->addChild(lightBeacon);
OSG::commitChanges();
return OSG::NodeTransitPtr(root);
}
void init(int *argc, char **argv)
{
OSG::preloadSharedObject("OSGFileIO");
OSG::preloadSharedObject("OSGImageFileIO");
OSG::osgInit(*argc,argv);
{
int winid = setupGLUT(argc, argv);
scene = createScenegraph();
OSG::commitChanges();
leftCamera = OSG::PerspectiveCamera::create();
rightCamera = OSG::PerspectiveCamera::create();
leftCamera->setBeacon(leftCamBeacon);
leftCamera->setFov(1.57);
leftCamera->setNear(0.1);
leftCamera->setFar(100);
rightCamera->setBeacon(rightCamBeacon);
rightCamera->setFov(1.57);
rightCamera->setNear(0.1);
rightCamera->setFar(100);
OSG::GradientBackgroundRecPtr leftBkg =
OSG::GradientBackground::create();
leftBkg->addLine(OSG::Color3f(0,0,0),0);
leftBkg->addLine(OSG::Color3f(1,1,1),1);
OSG::GradientBackgroundRecPtr rightBkg =
OSG::GradientBackground::create();
rightBkg->addLine(OSG::Color3f(1,0,0),0);
rightBkg->addLine(OSG::Color3f(0,1,0),1);
leftViewport = OSG::Viewport::create();
rightViewport = OSG::Viewport::create();
leftViewport->setCamera(leftCamera);
leftViewport->setBackground(leftBkg);
leftViewport->setRoot(scene);
leftViewport->setSize(0,0,0.5,1);
rightViewport->setCamera(rightCamera);
rightViewport->setBackground(rightBkg);
rightViewport->setRoot(scene);
rightViewport->setSize(0.5,0,1,1);
renderAction = OSG::RenderAction::create();
OSG::commitChanges();
OSG::GLUTWindowRecPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->setSize(300,300);
window = gwin;
window->addPort(leftViewport);
window->addPort(rightViewport);
OSG::commitChanges();
window->init();
OSG::commitChanges();
}
glutMainLoop();
}
void reshape(int w, int h)
{
window->resize(w,h);
OSG::commitChanges();
glutPostRedisplay();
}
void display(void)
{
window->render(renderAction);
OSG::commitChanges();
glutPostRedisplay();
}
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OSGVoxelization");
// register the GLUT callback functions
glutDisplayFunc(display);
glutReshapeFunc(reshape);
return winid;
}
------------------------------------------------------------------------------
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users