Irrlicht Qt-widget in Linux

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
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Irrlicht Qt-widget in Linux

Post by Digan »

I wrote own Qt - widget for irrlicht.

In Windows, all is OK.

In Linux irrlicht - log display the following text:
Irrlicht Engine version 1.7.2
Linux 2.6.32-24-generic #39-Ubuntu SMP Wed Jul 28 06:07:29 UTC 2010 i686
Creating X window...
Visual chosen: : 209
X Error: BadWindow (invalid Window parameter)
From call : X_CreateWindow
X Error: BadWindow (invalid Window parameter)
From call : X_GetWindowAttributes
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreateGC
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreateGC
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_GetGeometry
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_GetGeometry
X Error: BadWindow (invalid Window parameter)
From call : X_GetProperty
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreatePixmap
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreatePixmap
Using renderer: OpenGL 2.1
Software Rasterizer: Mesa Project
OpenGL driver version is 1.2 or better.
GLSL version: 1.2
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreateGC
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PolyFillRectangle
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PolyFillRectangle
X Error: BadPixmap (invalid Pixmap parameter)
From call : X_CreateCursor
X Error: BadGC (invalid GC parameter)
From call : X_FreeGC
X Error: BadPixmap (invalid Pixmap parameter)
From call : X_FreePixmap
X Error: BadPixmap (invalid Pixmap parameter)
From call : X_FreePixmap
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_GetGeometry
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_GetGeometry
X Error: BadCursor (invalid Cursor parameter)
From call : X_ChangeWindowAttributes
It turned out that this is due to create a device:

Code: Select all

    SIrrlichtCreationParameters params;
    params.DriverType = EDT_OPENGL;
    params.WindowId = reinterpret_cast<void*>(winId());
    params.WindowSize.Width = width();
    params.WindowSize.Height = height();

    device = createDeviceEx(params);
Without:

Code: Select all

params.WindowId = reinterpret_cast<void*>(winId());
errors in log is not.
But irrlicht - window is not created in my widget.

Problem with winId() in Linux?

Best regard
Digan
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Did you create an opengl window?
zester
Competition winner
Posts: 52
Joined: Sun May 01, 2011 6:50 am

Post by zester »

You need to upgrade to a newer version of Qt4. That is a know bug on linux. I think 4.6, 4.7.0 and 4.7.1 are all effected. Try the newest version Qt 4.7.3.
And yes it is a problem with winid, it doesn't give the correct window id, If I remember correctly it just returns 0 as the windows id.
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Post by Digan »

hybrid wrote:Did you create an opengl window?
Yes.

Code: Select all

...
params.DriverType = EDT_OPENGL;
...
device = createDeviceEx(params);
zester wrote:You need to upgrade to a newer version of Qt4. That is a know bug on linux. I think 4.6, 4.7.0 and 4.7.1 are all effected. Try the newest version Qt 4.7.3.
And yes it is a problem with winid, it doesn't give the correct window id, If I remember correctly it just returns 0 as the windows id.
Thanks. I tried the newest version Qt 4.7.3.

winId() now do not return 0.

I tried wrote the following code:

Code: Select all

    SIrrlichtCreationParameters params;
    params.DriverType = EDT_OPENGL;
    params.WindowId = reinterpret_cast<void*>(winId());

    qDebug() << "widget ID " << showbase << hex << winId();
    qDebug() << "win ID " << params.WindowId;

    params.WindowSize.Width = width();
    params.WindowSize.Height = height();

    device = createDeviceEx(params);
Received the message:

Code: Select all

widget ID  0x460001b 
win ID  0x460001b 
But on widget nothing. And again in the log the error messages.

Can look at my code?

Pro-file:

Code: Select all

QT       += core gui

TARGET = irrWidget
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    qirrwidget.cpp

HEADERS  += mainwindow.h \
    qirrwidget.h

FORMS    += mainwindow.ui

LIBS += -L/home/digan/irrdev/irrlicht/lib/Linux -lIrrlicht -lGL -lXext -lX11
INCLUDEPATH += /home/digan/irrdev/irrlicht/include
qirrwidget.cpp

Code: Select all

#include "qirrwidget.h"
#include <QDebug>

QirrWidget::QirrWidget(QWidget *parent) :
    QWidget(parent)
{
    device = 0;

    driverType = EDT_OPENGL;
}

QirrWidget::~QirrWidget()
{
    if ( device != 0 )
    {
        device->closeDevice();
        device->drop();
    }
}

void QirrWidget::init()
{
    if ( device != 0 )
        return;

    SIrrlichtCreationParameters params;
    params.DriverType = EDT_OPENGL;
    params.WindowId = reinterpret_cast<void*>(winId());

    qDebug() << "widget ID " << showbase << hex << winId();
    qDebug() << "win ID " << params.WindowId;

    params.WindowSize.Width = width();
    params.WindowSize.Height = height();

    device = createDeviceEx(params);

    if(device)
        camera = device->getSceneManager()->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));


    setAttribute(Qt::WA_OpaquePaintEvent);

    connect(this, SIGNAL(updateIrrlichtQuery(IrrlichtDevice*)), this, SLOT(updateIrrlicht(IrrlichtDevice*)));


    startTimer(0);
}

IrrlichtDevice* QirrWidget::getIrrlichtDevice()
{
    return device;
}

void QirrWidget::paintEvent(QPaintEvent* event)
{
    if ( device != 0 )
    {
        emit updateIrrlichtQuery(device);
    }
}

void QirrWidget::timerEvent(QTimerEvent* event)
{
    if ( device != 0 )
    {
        emit updateIrrlichtQuery(device);
    }

    event->accept();
}

void QirrWidget::resizeEvent(QResizeEvent* event)
{
    if ( device != 0 )
    {
        dimension2d<u32> widgetSize;
        widgetSize.Width = event->size().width();
        widgetSize.Height = event->size().height();
        device->getVideoDriver()->OnResize(widgetSize);

        ICameraSceneNode *cam = device->getSceneManager()->getActiveCamera();
        if (cam != 0)
        {
            cam->setAspectRatio( (f32)widgetSize.Height / (f32)widgetSize.Width );
        }
    }

    QWidget::resizeEvent(event);
}

void QirrWidget::updateIrrlicht( irr::IrrlichtDevice* device )
{
    if(device != 0)
    {
        device->getTimer()->tick();

        SColor color (255,100,101,140);

        device->getVideoDriver()->beginScene(true, true, color);

            device->getSceneManager()->drawAll();

        device->getVideoDriver()->endScene();
    }

}
mainwindow.cpp

Code: Select all

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    irrWidget.setParent(ui->centralWidget);
    irrWidget.setGeometry(160, 0, 630, 480);
}

MainWindow::~MainWindow()
{
    delete ui;
}

main.cpp

Code: Select all

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    w.irrWidget.init();

    ISceneManager *smgr = w.irrWidget.getIrrlichtDevice()->getSceneManager();
    IVideoDriver *driver = w.irrWidget.getIrrlichtDevice()->getVideoDriver();

    IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2");
    if (!mesh)
    {
        w.irrWidget.getIrrlichtDevice()->drop();
        return 1;
    }

    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture("media/sydney.bmp") );
    }

    return a.exec();
}
Thanks.
Image
Digan
Posts: 16
Joined: Tue Aug 24, 2010 11:21 am

Post by Digan »

The problem is solved in the following code:

Code: Select all

setAttribute(Qt::WA_PaintOnScreen);
Image
Post Reply