Hello Keyan,

On 08/15/2012 04:33 AM, Keyan wrote:
thanks for the tip. Unfortunately it is still not working. The only difference 
that I see, is that I do not use the OSG::GLUTWindow::create() but 
OSG::PassiveWindow::create(). Could that be the problem?

ok, PassiveWindow should not make a difference [1]. I think at this point your best bet is to run under a debugger and put a breakpoint in SimpleTextForeground::draw() and see if it gets called at all or if it exists early before drawing anything.

        Cheers,
                Carsten

[1] I'm attaching a version that uses PassiveWindow. I had to make one additional change (call pwin->resize(300, 300)) in the beginning to pass the initial window size in. Glut apparently only calls the reshape function after rendering the first frame which for me caused an OpenGL error, because glOrtho was called with invalid arguments (left == right, top == bottom).
// 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 "OSGGLUT.h"
#include "OSGConfig.h"
#include "OSGSimpleGeometry.h"
#include "OSGPassiveWindow.h"
#include "OSGSimpleSceneManager.h"
#include "OSGAction.h"

// New Headers
#include "OSGSimpleTextForeground.h"

// the general scene file loading handler
#include "OSGSceneFileHandler.h"

#include "OSGFieldContainerUtils.h"


// The SimpleSceneManager to manage simple applications
OSG::SimpleSceneManagerRefPtr 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
    OSG::osgInit(argc,argv);

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

    {
        // the connection between GLUT and OpenSG
        OSG::PassiveWindowUnrecPtr pwin= OSG::PassiveWindow::create();
        // pwin->setGlutId(winid);
        pwin->init();
        pwin->resize(300, 300);
    
        OSG::SimpleTextForegroundUnrecPtr stf = OSG::SimpleTextForeground::create();
        stf->setColor(OSG::Color4f(0.5f, 0.5f, 0.5f, 1.f));
        stf->setFamily("SANS");
        stf->setHorizontalAlign(2);
        stf->setVerticalAlign(0);
        stf->addLine("Hello World");
        
        // load the scene
    
        OSG::NodeUnrecPtr scene;
        
        if(argc < 2)
        {
            FWARNING(("No file given!\n"));
            FWARNING(("Supported file formats:\n"));
            
            OSG::SceneFileHandler::the()->print();
            scene = OSG::makeTorus(.5, 2, 16, 16);
        }
        else
        {
            /*
                All scene file loading is handled via the SceneFileHandler.
            */
            scene = OSG::SceneFileHandler::the()->read(argv[1]);
        }
    
        //scene->dump();
    
        OSG::commitChanges();
    
        // create the SimpleSceneManager helper
        mgr = OSG::SimpleSceneManager::create();
        mgr->setUseTraversalAction(true);

        // tell the manager what to manage
        mgr->setWindow(pwin );
        mgr->setRoot  (scene);
        mgr->addForeground(stf);
    
        // show the whole scene
        mgr->showAll();  
        // mgr->useOpenSGLogo();
    }

    // GLUT main loop
    glutMainLoop();

    return 0;
}

//
// GLUT callback functions
//

// redraw the window
void display(void)
{
    mgr->idle();
    mgr->redraw();
    OSG::Thread::getCurrentChangeList()->clear();

    glutSwapBuffers();
}

// 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:
            mgr = NULL;

            OSG::osgExit();
            exit(0);
        break;
        case 'f':
            mgr->setNavigationMode(OSG::Navigator::FLY);
        break;
        case 't':
            mgr->setNavigationMode(OSG::Navigator::TRACKBALL);
        break;
        case 'q':
            mgr->setStatistics(true);
        break;
        case 'w':
            mgr->setStatistics(false);
        break;
        case 'h':
            mgr->setHeadlight(!mgr->getHeadlightState());
        break;
        case 'r':
        {
            bool useTrav = !mgr->getUseTraversalAction();
            mgr->setUseTraversalAction(useTrav);
            printf("Using %s action.\n", useTrav ? "render traversal" : "render");
        }
        break;
        
        case 'p':
        {
            std::cout << "Scanning memory consumption." << std::endl;
            OSG::MemoryConsumption mc;
            mc.scan();
            mc.print(std::cout);
        }
        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;
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to