I have created a Testproject, with Qt5.4 where this is shown. It is based on the code of Egon Rath: http://www.matrix44.net/blog/?p=389
In this Example, I get 36 Fps, but if I add a texture to the cubes, the framerate drops by 10Fps. Adding one or two more different models, will drop the Framerate again.
main.cpp
Code: Select all
#include "testobjects.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TestObjects w;
w.show();
return a.exec();
}
Code: Select all
#pragma once
#include <QtWidgets/QMainWindow>
#include <QtCore/QTimer>
#include <irrlicht.h>
using namespace irr;
using namespace irr::video;
using namespace irr::core;
using namespace irr::scene;
class TestObjects : public QMainWindow
{
Q_OBJECT
public:
TestObjects(QWidget *parent = 0);
~TestObjects();
virtual void paintEvent(QPaintEvent *event);
virtual void resizeEvent(QResizeEvent *event);
virtual QPaintEngine * paintEngine() const;
public slots:
void onUpdateTimerTimeout();
private:
IrrlichtDevice *m_Device;
ISceneManager *m_Scene;
IVideoDriver *m_Driver;
QTimer* mpUpdateTimer;
void createIrrlichtDevice();
void buildIrrlichtScene();
void drawIrrlichtScene();
};
Code: Select all
#include "testobjects.h"
#include <QPushButton>
#include <QDebug>
TestObjects::TestObjects(QWidget *parent)
: QMainWindow(parent)
, m_Device(nullptr)
, m_Scene(nullptr)
, m_Driver(nullptr)
, mpUpdateTimer(new QTimer(this))
{
this->resize(640, 480);
this->setAttribute(Qt::WA_PaintOnScreen, true);
connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(onUpdateTimerTimeout()));
createIrrlichtDevice();
}
TestObjects::~TestObjects()
{
}
void TestObjects::createIrrlichtDevice()
{
dimension2d<u32> windowSize(this->geometry().width(), this->geometry().height());
qDebug() << "MainWindow::createIrrlichtDevice, width = " << windowSize.Width << " height = " << windowSize.Height;
SIrrlichtCreationParameters createParams;
createParams.WindowId = (void *) this->winId();
m_Device = createDeviceEx(createParams);
if (m_Device == 0)
qDebug() << "failed to create irrlicht device";
m_Driver = m_Device->getVideoDriver();
m_Scene = m_Device->getSceneManager();
buildIrrlichtScene();
}
void TestObjects::buildIrrlichtScene()
{
irr::scene::ICameraSceneNode* cam = m_Scene->addCameraSceneNode(0, vector3df(26.001, 20, 25), vector3df(25, 0, 25));
irr::scene::IMetaTriangleSelector* metaSelector = m_Device->getSceneManager()->createMetaTriangleSelector();
for (irr::f32 x = 0; x <= 49; x++){
for (irr::f32 z = 0; z <= 49; z++){
irr::scene::IMeshSceneNode* node = m_Device->getSceneManager()->addCubeSceneNode(1, 0, -1, irr::core::vector3df(x, 0, z), core::vector3df(0, 0, 0), core::vector3df(1, 1, 1));
//node->setMaterialTexture(0, m_Driver->getTexture("models/white.png"));
//node->setMaterialFlag(video::EMF_LIGHTING, false);
//node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
node->setMaterialFlag(video::EMF_FRONT_FACE_CULLING, false);
}
}
//irr::scene::IMeshSceneNode* node = m_Device->getSceneManager()->addCubeSceneNode(1, 0, -1, irr::core::vector3df(26, 0, 26), core::vector3df(0, 0, 0), core::vector3df(1, 1, 1));
ILightSceneNode *light = m_Scene->addLightSceneNode();
light->setLightType(ELT_DIRECTIONAL);
light->setRotation(vector3df(45.0f, 45.0f, 0.0f));
light->getLightData().AmbientColor = SColorf(0.2f, 0.2f, 0.2f, 1.0f);
light->getLightData().DiffuseColor = SColorf(0.8f, 0.8f, 0.8f, 1.0f);
mpUpdateTimer->setInterval(1);
mpUpdateTimer->start();
}
void TestObjects::paintEvent(QPaintEvent *event)
{
qDebug() << "MainWindow::paintEvent()";
drawIrrlichtScene();
}
void TestObjects::resizeEvent(QResizeEvent *event)
{
qDebug() << "MainWindow::resizeEvent()";
}
QPaintEngine * TestObjects::paintEngine() const
{
qDebug() << "MainWindow::paintEngine()";
return 0;
}
void TestObjects::drawIrrlichtScene()
{
//qDebug() << "MainWindow::drawIrrlichtScene()";
if (m_Device && m_Scene && m_Device)
{
m_Driver->beginScene(true, false, SColor(255, 128, 128, 128));
m_Scene->drawAll();
m_Driver->endScene();
core::stringw caption = L"";
caption += " FPS:";
caption += m_Driver->getFPS();
m_Device->setWindowCaption(caption.c_str());
}
}
void TestObjects::onUpdateTimerTimeout()
{
drawIrrlichtScene();
}