Skip to content

Game Development

What can we say - we like games. And you can use Qt to write some. Questions? Ask here.
862 Topics 4.0k Posts
  • QMaterial with just a rhi technique

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

    Unsolved
    3
    2 Votes
    3 Posts
    484 Views
    I

    @QtLukasz Looks interesting

  • 0 Votes
    5 Posts
    681 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
    260 Views
    No one has replied
  • 0 Votes
    5 Posts
    620 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
    738 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
    398 Views
    No one has replied
  • [Euler angles values are incorrect]

    Unsolved
    1
    0 Votes
    1 Posts
    308 Views
    No one has replied
  • 0 Votes
    3 Posts
    301 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
    401 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
    417 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
    807 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
    661 Views
    No one has replied
  • Dynamically changing mouse pointer speed/sensitivity

    Unsolved
    2
    0 Votes
    2 Posts
    362 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
    279 Views
    No one has replied
  • QT and 3D applications development(Game etc.).

    Unsolved
    4
    0 Votes
    4 Posts
    1k 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
    526 Views
    No one has replied
  • Qt 6.2.0, Qt3D. Cannot apply a texture to an object

    Unsolved
    1
    1 Votes
    1 Posts
    330 Views
    No one has replied
  • Qt 6.2.0, Qt3D. The COLLADA DAE model is darker than OBJ

    Unsolved
    3
    0 Votes
    3 Posts
    410 Views
    8Observer88

    Cube.dae

    <?xml version="1.0" encoding="utf-8"?> <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"> <asset> <contributor> <author>Blender User</author> <authoring_tool>Blender 2.76.0 commit date:2015-10-11, commit time:06:55, hash:48f7dd6</authoring_tool> </contributor> <created>2020-12-10T01:55:11</created> <modified>2020-12-10T01:55:11</modified> <unit name="meter" meter="1"/> <up_axis>Z_UP</up_axis> </asset> <library_images/> <library_effects> <effect id="BackgoundMaterial-effect"> <profile_COMMON> <technique sid="common"> <phong> <emission> <color sid="emission">0 0 0 1</color> </emission> <ambient> <color sid="ambient">0 0 0 1</color> </ambient> <diffuse> <color sid="diffuse">0.07052612 0.64 0.02013014 1</color> </diffuse> <specular> <color sid="specular">0.5 0.5 0.5 1</color> </specular> <shininess> <float sid="shininess">50</float> </shininess> <index_of_refraction> <float sid="index_of_refraction">1</float> </index_of_refraction> </phong> </technique> </profile_COMMON> </effect> <effect id="SideMaterial-effect"> <profile_COMMON> <technique sid="common"> <phong> <emission> <color sid="emission">0 0 0 1</color> </emission> <ambient> <color sid="ambient">0 0 0 1</color> </ambient> <diffuse> <color sid="diffuse">0.64 0.06314375 0.129652 1</color> </diffuse> <specular> <color sid="specular">0.5 0.5 0.5 1</color> </specular> <shininess> <float sid="shininess">50</float> </shininess> <index_of_refraction> <float sid="index_of_refraction">1</float> </index_of_refraction> </phong> </technique> </profile_COMMON> </effect> </library_effects> <library_materials> <material id="BackgoundMaterial-material" name="BackgoundMaterial"> <instance_effect url="#BackgoundMaterial-effect"/> </material> <material id="SideMaterial-material" name="SideMaterial"> <instance_effect url="#SideMaterial-effect"/> </material> </library_materials> <library_geometries> <geometry id="Cube-mesh" name="Cube"> <mesh> <source id="Cube-mesh-positions"> <float_array id="Cube-mesh-positions-array" count="24">1 1 -1 1 -1 -1 -1 -0.9999998 -1 -0.9999997 1 -1 1 0.9999995 1 0.9999994 -1.000001 1 -1 -0.9999997 1 -1 1 1</float_array> <technique_common> <accessor source="#Cube-mesh-positions-array" count="8" stride="3"> <param name="X" type="float"/> <param name="Y" type="float"/> <param name="Z" type="float"/> </accessor> </technique_common> </source> <source id="Cube-mesh-normals"> <float_array id="Cube-mesh-normals-array" count="36">0 0 -1 0 0 1 1 -5.96046e-7 3.27825e-7 -4.76837e-7 -1 0 -1 2.38419e-7 -1.19209e-7 2.08616e-7 1 0 0 0 -1 0 0 1 1 0 -2.38419e-7 0 -1 -4.76837e-7 -1 2.38419e-7 -1.49012e-7 2.68221e-7 1 2.38419e-7</float_array> <technique_common> <accessor source="#Cube-mesh-normals-array" count="12" stride="3"> <param name="X" type="float"/> <param name="Y" type="float"/> <param name="Z" type="float"/> </accessor> </technique_common> </source> <vertices id="Cube-mesh-vertices"> <input semantic="POSITION" source="#Cube-mesh-positions"/> </vertices> <polylist material="BackgoundMaterial-material" count="10"> <input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/> <input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/> <vcount>3 3 3 3 3 3 3 3 3 3 </vcount> <p>0 0 1 0 2 0 7 1 6 1 5 1 5 3 6 3 2 3 2 4 6 4 7 4 0 5 3 5 7 5 3 6 0 6 2 6 4 7 7 7 5 7 1 9 5 9 2 9 3 10 2 10 7 10 4 11 0 11 7 11</p> </polylist> <polylist material="SideMaterial-material" count="2"> <input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/> <input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/> <vcount>3 3 </vcount> <p>4 2 5 2 1 2 0 8 4 8 1 8</p> </polylist> </mesh> </geometry> </library_geometries> <library_controllers/> <library_visual_scenes> <visual_scene id="Scene" name="Scene"> <node id="Cube" name="Cube" type="NODE"> <matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix> <instance_geometry url="#Cube-mesh" name="Cube"> <bind_material> <technique_common> <instance_material symbol="BackgoundMaterial-material" target="#BackgoundMaterial-material"/> <instance_material symbol="SideMaterial-material" target="#SideMaterial-material"/> </technique_common> </bind_material> </instance_geometry> </node> </visual_scene> </library_visual_scenes> <scene> <instance_visual_scene url="#Scene"/> </scene> </COLLADA>

    Cube.obj

    # Blender v2.93.5 OBJ File: '' # www.blender.org mtllib Cube.mtl o Cube_Cube.001 v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 -1.000000 -1.000000 v 1.000000 1.000000 -1.000000 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 vn 0.0000 -1.0000 0.0000 vn 0.0000 1.0000 0.0000 vn -0.0000 0.0000 1.0000 vn -1.0000 -0.0000 0.0000 vn 0.0000 0.0000 -1.0000 vn 1.0000 0.0000 0.0000 usemtl BackgoundMaterial s off f 1//1 2//1 3//1 f 8//2 7//2 6//2 f 6//3 7//3 3//3 f 3//4 7//4 8//4 f 1//5 4//5 8//5 f 4//1 1//1 3//1 f 5//2 8//2 6//2 f 2//3 6//3 3//3 f 4//4 3//4 8//4 f 5//5 1//5 8//5 usemtl SideMaterial f 5//6 6//6 2//6 f 1//6 5//6 2//6

    Cube.mtl

    # Blender MTL File: 'None' # Material Count: 2 newmtl BackgoundMaterial Ns 225.000000 Ka 1.000000 1.000000 1.000000 Kd 0.070526 0.640000 0.020130 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2 newmtl SideMaterial Ns 225.000000 Ka 1.000000 1.000000 1.000000 Kd 0.640000 0.063144 0.129652 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2