Frame Listener in QMLOgre Lib Freeze Window

Problems building or running the engine, queries about how to use features etc.
Post Reply
antho130
Gnoblar
Posts: 1
Joined: Wed Dec 04, 2013 3:03 pm

Frame Listener in QMLOgre Lib Freeze Window

Post by antho130 »

Hello,

What we have to do in order to add a frame listener in qmlogre lib? Because if I try to set :

Code: Select all

m_ogreEngine = new OgreEngine(this);
m_root = m_ogreEngine->startEngine();
m_ogreEngine->setupResources();

m_ogreEngine->activateOgreContext();
//pRenderWindow=m_ogreEngine->getRenderWindow();

createScene();
createFrameListener();

// renderingLoop
m_root->startRendering();

while(true)
{
 Ogre::WindowEventUtilities::messagePump();

  if(pRenderWindow->isClosed())
    std::cout<<"pRenderWindow close"<renderOneFrame())
  std::cout<<"root renderOneFrame"<doneOgreContext();
  emit(ogreInitialized());
and use the frame listener i ‘ve defined, my Ogre window freezes…
Do I realy need to use and defined a frame listener or can i use ogreitem to repaint my scene with new element?

thanks!
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: Frame Listener in QMLOgre Lib Freeze Window

Post by scrawl »

startRendering is a render loop itself, so the loop below never gets executed.
hugox
Gnoblar
Posts: 6
Joined: Wed Dec 04, 2013 5:30 pm

Re: Frame Listener in QMLOgre Lib Freeze Window

Post by hugox »

Ok This is why the application was freezing!

I have the same pb!

But how do i use a framelistener if i can not put the :

Code: Select all


m_root->startRendering();

//createScene();
    while(true)
   {
       Ogre::WindowEventUtilities::messagePump();

       if(pRenderWindow->isClosed())
           std::cout<<"pRenderWindow close"<<std::endl;

       if(!m_root->renderOneFrame())
           std::cout<<"root renderOneFrame"<<std::endl;
   }

?

I don't know if you have ever seen how it works so i will also post the code of startengine develped in the libogreqml:


Code: Select all

OgreEngine::OgreEngine(QQuickWindow *window)
    : QObject(),
      m_resources_cfg(Ogre::StringUtil::BLANK)
{
    qmlRegisterType<OgreItem>("Ogre", 1, 0, "OgreItem");
    qmlRegisterType<OgreEngine>("OgreEngine", 1, 0, "OgreEngine");

    setQuickWindow(window);
}

OgreEngine::~OgreEngine()
{
    delete m_ogreContext;
}



Ogre::Root* OgreEngine::startEngine()
{
    m_resources_cfg = "resources.cfg";

    activateOgreContext();

    Ogre::Root *ogreRoot = new Ogre::Root;
    Ogre::RenderSystem *renderSystem = ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
    ogreRoot->setRenderSystem(renderSystem);
    ogreRoot->initialise(false);

    Ogre::NameValuePairList params;

    params["externalGLControl"] = "true";
    params["currentGLContext"] = "true";

    //Finally create our window.
    m_ogreWindow = ogreRoot->createRenderWindow("OgreWindow", 1, 1, false, &params);
    m_ogreWindow->setVisible(false);
    m_ogreWindow->update(false);

    doneOgreContext();

    return ogreRoot;

void OgreEngine::activateOgreContext()
{
    glPopAttrib();
    glPopClientAttrib();

    m_qtContext->functions()->glUseProgram(0);
    m_qtContext->doneCurrent();

    m_ogreContext->makeCurrent(m_quickWindow);
}

void OgreEngine::doneOgreContext()
{
    m_ogreContext->functions()->glBindBuffer(GL_ARRAY_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    m_ogreContext->functions()->glBindRenderbuffer(GL_RENDERBUFFER, 0);
    m_ogreContext->functions()->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);

    // unbind all possible remaining buffers; just to be on safe side
    m_ogreContext->functions()->glBindBuffer(GL_ARRAY_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_COPY_READ_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_COPY_WRITE_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
//    m_ogreContext->functions()->glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
//    m_ogreContext->functions()->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_TEXTURE_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
    m_ogreContext->functions()->glBindBuffer(GL_UNIFORM_BUFFER, 0);

    m_ogreContext->doneCurrent();

    m_qtContext->makeCurrent(m_quickWindow);
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
}


}

void OgreEngine::stopEngine(Ogre::Root *ogreRoot)
{
    if (ogreRoot) {
//        m_root->detachRenderTarget(m_renderTexture);
        // TODO tell node(s) to detach

    }

    delete ogreRoot;
}

void OgreEngine::setQuickWindow(QQuickWindow *window)
{
    Q_ASSERT(window);

    m_quickWindow = window;
    m_qtContext = QOpenGLContext::currentContext();

    // create a new shared OpenGL context to be used exclusively by Ogre
    m_ogreContext = new QOpenGLContext();
    m_ogreContext->setFormat(m_quickWindow->requestedFormat());
    m_ogreContext->setShareContext(m_qtContext);
    m_ogreContext->create();
}







When you want to draw something in Ogre you use:

Code: Select all

void ExampleApp::initialize()
{

    // we only want to initialize once
    disconnect(this, &ExampleApp::beforeRendering, this, &ExampleApp::initializeOgre);


    cout<<"initializeOgre3DCASE"<<endl;

    // start up Ogre
    m_ogreEngine = new OgreEngine(this);
    m_root = m_ogreEngine->startEngine();
    m_ogreEngine->setupResources();

  
     m_ogreEngine->activateOgreContext();


//draw a small cube
 new DebugDrawer(m_sceneManager, 0.5f);
     DrawCube(100,100,100);
     DebugDrawer::getSingleton().build();



    m_ogreEngine->doneOgreContext();
    emit(ogreInitialized());

}



so basicaly, when i read the tutorial i've try:

Code: Select all

void ExampleApp::initializeOgre3DCASE()
{

    // we only want to initialize once
    disconnect(this, &ExampleApp::beforeRendering, this, &ExampleApp::initializeOgre);


    cout<<"initializeOgre3DCASE"<<endl;

    // start up Ogre
    m_ogreEngine = new OgreEngine(this);
    m_root = m_ogreEngine->startEngine();
    m_ogreEngine->setupResources();

    pRenderWindow=m_ogreEngine->getRenderWindow();




    //initialisation  we create a first scene and the frame listener
    m_ogreEngine->activateOgreContext();
    createScene();
    createFrameListener();
    m_ogreEngine->doneOgreContext();
    emit(ogreInitialized());






    m_ogreEngine->activateOgreContext();

    if(!m_root->renderOneFrame())
        std::cout<<"root renderOneFrame"<<std::endl;


    // La Boucle de rendu
    m_root->startRendering();

//createScene();
    while(true)
   {
       Ogre::WindowEventUtilities::messagePump();

       if(pRenderWindow->isClosed())
           std::cout<<"pRenderWindow close"<<std::endl;

       if(!m_root->renderOneFrame())
           std::cout<<"root renderOneFrame"<<std::endl;
   }



    m_ogreEngine->doneOgreContext();
    emit(ogreInitialized());

}



I've try many things but I'm stucked!

I don't understand what I have to do to communicate with the rendering thread and so where i put the while loop?


Thanks!
Post Reply