qt 5 + irrlicht(Please, I need urgent help)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
fdgonzalez
Posts: 7
Joined: Wed Mar 07, 2012 2:27 pm

qt 5 + irrlicht(Please, I need urgent help)

Post by fdgonzalez »

I'm trying to make a level editor as http://www.ambiera.com/irredit/
but I can not embed irrlicht within a 5 qt window.
Searching the web I really liked the idea of implementing a Widget but the example is done in qt 4.8 and I have done everything possible to port it to Qt 5, but not successful.
I've tried everything in my power and that I fail. If anyone can help me, I will thank a lot. I do not speak English, sorry if I have any errors.
jiangcaiyang
Posts: 9
Joined: Tue Nov 12, 2013 3:24 pm

Re: qt 5 + irrlicht(Please, I need urgent help)

Post by jiangcaiyang »

Here is a code snippet showing something I guess you want.
http://www.qtcn.org/bbs/read-htm-tid-54915-page-e.html
fdgonzalez
Posts: 7
Joined: Wed Mar 07, 2012 2:27 pm

Re: qt 5 + irrlicht(Please, I need urgent help)

Post by fdgonzalez »

Thanks for the help. That's really what I was looking for. The example is very good but I had a problem when I try the example in Ubuntu 12.04 an qt 4.8. When you draw the object, it comes and goes. If I could solve this problem would be what I want. I've tried but nothing.
This is my code:

main.cpp
#include <QtGui/QApplication>
#include "qirrlichtwidget.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QIrrlichtWidget q;
q.show();


return a.exec();
}



qirrlichtwidget.h

#ifndef QIRRLICHTWIDGET_H
#define QIRRLICHTWIDGET_H

#include <QtGui>
#include <irrlicht.h>



using namespace irr;
using namespace irr::video;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::io;




class QIrrlichtWidget : public QWidget
{
Q_OBJECT
public:
explicit QIrrlichtWidget(QWidget *parent = 0);

protected:
virtual void paintEvent( QPaintEvent * );
virtual void timerEvent(QTimerEvent *);

private:
void createIrrlichtDevice();
void buildIrrlichtScene();
void drawIrrlichtScene();

IrrlichtDevice* device;
ISceneManager* sceneManager;
IVideoDriver* videoDriver;
SColor bgColor;

};

#endif // QIRRLICHTWIDGET_H



qirrlichtwidget.cpp

QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) :
QWidget(parent)
{
createIrrlichtDevice();
startTimer(0);
}

void QIrrlichtWidget::paintEvent(QPaintEvent *)
{
drawIrrlichtScene();
qDebug()<<"paintEvent";
}

void QIrrlichtWidget::timerEvent(QTimerEvent *)
{
if ( device != 0 )
{
update();
}
}

void QIrrlichtWidget::createIrrlichtDevice()
{
dimension2d<u32> windowSize( this->geometry().width(), this->geometry().height() );


qDebug() << "QIrrlicht::createIrrlichtDevice, width = " << windowSize.Width << " height = " << windowSize.Height;


SIrrlichtCreationParameters createParams;
createParams.WindowId = ( void * ) this->winId();
createParams.AntiAlias = 1;
createParams.DriverType = EDT_OPENGL;
createParams.Bits = 16;
createParams.DriverMultithreaded = true;
createParams.IgnoreInput = false;
createParams.HighPrecisionFPU = true;
createParams.Vsync = false;
createParams.Stencilbuffer = false;
device = createDeviceEx( createParams );
if( device == 0 )
qDebug() << "failed to create irrlicht device";


device->setResizable(true);
videoDriver = device->getVideoDriver();
sceneManager = device->getSceneManager();


buildIrrlichtScene();
drawIrrlichtScene();
}

void QIrrlichtWidget::buildIrrlichtScene()
{
IAnimatedMesh* mesh = sceneManager->getMesh("media/sydney.md2");
sceneManager->loadScene("media/example.irr");
sceneManager->addCameraSceneNode(0, vector3df(0, 30, -40), vector3df(0, 5, 0));
IAnimatedMeshSceneNode* node = sceneManager->addAnimatedMeshSceneNode(mesh);
if(node ) {
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMaterialTexture(0, videoDriver->getTexture("media/sydney.bmp"));
node->setPosition(vector3df(20,0,10));
node->setScale(vector3df(0.5,0.5,0.5));
node->setRotation(vector3df(0,90,0));
}
}

void QIrrlichtWidget::drawIrrlichtScene()
{
device->getTimer()->tick();
videoDriver->beginScene( true, true, bgColor);
sceneManager->drawAll();
videoDriver->endScene();
}
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: qt 5 + irrlicht(Please, I need urgent help)

Post by zerochen »

hi,

i dont know qt but i m pretty much sure that you have to put drawIrrlichtScene(); in a loop are maybe something like a draw callback from qt that is called every frame.

regards
zerochen

edit:oh nevermind... i didnt see it
Last edited by zerochen on Sat Nov 16, 2013 12:47 pm, edited 1 time in total.
jiangcaiyang
Posts: 9
Joined: Tue Nov 12, 2013 3:24 pm

Re: qt 5 + irrlicht(Please, I need urgent help)

Post by jiangcaiyang »

Try to fix like this:
Add "update();" after "drawIrrlichtScene();" in paintEvent().
fdgonzalez
Posts: 7
Joined: Wed Mar 07, 2012 2:27 pm

Re: qt 5 + irrlicht(Please, I need urgent help)

Post by fdgonzalez »

Ican't fix this problem. Some other idea about I can do world editor in qt. I want to make an editor in qt creator to use the visual components of this framework, but I can not embed irrlicht within a qt window correctly. Any idea how to do it?
fdgonzalez
Posts: 7
Joined: Wed Mar 07, 2012 2:27 pm

Re: qt 5 + irrlicht(Please, I need urgent help)

Post by fdgonzalez »



Last bumped by fdgonzalez on Fri Dec 20, 2013 5:15 am.
Post Reply