Hi,

to ensure the correct ordering of rendering stages (e.g. SimpleStage), I have been attaching the stages that need to be executed first as children of the stages that need to be executed later on. This works for SimpleStages so far, but now I require the same with an AlgorithmStage, but when attaching a SimpleStage to an AlgorithmStage, the child is not visited. Is there any way to ensure the children of an AlgorithmStage are visited, or another way to ensure execution order is maintained? A simple example is attached.

Regards

--
Johannes S. Mueller-Roemer, MSc
Wiss. Mitarbeiter - Interactive Engineering Technologies (IET)

Fraunhofer-Institut für Graphische Datenverarbeitung IGD
Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
Tel +49 6151 155-606  |  Fax +49 6151 155-139
johannes.mueller-roe...@igd.fraunhofer.de  |  www.igd.fraunhofer.de

#pragma warning(push)
#pragma warning(disable:4244)
#pragma warning(disable:4231)
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGCallbackAlgorithm.h>
#include <OpenSG/OSGAlgorithmStage.h>
#include <OpenSG/OSGSimpleStage.h>
#include <OpenSG/OSGRenderBuffer.h>
#include <OpenSG/OSGTextureObjChunk.h>
#include <OpenSG/OSGTextureBuffer.h>
#include <OpenSG/OSGSolidBackground.h>
#include <OpenSG/OSGVisitSubTree.h>

#include <OpenSG/OSGPolygonForeground.h>
#pragma warning(pop)

#define STRINGIFY(A) #A

OSG::SimpleSceneManager *mgr = 0;
OSG::TextureObjChunk *fboTex = 0;
OSG::Image *fboImg = 0;
OSG::FrameBufferObject *fbo = 0;
OSG::GLUTWindow *gwin = 0;

int setupGLUT( int *argc, char *argv[] );

void drawCallback(OSG::DrawEnv *env)
{
        GLuint texId = 0;
        if(fboTex && gwin)
                texId = gwin->getGLObjectId(fboTex->getGLId());

        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();

        glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT);

        glDisable(GL_DEPTH_TEST);
        glDepthMask(false);

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texId);

        glBegin(GL_QUADS);
        glTexCoord2f( 0.f, 0.f);
        glVertex2f  (-1.f,-1.f);
        glTexCoord2f( 1.f, 0.f);
        glVertex2f  ( 1.f,-1.f);
        glTexCoord2f( 1.f, 1.f);
        glVertex2f  ( 1.f, 1.f);
        glTexCoord2f( 0.f, 1.f);
        glVertex2f  (-1.f, 1.f);
        glEnd();

        glPopAttrib();

        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
}

#define ATTACH_FBO_TO_ALGO

int main(int argc, char **argv)
{
    OSG::osgInit(argc,argv);

    int winid = setupGLUT(&argc, argv);

    {
        OSG::GLUTWindowRefPtr gwin_ = OSG::GLUTWindow::create();
                gwin = gwin_;
        gwin->setGlutId(winid);
        gwin->init();

                int width = gwin->getWidth(), height = gwin->getHeight();

                OSG::NodeRefPtr torus = OSG::makeTorus(.25, 1., 64, 128);

                OSG::ImageRefPtr fboImg_ = OSG::Image::create();
                fboImg = fboImg_;
                fboImg->set(OSG::Image::OSG_RGBA_PF, width, height, 1, 1, 1, 
0., 0, OSG::Image::OSG_UINT8_IMAGEDATA);

                OSG::TextureObjChunkRefPtr fboTex_ = 
OSG::TextureObjChunk::create();
                fboTex = fboTex_;
                fboTex->setImage(fboImg);
                fboTex->setMinFilter(GL_LINEAR);
                fboTex->setMagFilter(GL_LINEAR);

                OSG::TextureBufferRefPtr fboC = OSG::TextureBuffer::create();
                fboC->setTexture(fboTex);

                OSG::RenderBufferRefPtr fboZ  = OSG::RenderBuffer::create();
                fboZ->setInternalFormat(GL_DEPTH_COMPONENT24);

                OSG::FrameBufferObjectRefPtr fbo_ = 
OSG::FrameBufferObject::create();
                fbo = fbo_;
                fbo->setColorAttachment(fboC, 0);
                fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
                fbo->setDepthAttachment(fboZ);
                fbo->setWidth(width);
                fbo->setHeight(height);

                OSG::SolidBackgroundRefPtr bg = OSG::SolidBackground::create();
                bg->setColor(OSG::Color3f(1.f,0.f,0.f));
                bg->setAlpha(1.f);

                OSG::SimpleStageRefPtr fboStage = OSG::SimpleStage::create();
                fboStage->setRenderTarget(fbo);
                fboStage->setSize(0.0f, 0.0f, 1.0f, 1.0f);
                fboStage->setBackground(bg);

                OSG::NodeRefPtr fboStageNode = OSG::makeNodeFor(fboStage);
                fboStageNode->addChild(torus);

                OSG::CallbackAlgorithmRefPtr algo = 
OSG::CallbackAlgorithm::create();
                algo->setCallback(&drawCallback, "");

                OSG::AlgorithmStageRefPtr algoStage = 
OSG::AlgorithmStage::create();
                algoStage->setAlgorithm(algo);

                OSG::NodeRefPtr algoStageNode = OSG::makeNodeFor(algoStage);

                OSG::NodeRefPtr sceneRoot = OSG::makeCoredNode<OSG::Group>();
                sceneRoot->addChild(algoStageNode);
#ifdef ATTACH_FBO_TO_ALGO
                algoStageNode->addChild(fboStageNode);
#else
                sceneRoot->addChild(fboStageNode);
#endif

        mgr = new OSG::SimpleSceneManager;
        mgr->setWindow(gwin);
        mgr->setRoot(sceneRoot);
                mgr->getBackground()->editClearColor() = false;
        mgr->showAll();

                fboStage->setCamera(mgr->getCamera());

                OSG::commitChanges();
    }

    glutMainLoop();

    return 0;
}

void display(void)
{
    mgr->redraw();
}

void reshape(int w, int h)
{
    mgr->resize(w, h);
        fboImg->set(OSG::Image::OSG_RGBA_PF, w, h, 1, 1, 1, 0., 0, 
OSG::Image::OSG_UINT8_IMAGEDATA);
        fbo->setWidth(w);
        fbo->setHeight(h);
    glutPostRedisplay();
}

void mouse(int button, int state, int x, int y)
{
        if(button > 2)
                return;

    if(state)
        mgr->mouseButtonRelease(button, x, y);
    else
        mgr->mouseButtonPress(button, x, y);
        
    glutPostRedisplay();
}

void motion(int x, int y)
{
    mgr->mouseMove(x, y);
    glutPostRedisplay();
}

void keyboard(unsigned char k, int x, int y)
{
    switch(k)
    {
        case 27:
        {
            delete mgr;
        
            OSG::osgExit();
            exit(0);
        }
        break;

        case 's':
        {
            mgr->setStatistics(!mgr->getStatistics());
        }
        break;
    }
}

int setupGLUT(int *argc, char *argv[])
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    int winid = glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    return winid;
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to