Hi
In OpenSG 2.0 anyone tested Gradient Background class ? I am facing some
problem . When I am attaching Gradient Background torus is not displaying .
Is there any sequence to maintain ?
Please find attached code for reference if anyone can help me is appreciated
Naresh
// 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.
//
#ifdef OSG_BUILD_ACTIVE
// Headers
#include <OSGGLUT.h>
#include <OSGConfig.h>
#include <OSGSimpleGeometry.h>
#include <OSGGLUTWindow.h>
#include <OSGSimpleSceneManager.h>
#include <OSGAction.h>
#include <OSGGradientBackground.h>
// New Headers
// the general scene file loading handler
#include <OSGSceneFileHandler.h>
#else
// 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>
// New Headers
// the general scene file loading handler
#include <OpenSG/OSGSceneFileHandler.h>
#endif
// Activate the OpenSG namespace
OSG_USING_NAMESPACE
// 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)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
GLUTWindowRefPtr gwin = GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// load the scene
NodeRefPtr scene;
if(argc < 2)
{
FWARNING(("No file given!\n"));
FWARNING(("Supported file formats:\n"));
std::list<const char*> suffixes;
SceneFileHandler::the()->getSuffixList(suffixes);
SceneFileHandler::the()->print();
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]);
}
commitChanges();
// 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();
// Create Background
GradientBackgroundRefPtr gradBack =
GradientBackground::create();
gradBack->addLine(Color3f(0.87f,0.85f,0.76f),0);
gradBack->addLine(Color3f(0.57f,0.54f,0.32f),5);
ViewportRefPtr vp = gwin->getPort(0);
vp->setBackground(gradBack);
}
// 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:
{
// clean up global variables
delete mgr;
OSG::osgExit();
exit(0);
}
break;
case 'f':
{
mgr->setNavigationMode(Navigator::FLY);
}
break;
case 't':
{
mgr->setNavigationMode(Navigator::TRACKBALL);
}
break;
case 's':
{
mgr->setStatistics(!mgr->getStatistics());
}
}
}
// 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);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return winid;
}
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users