Embedding Ogre i en qt applikation på Windows platform

Indlæg af Hanne Mølgaard Plasc

Problem



Embedding Ogre i en qt ansøgning
Link: QtOgre [3]


Men det er Mac og Linux platform, jeg forsøger at migrere til Windows platform, men mislykkedes.
Min app løber sådan:
Indtast billedbeskrivelse her


enter code here
#ifndef OGREWIDGET\_H
#define OGREWIDGET\_H
#include "XVQCUGLLIB\_Global.h"
#include <QGLWidget>
#include <Ogre/Ogre.h>


class XVQCUGLFXLIB\_API OgreWidget : public QGLWidget
{
    //Q\_OBJECT;

public:
    OgreWidget( QWidget *parent=0 );
    virtual ~OgreWidget();

protected:
     virtual void initializeGL();
    virtual void resizeGL( int, int );
    virtual void paintGL();

    void init();

    virtual Ogre::RenderSystem* chooseRenderer( Ogre::RenderSystemList* );

    Ogre::Root *mOgreRoot;
    Ogre::RenderWindow *mOgreWindow;
    Ogre::Camera *mCamera;
    Ogre::Viewport *mViewport;
    Ogre::SceneManager *mSceneMgr;
};
#endif // OGREWIDGET\_H


///////////////////////////////////////


  #include "XVQCUGLLIB\_Internal.h"

 #include "OgreWidget.h"
 #define THIS OgreWidget

 OgreWidget::OgreWidget(QWidget *parent)
     : QGLWidget( parent ),
     mOgreWindow(NULL)
 {
     init();
 }

 OgreWidget::~OgreWidget()
 {
     mOgreRoot->shutdown();
     delete mOgreRoot;
     destroy();
 }

 /**
  * @brief init the object
  * @author kito berg-taylor
  */
      void THIS::init()
      {
   // create the main ogre object
   mOgreRoot = new Ogre::Root;

   mOgreRoot->loadPlugin("RenderSystem\_GL\_d");
   Ogre::String rName("OpenGL Rendering Subsystem");
   Ogre::RenderSystemList rList = mOgreRoot->getAvailableRenderers();
   Ogre::RenderSystemList::iterator it = rList.begin();
   Ogre::RenderSystem *rSys = 0;
   while(it != rList.end())
   {
       rSys = * (it++);
       Ogre::String strx=rSys->getName();
       if(strx == rName)
       {
           mOgreRoot->setRenderSystem(rSys);
           break;
       }
   }
   mOgreRoot->initialise(false); // don't create a window
 }

 /**
  * @brief setup the rendering context
  * @author Kito Berg-Taylor
  */
 void THIS::initializeGL()
 {

   //== Creating and Acquiring Ogre Window ==//

   // Get the parameters of the window QT created

   Ogre::String winHandle=Ogre::StringConverter::toString((size\_t)(HWND)winId());

   Ogre::NameValuePairList params;
   params["parentWindowHandle"] = winHandle;

   mOgreWindow = mOgreRoot->createRenderWindow( "QOgreWidget\_RenderWindow",
                            this->width(),
                            this->height(),
                            false,
                            &params );

   //mOgreWindow->setActive(true);
   //WId ogreWinId = 0x0;
   //mOgreWindow->getCustomAttribute( "WINDOW", &ogreWinId );

   //assert( ogreWinId );

   //this->create( ogreWinId );
   setAttribute( Qt::WA\_PaintOnScreen, true );
   setAttribute( Qt::WA\_NoBackground );

   //== Ogre Initialization ==//
   Ogre::SceneType scene\_manager\_type = Ogre::ST\_EXTERIOR\_CLOSE;

   mSceneMgr = mOgreRoot->createSceneManager( scene\_manager\_type );
   mSceneMgr->setAmbientLight( Ogre::ColourValue(1,1,1) );

   mCamera = mSceneMgr->createCamera( "QOgreWidget\_Cam" );
   mCamera->setPosition( Ogre::Vector3(0,1,0) );
   mCamera->lookAt( Ogre::Vector3(0,0,0) );
   mCamera->setNearClipDistance( 1.0 );

   Ogre::Viewport *mViewport = mOgreWindow->addViewport( mCamera );
   mViewport->setBackgroundColour( Ogre::ColourValue( 1.0,1.0,1.0 ) );
 }

 /**
  * @brief render a frame
  * @author Kito Berg-Taylor
  */
 void THIS::paintGL()
 {
     //QGLWidget::paintGL();
   assert( mOgreWindow );


   mOgreRoot->\_fireFrameStarted();

  mOgreWindow->update();

  // mOgreRoot->renderOneFrame();

   mOgreRoot->\_fireFrameEnded();
 }

 /**
  * @brief resize the GL window
  * @author Kito Berg-Taylor
  */
 void THIS::resizeGL( int width, int height )
 {
//QGLWidget::resizeGL(width,height);
   assert( mOgreWindow );
   mOgreWindow->windowMovedOrResized();
   mCamera->setAspectRatio(Ogre::Real(width) / Ogre::Real(height));
 }

 /**
  * @brief choose the right renderer
  * @author Kito Berg-Taylor
  */
 Ogre::RenderSystem* THIS::chooseRenderer( Ogre::RenderSystemList *renderers )
 {
   // It would probably be wise to do something more friendly 
   // that just use the first available renderer
   return *renderers->begin();
 }

Bedste reference


Ringer du initialiserGL () hvor som helst?


IIRC skal du udtrykkeligt kalde det - det sker ikke automatisk

Andre referencer 1


Over ride QWidget :: resizeEvent () metode. Ved denne metode modtager du underretninger om ændringer i vinduets størrelse. Ændre størrelsen på vinduet ogre.