int main(int argc, char **argv) 
{
    // we need to load some relative images and geometry files.
    // to make this work reliable (e.g. starting the tutorial via link)
    // we use the argv[0] parameter.
#ifdef WIN32
    std::string sep("\\");
#else
    std::string sep("/");
#endif
    std::string path = argv[0];
    // remove app name
    std::string::size_type i = path.rfind(sep);
    if(i != std::string::npos)
        path = path.substr(0, i);
    // set the current dir to the application dir.
    OSG::Directory::setCurrent(path.c_str());

    // OSG init
    OSG::osgInit(argc, argv);
    
    /* Initialize GLUT state - glut will take any command line arguments that pertain to it or 
     X Windows - look at its documentation at http://reality.sgi.com/mjk/spec3/spec3.html */  
    glutInit(&argc, argv);  
    
    /* Select type of Display mode:   
     Double buffer 
     RGBA color
     Alpha components supported (use GLUT_ALPHA)
     Depth buffer */  
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE |  GLUT_DEPTH );  
    
    /* get a 640 x 480 window */
    //glutInitWindowSize(640, 480);  
    glutInitWindowSize(Width, Height);
    
    /* the window starts at the upper left corner of the screen */
    glutInitWindowPosition(300, 0);  
    
    /* Open a window */  
    window = glutCreateWindow("Oz, Mouse Control");
    
    if (m_bFullscreen)
        glutFullScreen();
    glutSetCursor(GLUT_CURSOR_NONE);
    
    glutDisplayFunc(&DrawGLScene); 
    
    // register all GLUT callback functions
    glutIdleFunc(idleFunc);
    
    /* Register the function called when our window is resized. */
    glutReshapeFunc(ReSizeGLScene);
    
    /* Register the function called when the keyboard is pressed. */
    glutKeyboardFunc(keyPressed);
    
    /* Register the function called when special keys (arrows, page down, etc) are pressed. */
    //glutSpecialFunc(&specialKeyPressed);
    
    glutMouseFunc(mouseFunc);
    glutMotionFunc(motionFunc);
    glutPassiveMotionFunc(motionFunc);
    
    /* Initialize our window. */
    InitGL(640, 480);
    
    pwin = OSG::PassiveWindow::create();
    pwin->init();
    
    /*
    All scene file loading is handled via the SceneFileHandler.
    */
    world = OSG::SceneFileHandler::the()->read("Data/tie.wrl");
    // create the main scene transformation node
    
    // 1. create the Node
    scene =OSG:: Node::create();
    
    // 2. create the core
    trans = OSG::Transform::create();
    
    // 3. associate the core with the node
    scene->setCore(trans);
    scene->addChild(world); // add the world as a child
    
    // create the SimpleSceneManager helper - it will be only partially used
    mgr = new OSG::SimpleSceneManager;
    
    // tell the manager what to manage
    mgr->setWindow(pwin );
    mgr->setRoot  (scene);

    if (pwin->getMFPort()->size() != 0) 
    {
        OSG::PassiveBackgroundRefPtr bg = OSG::PassiveBackground::create();
        
        vp  = pwin->getPort(0);
        cam = dynamic_cast<OSG::PerspectiveCamera *>(vp->getCamera());
        newcam = OSG::MatrixCamera::create();  // the MatrixCamera will only be a slave to the OpenGL matrices
        vp->setCamera(newcam); // replace the cam
        vp->setBackground(bg); // keep OpenSG from deleting the background, we will do that ourselves
        if(cam == NULL)
            exit(1);
    }
    else
    {
        printf("Could not acquire pointer to camera !!\n");
        exit(1);
    }
    
    OSG::commitChanges();
    
    /* Start Event Processing Engine */  
    glutMainLoop();

    return 1;
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    OSG::osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    {
        // the connection between GLUT and OpenSG
        OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();

        gwin->setGlutId(winid);
        gwin->init();

        // create the scene
        OSG::NodeRefPtr torus = OSG::makeTorus( .5, 2, 16, 32 );
        OSG::NodeRefPtr scene = OSG::Node::create();

        trans = OSG::Transform::create();

        scene->setCore(trans);
        scene->addChild(torus);

        // Create the parts needed for the video background
        OSG::UInt32 width  = 640;
        OSG::UInt32 height = 480;

        // get the desired size from the command line
        if(argc >= 3)
        {
            width  = atoi(argv[1]);
            height = atoi(argv[2]);
        }

        // To check OpenGL extensions, the Window needs to have run through
        // frameInit at least once. This automatically happens when rendering,
        // but we can't wait for that here.

        gwin->activate ();
        gwin->frameInit();

        // Now we can check for OpenGL extensions
        hasNPOT = gwin->hasExtension("GL_ARB_texture_non_power_of_two");

        // Print what we've got
        SLOG << "Got " << (isPOT?"":"non-") << "power-of-two images and "
            << (hasNPOT?"can":"cannot") << " use NPOT textures, changing "
            << (changeOnlyPart?"part":"all")
            << " of the screen"
            << std::endl;

        // Ok, now for the meat of the code...
        // first we need an Image to hold the picture(s) to show
        image = OSG::Image::create();

        // set the image's size and type, and allocate memory
        // this example uses RGB. On some systems (e.g. Windows) BGR
        // or BGRA might be faster, it depends on how the images are
        // acquired

        image->set(OSG::Image::OSG_RGB_PF, width, height);



        // Now create the texture to be used for the background
        texObj = OSG::TextureObjChunk::create();

        // Associate image and texture
        texObj->setImage(image);

        // Set filtering modes. LINEAR is cheap and good if the image size
        // changes very little (i.e. the window is about the same size as
        // the images).

        texObj->setMinFilter(GL_LINEAR);
        texObj->setMagFilter(GL_LINEAR);

        // Set the wrapping modes. We don't need repetition, it might actually
        // introduce artifactes at the borders, so switch it off.

        texObj->setWrapS(GL_CLAMP_TO_EDGE);
        texObj->setWrapT(GL_CLAMP_TO_EDGE);

        // Newer versions of OpenGL can handle NPOT textures directly.
        // OpenSG will do that internally automatically.
        //
        // Older versions need POT textures. By default OpenSG
        // will scale an NPOT texture to POT while defining it.
        // For changing textures that's too slow.
        // So tell OpenSG not to scale the image and adjust the texture
        // coordinates used by the TextureBackground (see below).

        texObj->setScale(false);

        // Create the background

        OSG::TextureBackgroundRefPtr back = OSG::TextureBackground::create();

        // Set the texture to use
        back->setTexture(texObj);

        // if the image is NPOT and we don't have hardware support for it
        // adjust the texture coordinates.
        if(isPOT == false && hasNPOT == false)
        {
            OSG::UInt32 potWidth  = OSG::osgNextPower2(width );
            OSG::UInt32 potHeight = OSG::osgNextPower2(height);

            OSG::Real32 tcRight = OSG::Real32(width ) / OSG::Real32(potWidth );
            OSG::Real32 tcTop   = OSG::Real32(height) / OSG::Real32(potHeight);

            back->editMFTexCoords()->push_back(OSG::Vec2f(    0.f,   0.f));
            back->editMFTexCoords()->push_back(OSG::Vec2f(tcRight,   0.f));
            back->editMFTexCoords()->push_back(OSG::Vec2f(tcRight, tcTop));
            back->editMFTexCoords()->push_back(OSG::Vec2f(    0.f, tcTop));
        }

        OSG::commitChanges();

        // create the SimpleSceneManager helper
        mgr = OSG::SimpleSceneManager::create();

        // tell the manager what to manage
        mgr->setWindow(gwin );
        mgr->setRoot  (scene);
        mgr->setStatistics(true);

        // replace the background
        // This has to be done after the viewport has been created, which the
        // SSM does in setRoot().

        OSG::ViewportRefPtr vp = gwin->getPort(0);

        vp->setBackground(back);
    }

    // show the whole scene
    mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;

}