Ogre's viewport wont update in real time



  • I'm not sure why but the viewports of Ogre don't update in realy time, i make a change then i have to resize the widget it's in to see the affect of the command.......Here's the class used for rendering/updating

    @#include "stdafx.h"
    #include "CRenderer.h"
    #include "qwidget.h"

    void CRenderer::clearViewport()
    {
    QColor Color2 = QColorDialog::getColor(Color,this);
    Ogre::ColourValue cv;
    cv.r = Color2.redF();
    cv.b = Color2.blueF();
    cv.g = Color2.greenF();
    cv.a = 1.0;
    this->m_pIViewport->setBackgroundColour(cv);
    }
    QPaintEngine* CRenderer::paintEngine() const
    {
    return 0;
    }

    void CRenderer::paintEvent(QPaintEvent* evt)
    {
    Ogre::Timer* time = m_pIRoot->getTimer();
    time->reset();
    Ogre::FrameEvent event;
    event.timeSinceLastFrame += time->getMillisecondsCPU();
    if(isInitialized)
    {

    Ogre::Root::getSingleton()._fireFrameStarted();
    m_pIRenderWindow->update(true);
    for (unsigned int X = 0; X < m_pIRenderWindow->getNumViewports(); ++X)
    {
    this->m_pIRenderWindow->getViewport(X)->update();
    }
    Ogre::Root::getSingleton()._fireFrameRenderingQueued();
    Ogre::Root::getSingleton()._fireFrameEnded();

    }

    }

    void CRenderer::resizeEvent(QResizeEvent* evt)
    {
    this->resize(this->parentWidget()->width(),this->parentWidget()->height());
    if (m_pIRenderWindow)
    {

    m_pIRenderWindow->resize(this->parentWidget()->width(),this->parentWidget()->height());
    m_pIRenderWindow->windowMovedOrResized();

    for (unsigned short X = 0; X < m_pIRenderWindow->getNumViewports(); ++X)
    {
    Ogre::Viewport* views = m_pIRenderWindow->getViewport(X);
    Ogre::Camera* cam = views->getCamera();
    cam->setAspectRatio(static_castOgre::Real(views->getActualWidth())/static_castOgre::Real(views->getActualHeight()));
    m_pIRenderWindow->_updateViewport(views);

    }
    }

    }
    bool CRenderer::DrawScene()
    {

    return true;

    }

    void CRenderer::mousePressEvent(QMouseEvent event)
    {
    Ogre::Entity
    Cube = m_pSceneMgr->getEntity("Ogre");
    Ogre::SceneNode* N = Cube->getParentSceneNode();

    if(event->buttons() & Qt::LeftButton)
    {
    m_pIRenderWindow->_beginUpdate();

    N->pitch(-Ogre::Degree(lastPos.rx()));
    N->yaw(-Ogre::Degree(lastPos.ry()));

    m_pIViewport->update();
    m_pIRenderWindow->_endUpdate();
    }

    }

    void CRenderer::mouseReleaseEvent(QMouseEvent *event)
    {

    }

    void CRenderer::mouseMoveEvent(QMouseEvent *event)
    {

    lastPos = event->pos();

    }

    void CRenderer::keyPressEvent(QKeyEvent *event)
    {

    if(event->key() == Qt::Key_A)
    {
    MessageBoxA(NULL,"","",MB_OK);
    }

    }

    void CRenderer::keyReleaseEvent(QKeyEvent *event)
    {

    }

    void CRenderer::contextMenuEvent(QContextMenuEvent *event)
    {

    }

    void CRenderer::focusInEvent(QFocusEvent *fevent)
    {
    if (fevent->gotFocus() && fevent->reason() == QFocusEvent::ActiveWindow)
    {
    m_pIRenderWindow->_beginUpdate();
    m_pIRenderWindow->setActive(true);
    m_pIViewport->update();
    m_pIRenderWindow->_endUpdate();
    }
    }

    @

    Yes, it's long...but if i can figure out how to fix it in this widget then making sure that the viewport updates in real time in all the other windows will be easy



  • Not sure if this helps, yet somewheres in your set up you should call, the startRendering method of the Root object. When and how is up to you. Without it, there is no trigger to repaint anything, unless an event forces a re-paint, i.e. when you change the size of the window screen.



  • I actually tried that and the program was unresponsive....



  • Aha. Then I've have to pass. I just getting into QT as a game engine. I did not see your second control QPaintEngine. One of the QT team should be able to respond. Or delete this thread, and rephrase the question using only QT controls.
    Another potential issue I see is that there is no 'visible statement' in your code snippet you posted, to link to QT's OpenGL support; <QGLWidget> . In other words, QT does not release ownership to Ogre renderer because it may not be able to read it fully.

    This is what the world really needs, a debugger that caters to gamers. :)



  • well, i asked on the Ogre forum and managed to get an answer, i had to call update() in paintEvent and it worked, the mesh still doesn't rotate smoothly though but it's a start



  • Thanks. I just wrote that down! Yes, ironic, me trying to help and getting answers instead. :D



  • well, that's how it is.......there's still a lot of work to do with it and i've found my self creating multiple windows and scene managers for each part, like a mat_mgr for material editing, blah blah



  • [quote author="Taamalus" date="1289060400"].... I just getting into QT as a game engine. I did not see your second control QPaintEngine. One of the QT team should be able to respond. Or delete this thread, and rephrase the question using only QT controls.
    Another potential issue I see is that there is no 'visible statement' in your code snippet you posted, to link to QT's OpenGL support; <QGLWidget> . In other words, QT does not release ownership to Ogre renderer because it may not be able to read it fully.[/quote]

    Taamalus, it should be Qt, QT is Quick Time :)



  • Hi,

    My name is hugo and i'm working on a adaptation of ogre3D engine
    using qt5 :
    http://advancingusability.wordpress.com/2013/03/30/how-to-integrate-ogre3d-into-a-qt5-qml-scene/

    I've post similar message in different forums

    http://www.ogre3d.org/forums/viewtopic.php?f=2&t=79649&p=499433#p499433

    My problem is very similar to yours. I 'm using a special version of QtOgre
    and I don't understand how to use or where to put my rendering
    loop...Because on this version the autor defined two method called
    activateOgrecontext and doneOgreContext which activate already the rendering
    process.
    But on this particulary point I don't understand how it works! Because there
    is no call to Node root->startRendering() or renderingqueue or something
    else....

    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);
    }

    when you want to draw something but only in initialisation you do :

    void ExampleApp::initialize()
    {

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

    // 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());

    }

    after read somme tutorial i've try to loop the rendering process :

    void ExampleApp::initialize()
    {

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

    // 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());

    }

    But my app freeze...

    Do you have an idea?



  • sorry for the presentation but I have no choice in type of presentation (texte , code ,....)

    :|



  • Last try!

    Hi,

    My name is hugo and i’m working on a adaptation of ogre3D engine
    using qt5 :
    http://advancingusability.wordpress.com/2013/03/30/how-to-integrate-ogre3d-into-a-qt5-qml-scene/

    I’ve post similar message in different forums

    http://www.ogre3d.org/forums/viewtopic.php?f=2&t=79649&p=499433#p499433

    My problem is very similar to yours. I ‘m using a special version of QtOgre
    and I don’t understand how to use or where to put my rendering
    loop…Because on this version the autor defined two method called
    activateOgrecontext and doneOgreContext which activate already the rendering
    process.
    But on this particulary point I don’t understand how it works! Because there
    is no call to Node root->startRendering() or renderingqueue or something
    else….
    @
    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); }
    @
    when you want to draw something but only in initialisation you do :
    @
    void ExampleApp::initialize()
    {
    // we only want to initialize once disconnect(this, &ExampleApp::beforeRendering, this, &ExampleApp::initializeOgre); // 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());

    }
    @
    after read somme tutorial i’ve try to loop the rendering process :

    @
    void ExampleApp::initialize() { // we only want to initialize once disconnect(this, &ExampleApp::beforeRendering, this, &ExampleApp::initializeOgre); // 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()); }
    @

    But my app freeze…

    Do you have an idea?



  • Your better off not using Qt at all in regards to a 3D Game Engine. I worked on it for years with developers from Irrlicht, Ogre3D, Horde3D, Gameplay3D, OSG, SFML2, .... and have even tried to assist commercial Game Engine developers (Leadwerks) . You will solve one problem with integration and expose ten other issues. The way Qt's abstraction and just in general its designed is bad for games or external 3d graphics engines.

    Qt5 makes the problem even worse.

    I won't go into it, because core Qt devs never listen and tempers just git heated. But if you want to know what the problems are do a google search.

    Without a huge amount of effort re-factoring some of Qt's core components like Autodesk or The Foundry had to do to get things to work out its not going to happen.

    Valve, Leadwerks, Gameplay, ... all just used Gtk.

    If you have the skills you would be even better off using ...

    Poco C++
    Boost
    Luajit and Luawrapper
    SFML2
    Bullet

    And OpenGL 4.3 or better
    http://ogldev.atspace.co.uk/index.html

    1. Drawing a pixel
    2. Triangle
    3. Shaders
    4. Uniform Variables
    5. Translation Transformation
    6. Rotation Transformation
    7. Scaling Transformation
    8. Interpolation
    9. Indexed Draws
    10. Concatenating Transformations
    11. Perspective Projection
    12. Camera Space
    13. Camera Control 1
    14. Camera Control 2
    15. Basic Texture Mapping
    16. Ambient Lighting
    17. Diffuse Lighting
    18. Specular Lighting
    19. Point Lighting
    20. Spot Lighting
    21. Loading Models with Assimp
    22. Shadow Mapping - Part 1
    23. Shadow Mapping - Part 2
    24. Skybox
    25. Normal Mapping
    26. Billboarding and Geometry Shaders
    27. Particle System Using Transform Feedback
    28. 3D Picking
    29. Basic Tessellation
    30. PN Triangle Tessellation
    31. Vertex Array Objects
    32. Instance Rendering
    33. GLFX - OpenGL Effects Library
    34. Deferred Shading - Part 1
    35. Deferred Shading - Part 2
    36. Deferred Shading - Part 3
    37. Skeletal Animation with Assimp
    38. Silhouette Detection
    39. Stencil Shadow Volume
    40. Object Motion Blur

    http://nopper.tv/norbert/opengl.html

    1. Rendering a Triangle
    2. Grey Filter
    3. Perspective Rendering a Cube
    4. Phong rendering of a sphere
    5. Texturing a Cube
    6. Normal Mapping
    7. Enviroment/cube mapping
    8. GPU Particles
    9. Geometry Shaders
    10. Reflection and Refraction
    11. Shadow Mapping
    12. Simple Tessellation
    13. Terrain Rendering
    14. Water Rendering
    15. Model Loading and Rendering
    16. Clipping Planes and two sided Rendering
    17. Using Stencil Buffer and Clipping
    18. Rendering to texture and planar reflection
    19. Texture matrix, alpha blending and discarding
    20. Compute Shaders
    21. Shadow Volumes
    22. Displacement Mapping
    23. Erode effect using perlin noise
    24. Model with groups and materials
    25. Fur rendering
    26. Projection shadow for directional lighting
    27. Screen Space Ambient Occlusion (SSAO)
    28. CPU ray tracing
    29. GPU ray tracing using computer shader.

    http://antongerdelan.net/opengl/index.html

    1. Hello Triangle
    2. Extended Initialisation
    3. Shaders
    4. Vertex Buffers
    5. Matrices and Vectors
    6. Virtual Camera
    7. Quaternion Quick-Start
    8. Ray-Based Picking
    9. Phong Lighting
    10. Texture Maps
    11. Importing a Mesh
    12. Multi-Texturing
    13. Using Textures for Light Coefficients
    14. Fragment Rejection
    15. Alpha Blending for Transparency
    16. Spotlights and Directional Lights
    17. Distance Fog
    18. Normal Mapping
    19. Cube Maps: Sky Boxes and Enviroment Mapping
    20. Geometry Shaders
    21. Tessellation Shaders
    22. Overlay Panels
    23. Sprite Sheets and 2D Animation
    24. Bitmap Fonts
    25. Vertex Displacement Animation
    26. Particle Systems
    27. Hardware Skinning
    28. Morph Target Animation
    29. Switching Framebuffer
    30. Image Processing with a Kernel
    31. Colour-Based Picking
    32. Deferred Shading
    33. Texture Projection Shadows

    http://www.opengl-tutorial.org/

    1. Opening a window
    2. The first triangle
    3. Matrices
    4. A Colored Cube
    5. A Textured Cube
    6. Keyboard and Mouse
    7. Model loading
    8. Basic shading
    9. VBO Indexing
    10. Transparency
    11. 2D text
    12. OpenGL Extensions
    13. Normal Mapping
    14. Render To Texture
    15. Lightmaps
    16. Shadow mapping
    17. Rotations
    18. Billboards & Particles
    19. Billboards - Particles / Instancing
    20. Picking with an OpenGL hack
    21. Picking with a physics library
    22. Picking with custom Ray-OBB function

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.