November 3, 2010

ProgrammerAtHeart3344 ProgrammerAt..
Lab Rat
39 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

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

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

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