Trouble getting Ogre window to display properly.
-
I've been trying to follow tutoria;ls and experiment setting up Ogre with QtGUI but i've run into some problems.
first, the Widget is like 100x30 no matter what size i make it, and i find it funny that if i pick Direct3D9 renderer i get openGL if i pick OpenGL i get D3D9.........
Here's the output of the window when i run the program:!http://fc04.deviantart.net/fs70/i/2010/289/6/7/lol2_by_programmer3344-d30w1bn.jpg(This is what appears)!
now here is my code for it:
Header:
@
#ifndef CRENDERER_H
#define CRENDERER_H#include <Ogre.h>
#include <QtGui/QWidget>#if defined(_DEBUG)
#pragma comment(lib,"OgreMain_d.lib")
#else
#pragma comment(lib,"OgreMain.lib")
#endif
using namespace Ogre;class CRenderer : public QWidget
{
public:
CRenderer(QWidget* win);~CRenderer();
void createRenderer(Ogre::String rendererName);
void DrawScene();
private:
QWidget* m_pWindow;
QString dims;Root* m_pIRoot;
RenderWindow* m_pIRenderWindow;
Camera* m_pICamera;
Viewport* m_pIViewport;
SceneManager* m_pSceneMgr;Ogre::String m_pIResources;
Ogre::String m_pIPlugins;Ogre::String m_pILog;
};
@
Souce:
@
#include "CRenderer.h"CRenderer::CRenderer(QWidget* win)
: QWidget(win)
{
this->m_pWindow = win;
}CRenderer::~CRenderer()
{}
void CRenderer::createRenderer(Ogre::String rendererName)
{
#if defined(_DEBUG)
this->m_pIPlugins = "Irrational_Plugins_d.cfg";
this->m_pILog = "Engine_log_d.log";
#else
this->m_pIPlugins = "Irrational_Plugins.cfg";
m_pILog = "Engine_log.log";
#endifm_pIRoot = new Root(this->m_pIPlugins,"Engine.cfg",this->m_pILog);
#if defined(_DEBUG)
this->m_pIResources = "Engine_resources_d.cfg";
#else
this->m_pIResources = "Engine_resources.cfg";
#endifConfigFile cf;
cf.load(this->m_pIResources);Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
Ogre::String secName,
typeName,
archName;while(seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}RenderSystemList rList = m_pIRoot->getAvailableRenderers();
RenderSystemList::iterator i = rList.begin();
RenderSystem* RenderSys;
while (i != rList.end())
{
RenderSys = (*i++);if(RenderSys->getName().find(rendererName))
{
m_pIRoot->setRenderSystem(RenderSys);
}}
if(RenderSys == 0)
{
delete m_pIRoot;
MessageBoxA(NULL,"No render system detected","ERROR",MB_OK | MB_ICONINFORMATION);
return;
}
this->dims = QString("%1x%2").arg(this->m_pWindow->width()).arg(this->m_pWindow->height());RenderSys->setConfigOption("Video Mode", dims.toStdString());
RenderSys->setConfigOption("Full Screen", "No");
m_pIRoot->saveConfig();m_pIRoot->initialise(false);
Ogre::String WinHandle;
WinHandle += StringConverter::toString((unsigned int)(this->m_pWindow->winId()));Ogre::NameValuePairList pList;
pList["externalWindowHandle"] = WinHandle;
this->m_pIRenderWindow = m_pIRoot->createRenderWindow("The Irrational Engine v1.0",
m_pWindow->width(),
m_pWindow->height(),
false,
&pList);WId OWindow = 0x0;
m_pIRenderWindow->getCustomAttribute("WINDOW",&OWindow);this->create(OWindow);
m_pIRenderWindow->resize(this->m_pWindow->width(),
this->m_pWindow->height());
setAttribute(Qt::WA_PaintOnScreen,true);
setAttribute(Qt::WA_NoBackground);Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(10);
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
this->m_pSceneMgr = m_pIRoot->createSceneManager(ST_GENERIC,"Main");
this->m_pICamera = m_pSceneMgr->createCamera("Main Camera");
m_pICamera->setPosition(0,0,500);
m_pICamera->lookAt(0,0,0);this->m_pIViewport = m_pIRenderWindow->addViewport(m_pICamera);
this->m_pIViewport->setBackgroundColour(ColourValue::Blue);
m_pIRenderWindow->setActive(true);
m_pIRenderWindow->update();}
void CRenderer::DrawScene()
{
m_pIRoot->renderOneFrame();
}@
How i'm calling this class:
@
CRenderer* Win = new CRenderer(w.getCentral());
try
{
Win->createRenderer("OpenGL");
}
catch(Ogre::Exception &e)
{
MessageBoxA(NULL,e.getFullDescription().c_str(),"",MB_OK);
}Win->DrawScene();
w.show();
@
hopefully someone can help me other wise i'll ask on the Ogre3D forum, i'm not sure if this is an Ogre problem or a QT4 widget problem (Meaning i might not know how to set it up\ right, which is possible......)