November 3, 2010

ProgrammerAtHeart3344 ProgrammerAt..
Lab Rat
44 posts

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

  1. #include "stdafx.h"
  2. #include "CRenderer.h"
  3. #include "qwidget.h"
  4.  
  5. void CRenderer::clearViewport()
  6. {
  7.  QColor Color2 = QColorDialog::getColor(Color,this);
  8.  Ogre::ColourValue cv;
  9.  cv.r = Color2.redF();
  10.  cv.b = Color2.blueF();
  11.  cv.g = Color2.greenF();
  12.  cv.a = 1.0;
  13.  this->m_pIViewport->setBackgroundColour(cv);
  14. }
  15. QPaintEngine* CRenderer::paintEngine() const
  16. {
  17.  return 0;
  18. }
  19.  
  20. void CRenderer::paintEvent(QPaintEvent* evt)
  21. {
  22.  Ogre::Timer* time = m_pIRoot->getTimer();
  23.  time->reset();
  24.  Ogre::FrameEvent event;
  25.  event.timeSinceLastFrame += time->getMillisecondsCPU();
  26.  if(isInitialized)
  27.  {
  28.  
  29.   Ogre::Root::getSingleton()._fireFrameStarted();
  30.   m_pIRenderWindow->update(true);
  31.   for (unsigned int X = 0; X < m_pIRenderWindow->getNumViewports(); ++X)
  32.   {
  33.    this->m_pIRenderWindow->getViewport(X)->update();
  34.   }
  35.   Ogre::Root::getSingleton()._fireFrameRenderingQueued();
  36.   Ogre::Root::getSingleton()._fireFrameEnded();
  37.  
  38.  
  39.  }
  40.  
  41. }
  42.  
  43. void CRenderer::resizeEvent(QResizeEvent* evt)
  44. {
  45.  this->resize(this->parentWidget()->width(),this->parentWidget()->height());
  46.  if (m_pIRenderWindow)
  47.  {
  48.  
  49.   m_pIRenderWindow->resize(this->parentWidget()->width(),this->parentWidget()->height());
  50.   m_pIRenderWindow->windowMovedOrResized();
  51.  
  52.   for (unsigned short X = 0; X < m_pIRenderWindow->getNumViewports(); ++X)
  53.   {
  54.    Ogre::Viewport* views = m_pIRenderWindow->getViewport(X);
  55.    Ogre::Camera* cam = views->getCamera();
  56.    cam->setAspectRatio(static_cast<Ogre::Real>(views->getActualWidth())/static_cast<Ogre::Real>(views->getActualHeight()));
  57.    m_pIRenderWindow->_updateViewport(views);
  58.  
  59.   }
  60.  }
  61.  
  62. }
  63. bool CRenderer::DrawScene()
  64. {
  65.  
  66.  
  67.  return true;
  68.  
  69.  
  70. }
  71.  
  72. void CRenderer::mousePressEvent(QMouseEvent *event)
  73. {
  74.  Ogre::Entity* Cube = m_pSceneMgr->getEntity("Ogre");
  75.  Ogre::SceneNode* N = Cube->getParentSceneNode();
  76.  
  77.  
  78.  
  79.  if(event->buttons() & Qt::LeftButton)
  80.  {
  81.   m_pIRenderWindow->_beginUpdate();
  82.  
  83.   N->pitch(-Ogre::Degree(lastPos.rx()));
  84.   N->yaw(-Ogre::Degree(lastPos.ry()));
  85.  
  86.   m_pIViewport->update();
  87.   m_pIRenderWindow->_endUpdate();
  88.  }
  89.  
  90.  
  91.  
  92. }
  93.  
  94. void CRenderer::mouseReleaseEvent(QMouseEvent *event)
  95. {
  96.  
  97. }
  98.  
  99. void CRenderer::mouseMoveEvent(QMouseEvent *event)
  100. {
  101.  
  102.  lastPos = event->pos();
  103.  
  104.  
  105. }
  106.  
  107. void CRenderer::keyPressEvent(QKeyEvent *event)
  108. {
  109.  
  110.   if(event->key() == Qt::Key_A)
  111.   {
  112.    MessageBoxA(NULL,"","",MB_OK);
  113.   }
  114.  
  115.  
  116. }
  117.  
  118. void CRenderer::keyReleaseEvent(QKeyEvent *event)
  119. {
  120.  
  121. }
  122.  
  123. void CRenderer::contextMenuEvent(QContextMenuEvent *event)
  124. {
  125.  
  126. }
  127.  
  128. void CRenderer::focusInEvent(QFocusEvent *fevent)
  129. {
  130.  if (fevent->gotFocus() && fevent->reason() == QFocusEvent::ActiveWindow)
  131.  {
  132.   m_pIRenderWindow->_beginUpdate();
  133.   m_pIRenderWindow->setActive(true);
  134.   m_pIViewport->update();
  135.   m_pIRenderWindow->_endUpdate();
  136.  }
  137. }

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

11 replies

November 5, 2010

Taamalus Taamalus
Lab Rat
61 posts

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.

 Signature 

... time waits for no one. - Henry

November 6, 2010

ProgrammerAtHeart3344 ProgrammerAt..
Lab Rat
44 posts

I actually tried that and the program was unresponsive….

November 6, 2010

Taamalus Taamalus
Lab Rat
61 posts

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. :)

 Signature 

... time waits for no one. - Henry

November 6, 2010

ProgrammerAtHeart3344 ProgrammerAt..
Lab Rat
44 posts

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

November 6, 2010

Taamalus Taamalus
Lab Rat
61 posts

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

 Signature 

... time waits for no one. - Henry

November 7, 2010

ProgrammerAtHeart3344 ProgrammerAt..
Lab Rat
44 posts

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

November 7, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts
Taamalus wrote:
…. 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.

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

December 5, 2013

hugox hugox
Lab Rat
3 posts

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?

December 5, 2013

hugox hugox
Lab Rat
3 posts

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

:|

December 5, 2013

hugox hugox
Lab Rat
3 posts

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….

  1. Ogre::Root* OgreEngine::startEngine()
  2. { m_resources_cfg = “resources.cfg;
  3. 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; }

  1. void OgreEngine::activateOgreContext()
  2. { glPopAttrib(); glPopClientAttrib();
  3. m_qtContext->functions()->glUseProgram(0); m_qtContext->doneCurrent(); m_ogreContext->makeCurrent(m_quickWindow); }
  4.  
  5. void OgreEngine::doneOgreContext()
  6. { 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);
  7. // 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 :
  1. void ExampleApp::initialize()
  2. {
  3. // 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());
  4.  
  5. }

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

  1. 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?

December 14, 2013

zester zester
Lab Rat
89 posts

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 33. Instance Rendering 34. GLFX – OpenGL Effects Library 35. Deferred Shading – Part 1 26. Deferred Shading – Part 2 27. Deferred Shading – Part 3 28. Skeletal Animation with Assimp 29. Silhouette Detection 30. Stencil Shadow Volume 31. 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

 
  ‹‹ Qt Quick Game Programming      How to parametrize Phonon::Effects ››

You must log in to post a reply. Not a member yet? Register here!