I want to send all Irrlicht frames to a Qml item, this Qml item, receives a QImage as argument, the QImage is fixed size always, the arguments of QImage are:
QImage(unsinned char * image_pixels, int width, int height, int bytesPerLine, Format format)
I found some examples of integrating Irrlicht and Qt, but always drawing the scene en the window background.
http://www.matrix44.net/blog/?p=389
This is the code Im using to test this feature, but without Qml, I'm sending the frames to a QLabel.
Code: Select all
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <irrlicht/irrlicht.h>
using namespace irr;
using namespace irr::video;
using namespace irr::core;
using namespace irr::scene;
namespace Ui
{
class MainWindow;
}
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
// This is the widget Im using to draw my offscreen scene.
QWidget offscreen;
QTimer timer;
IrrlichtDevice *device;
IVideoDriver *driver;
ISceneManager *smgr;
ITexture *offscreen_texture;
ICameraSceneNode* user_eyes;
IAnimatedMesh *mesh;
IAnimatedMeshSceneNode *node;
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void show_frame();
};
#endif // MAINWINDOW_H
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtDebug>
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
offscreen.resize(640, 480);
// If offscreen is not visible the scene is not rendered, but this must be hiden :(
offscreen.show();
SIrrlichtCreationParameters createParams;
createParams.WindowId = (void *)offscreen.winId();
createParams.DriverType = EDT_OPENGL;
device = createDeviceEx(createParams);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
// Setup some nodes for the test.
mesh = smgr->getMesh("media/sydney.md2");
node = smgr->addAnimatedMeshSceneNode( mesh );
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("media/sydney.bmp") );
// Setup user view.
user_eyes = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
// The scene is rendered every 1 msec.
timer.setInterval(1);
connect(&timer, SIGNAL(timeout()), this, SLOT(show_frame()));
timer.start();
}
MainWindow::~MainWindow()
{
device->drop();
delete ui;
}
void MainWindow::show_frame()
{
driver->beginScene(true, false, SColor(255, 127, 127, 191));
smgr->setActiveCamera(user_eyes);
smgr->drawAll();
driver->endScene();
// Here I'm convert from IImage to QImage;
IImage *image = driver->createScreenShot();
QImage qimage((uchar *)image->lock(), offscreen.width(), offscreen.height(), 3 * offscreen.width(), QImage::Format_RGB888);
// Then it is showed in QLabel
QPixmap pixmap;
pixmap.convertFromImage(qimage);
ui->lblScene->setPixmap(pixmap);
}
![Sad :(](./images/smilies/icon_sad.gif)
Then, How I can create QImage from Irrlicht frames?
Thanks in advance.