Skip to content

Game Development

What can we say - we like games. And you can use Qt to write some. Questions? Ask here.
830 Topics 4.0k Posts
  • SFML to Qt...

    Unsolved
    9
    0 Votes
    9 Posts
    3k Views
    BondrusiekB

    I did many games in Qt/C++ which can be alse created in SFML. If you want to see: https://forum.qt.io/topic/137223/simple-qt-c-games

  • QMaterial with just a rhi technique

    Unsolved
    1
    0 Votes
    1 Posts
    164 Views
    No one has replied
  • Another 2D Game

    Unsolved
    3
    2 Votes
    3 Posts
    370 Views
    I

    @QtLukasz Looks interesting

  • 0 Votes
    5 Posts
    419 Views
    K

    I found out what was the problem:

    The Window, which hosts the layout in which the 3D Widget is set, contains the following statement in the constructor:

    setWindowState(windowState() | Qt::WindowMaximized);

    or..

    setWindowState(Qt::WindowMaximized);

    I removed this statement and the 3D Window now shows the content.

    This is not happening in the Linux build!

    Now, both builds work correctly.

    Issue is solved.

  • Qt3D example using QSkeleton QArmature?

    Unsolved
    1
    0 Votes
    1 Posts
    184 Views
    No one has replied
  • 0 Votes
    5 Posts
    368 Views
    B

    @JonB You’re right, Thanks, QGraphicsItemGroup did the trick. I just needed to set the transform origin point to the centre of the red rectangle. Now the desired effect is achieved by this code:

    #include "game.h" #include <QGraphicsItemGroup> QGraphicsItemGroup* g = new QGraphicsItemGroup; Game::Game() { player = new QGraphicsRectItem(); rectItem = new QGraphicsRectItem(); m_view = new QGraphicsView(this); m_view->setSceneRect(QRectF(0,0,800,600)); this->setBackgroundBrush(Qt::black); m_view->setScene(this); m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); m_view->setViewportUpdateMode(QGraphicsView::NoViewportUpdate); m_view->show(); player->setRect(0,0,100,100); player->setBrush(Qt::red); player->setPos(400,300); player->setFocus(); rectItem->setRect(0,0,100,100); rectItem->setBrush(Qt::green); rectItem->setPos(400,330); this->addItem(g); player->setZValue(10); rectItem->setZValue(1); g->addToGroup(player); g->addToGroup(rectItem); g->setTransformOriginPoint(player->pos().x() + player->boundingRect().width()/2 ,player->pos().y() + player->boundingRect().height()/2); } void Game::advance() { } void Game::keyPressEvent(QKeyEvent *event) { switch(event->key()) { case Qt::Key_Left : g->moveBy(-5,0); break; case Qt::Key_Right : g->moveBy(5,0); break; case Qt::Key_Up : g->moveBy(0,-5); break; case Qt::Key_Down : g->moveBy(0,5); break; case Qt::Key_Q : g->setRotation(g->rotation()- 3); break; case Qt::Key_W : g->setRotation(g->rotation() +3); break; } update(); }
  • Qt3D - [c++] Q: How to activate shadow mapping

    Unsolved
    6
    0 Votes
    6 Posts
    476 Views
    BondrusiekB

    @kevin_d
    I dont know this topic well but recommend you see : https://doc.qt.io/qt-6/qsgmaterialshader-graphicspipelinestate.html
    or use some environments like ie

    qputenv("QT3D_GLSL100_WORKAROUND", "");

    The qputenv("QT3D_GLSL100_WORKAROUND", "") instruction is a workaround related to Qt3D
    shaders on some embedded Linux devices, such as the Raspberry Pi. It will enable a separate
    GLSL 1.00 snippet for the lights required by some embedded devices.
    Maybe you must see this kind of variables.

  • 0 Votes
    1 Posts
    289 Views
    No one has replied
  • [Euler angles values are incorrect]

    Unsolved
    1
    0 Votes
    1 Posts
    247 Views
    No one has replied
  • 0 Votes
    3 Posts
    198 Views
    K

    Finally the scene gets properly rendered by explicietely setting the QSortPolicy on the frameGraph:

    Qt3DRender::QFrameGraphNode *framegraph = view.activeFrameGraph(); Qt3DRender::QSortPolicy *sortPolicy = new Qt3DRender::QSortPolicy(scene); framegraph->setParent(sortPolicy); QVector<Qt3DRender::QSortPolicy::SortType> sortTypes = QVector<Qt3DRender::QSortPolicy::SortType>() << Qt3DRender::QSortPolicy::BackToFront; sortPolicy->setSortTypes(sortTypes); view.setActiveFrameGraph(framegraph);
  • High CPU usage

    Unsolved
    4
    0 Votes
    4 Posts
    2k Views
    J

    @Darksorrow said in High CPU usage:

    If i can't figure this out i think i'll go back to use OpenGL directly >.<

    I have the same problem>.<!
    Any good results?

  • 0 Votes
    3 Posts
    215 Views
    K

    If you like to have a look on how the scene-loader works with nested objects and materials, have a look on the topic:

    https://forum.qt.io/topic/134729/q-qt3d-c-apply-qmaterial-on-a-loaded-obj-file/3

  • How to animate chracter ?

    Unsolved
    3
    0 Votes
    3 Posts
    269 Views
    8Observer88

    Sprite animation using QPainter:

    You can download the "sprites-cat-running.png" sprite sheet here: https://plnkr.co/edit/zjYT0KTfj50MejT9?preview

    main.cpp

    #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtGui/QPainter> #include <QtGui/QImage> #include <QtCore/QTimer> #include <QtCore/QElapsedTimer> #include <QtCore/QDebug> #define N_FRAMES 8 class Window : public QWidget { Q_OBJECT public: Window() { setWindowTitle("Qt C++"); resize(512, 256); // Download a sprite sheet here: // https://plnkr.co/edit/zjYT0KTfj50MejT9?preview m_spriteSheet.load(":/Sprites/sprites-cat-running.png"); int index = 0; for (int i = 0; i < 2; i++ ) { for (int j = 0; j < 4; j++) { m_frames[index] = QPoint(j * m_sw, i * m_sh); qDebug() << m_frames[index]; index++; } } connect(&m_timer, &QTimer::timeout, this, &Window::animationLoop); m_timer.start(1000.f/60.f); m_elapsedTimer.start(); } private: QTimer m_timer; QElapsedTimer m_elapsedTimer; float m_deltaTime; float m_animationTime = 0.f; const float m_animationSpeed = 100.f; QImage m_spriteSheet; QPoint m_frames[N_FRAMES]; int m_frameIndex = 0; int m_x, m_y; const int m_sw = 512, m_sh = 256; // Source image width and height private slots: void animationLoop() { m_deltaTime = m_elapsedTimer.elapsed(); m_elapsedTimer.restart(); m_animationTime += m_deltaTime; if (m_animationTime > m_animationSpeed) { m_animationTime = 0; m_x = m_frames[m_frameIndex].x(); m_y = m_frames[m_frameIndex].y(); m_frameIndex++; if (m_frameIndex >= N_FRAMES) { m_frameIndex = 0; } } update(); } private: void paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter qp(this); qp.drawImage(0, 0, m_spriteSheet, m_x, m_y, m_sw, m_sh); } }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); Window w; w.show(); return a.exec(); }

    a302b780-34ce-4ae6-9219-ad76c844ee66.gif

  • Q: Qt3D - [c++] Apply QMaterial on a loaded obj file

    Solved
    3
    0 Votes
    3 Posts
    543 Views
    K

    I am very happy now. All the materials work.
    There were two problems:

    1.) Never reuse material references. Always create a new material which apply to the individual object.

    2.) The assignment of materials don't work recursively. As in http://man.hubwiz.com/docset/Qt_5.docset/Contents/Resources/Documents/doc.qt.io/qt-5/qt3drender-qsceneloader.html, it needs to traverse through the complete entities-tree of the loader, eg. with the SceneWalker, referenced here: https://code.qt.io/cgit/qt/qt3d.git/tree/tests/manual/assimp-cpp/main.cpp and assign the material to all entities found.

    Code here:

    void SceneWalker::walk(Qt3DCore::QEntity *ent, int depth) { // get entity in entities ... // apply material to entity // call walk recursively } void Scene::loadAndApply() { QPhongAlphaMaterial *_material= new QPhongAlphaMaterial; _material->setDiffuse(QColor(100,100,200)); [...] SceneWalker *sceneWalker = new SceneWalker(_material); QObject::connect(loader, &Qt3DRender::QSceneLoader::statusChanged, [sceneWalker, loader](Qt3DRender::QSceneLoader::Status status) { if (status = Qt3DRender::QSceneLoader::Ready) sceneWalker->onStatusChanged(loader); } entity->addComponent(loader); }

    best regards

  • 0 Votes
    1 Posts
    513 Views
    No one has replied
  • Dynamically changing mouse pointer speed/sensitivity

    Unsolved
    2
    0 Votes
    2 Posts
    250 Views
    SGaistS

    Hi and welcome to devnet,

    IIRC, you should rather implement a "virtual pointer" so that you have complete control on it rather than trying to modify your system settings from within your application.

  • macos:: can't find QVulkanInstance

    Unsolved
    1
    0 Votes
    1 Posts
    207 Views
    No one has replied
  • QT and 3D applications development(Game etc.).

    Unsolved
    3
    0 Votes
    3 Posts
    794 Views
    8Observer88

    I study Godot. I like this engine. It uses signal/slot like Qt. The GDScript language is very similar to Python. If you use PyQt5 a long time then GDScript will be easy for you. But I like study Qt C++ by making simple games with WebSockets (Godot supports WebSockets too). I like to study OpenGL and GLSL. Vulkan is not supported by my video card. You can use OpenGL not for simple games by for drawing something like diagrams, plots, some nongame 3D-stuff and you have full controls with OpenGL and you study computer graphics. Writing your little games engines in Qt OpenGL is useful for your education.

    This book is good:

    Game Programming using Qt 5 Beginner's Guide: Create amazing games with Qt 5, C++, and Qt Quick, 2nd Edition This is a code for the book: https://github.com/PacktPublishing/Game-Programming-Using-Qt-5-Beginners-Guide-Second-Edition
  • 0 Votes
    1 Posts
    457 Views
    No one has replied
  • Qt 6.2.0, Qt3D. Cannot apply a texture to an object

    Unsolved
    1
    1 Votes
    1 Posts
    252 Views
    No one has replied