Skip to content

Game Development

What can we say - we like games. And you can use Qt to write some. Questions? Ask here.
875 Topics 4.1k Posts
  • [Euler angles values are incorrect]

    Unsolved
    1
    0 Votes
    1 Posts
    384 Views
    No one has replied
  • Qt3D - [c++] QExtrudedTextMesh gets overlayed by lower QCuboidMesh

    Solved
    3
    0 Votes
    3 Posts
    464 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?
  • Qt3D - [c++] SetEnabled is loosing objects after some time

    Solved
    3
    0 Votes
    3 Posts
    552 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
    598 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(); } [image: a0070bc5-b7a7-44e1-8a96-a501949ee756.gif]
  • Q: Qt3D - [c++] Apply QMaterial on a loaded obj file

    Solved
    3
    0 Votes
    3 Posts
    1k 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
    780 Views
    No one has replied
  • Dynamically changing mouse pointer speed/sensitivity

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

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

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

    Unsolved
    3
    0 Votes
    3 Posts
    591 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
  • 0 Votes
    2 Posts
    737 Views
    8Observer88
    When I wrote this question I understood the answer. I forgot to add activation of second video of my laptop at the beginning of main.cpp: #ifdef _WIN32 #include <windows.h> extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; #endif
  • Can someone Interpret texture methods and/or uniforms into QT OpenGL

    Unsolved
    2
    0 Votes
    2 Posts
    472 Views
    8Observer88
    @AI_Messiah said in Can someone Interpret texture methods and/or uniforms into QT OpenGL: if there is no equivalent method is there some kind of work around? Why do you use SOIL with Qt? Qt can load textures by itself: #include <QtGui/QOpenGLTexture> /* ... */ m_texture.create(); m_texture.setData(QImage(":/Textures/WornBrownBrickwork_256.png")); m_texture.setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); m_texture.setWrapMode(QOpenGLTexture::ClampToEdge); Example: // Add this line to .pro: // win32: LIBS += -lopengl32 #ifdef _WIN32 #include <windows.h> extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; #endif #include <QtWidgets/QApplication> #include <QtWidgets/QOpenGLWidget> #include <QtGui/QOpenGLShaderProgram> #include <QtGui/QOpenGLBuffer> #include <QtGui/QOpenGLTexture> #include <QtGui/QMatrix4x4> class Widget : public QOpenGLWidget { Q_OBJECT public: Widget() : m_texture(QOpenGLTexture::Target2D) { setWindowTitle("OpenGL 3.3. Qt C++"); resize(400, 400); } private: QOpenGLShaderProgram m_program; QOpenGLBuffer m_vertPosBuffer; QOpenGLBuffer m_texCoordBuffer; QOpenGLTexture m_texture; QMatrix4x4 m_mvpMatrix; QMatrix4x4 m_projMatrix; QMatrix4x4 m_viewMatrix; QMatrix4x4 m_modelMatrix; int m_uMvpMatrixLocation; const float WORLD_HEIGHT = 50; void initializeGL() override { glClearColor(0.5f, 0.5f, 0.5f, 1.0f); const char *vertShaderSrc = "#version 330 core\n" "in vec3 aPosition;" "in vec2 aTexCoord;" "uniform mat4 uMvpMatrix;" "out vec2 vTexCoord;" "void main()" "{" " gl_Position = uMvpMatrix * vec4(aPosition, 1.0);" " vTexCoord = aTexCoord;" "}"; const char *fragShaderSrc = "#version 330 core\n" "uniform sampler2D uSampler;" "in vec2 vTexCoord;" "out vec4 fragColor;" "void main()" "{" " fragColor = texture2D(uSampler, vTexCoord);" "}"; m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, vertShaderSrc); m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, fragShaderSrc); m_program.link(); m_program.bind(); float vertPositions[] = { -0.5f, -0.5f, 0.f, 0.5f, -0.5f, 0.f, -0.5f, 0.5f, 0.f, 0.5f, 0.5f, 0.f }; float texCoords[] = { 0.f, 1.f, 1.f, 1.f, 0.f, 0.f, 1.f, 0.f }; initVertexBuffer(m_vertPosBuffer, vertPositions, sizeof(vertPositions), "aPosition", 0, 3); initVertexBuffer(m_texCoordBuffer, texCoords, sizeof(texCoords), "aTexCoord", 1, 2); m_texture.create(); m_texture.setData(QImage(":/Textures/WornBrownBrickwork_256.png")); m_texture.setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); m_texture.setWrapMode(QOpenGLTexture::ClampToEdge); m_program.bind(); m_uMvpMatrixLocation = m_program.uniformLocation("uMvpMatrix"); m_modelMatrix.scale(QVector3D(50.f, 50.f, 1.f)); m_viewMatrix.lookAt(QVector3D(0.f, 0.f, 40.f), QVector3D(0.f, 0.f, 0.f), QVector3D(0.f, 1.f, 0.f)); } void paintGL() override { glClear(GL_COLOR_BUFFER_BIT); m_mvpMatrix = m_projMatrix * m_viewMatrix * m_modelMatrix; m_program.bind(); m_program.setUniformValue(m_uMvpMatrixLocation, m_mvpMatrix); m_texture.bind(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } void resizeGL(int w, int h) override { glViewport(0, 0, w, h); float aspect = (float) w / h; float worldWidth = aspect * WORLD_HEIGHT; m_projMatrix.setToIdentity(); m_projMatrix.ortho(-worldWidth / 2.f, worldWidth / 2.f, -WORLD_HEIGHT / 2.f, WORLD_HEIGHT / 2.f, 50.f, -50.f); } void initVertexBuffer(QOpenGLBuffer &buffer, float data[], int amount, const char *locationName, int locationIndex, int tupleSize) { buffer.create(); buffer.bind(); buffer.allocate(data, amount); m_program.bindAttributeLocation(locationName, locationIndex); m_program.setAttributeBuffer(locationIndex, GL_FLOAT, 0, tupleSize); m_program.enableAttributeArray(locationIndex); } }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }
  • How to rotate/flip a texture in Qt3d C++

    Unsolved
    4
    0 Votes
    4 Posts
    708 Views
    kshegunovK
    Either draw the texture rotated with QPaintedTextureImage or generate it rotated beforehand. I see no other way.
  • Qt3d Sample "basicshapes-cpp" run with -platform eglfs

    Unsolved
    1
    0 Votes
    1 Posts
    353 Views
    No one has replied
  • Hundreds of thousands of points

    Unsolved
    16
    0 Votes
    16 Posts
    2k Views
    SGaistS
    Does your item have a geometry ? If none, then there's no reason for its paint method to be called.
  • Qt creator and joystick. QtGamepad

    Unsolved
    8
    0 Votes
    8 Posts
    4k Views
    8Observer88
    Example: Joystick test application (Qt + SFML) [Windows/Linux] This example was written in Qt4 but you can run it in Qt5. You need to and "widgets" here: QT += core gui widgets. And replace this line #include <QtGui/QApplication> to this #include <QtWidgets/QApplication> in main.cpp I built the demo: QtJoystick-SFML-exe.zip (7.39 MB) Source Code for Qt5: Source_QtJoystick-SFML.zip (235 KB) I tested this example. It works with PS2 controller and USB converter: [image: be61e3a8-bc06-429d-910f-d4385b14c6ba.png]
  • How to get text input from user and set that text on a 3d object?

    Unsolved qt3d text animation qml
    2
    0 Votes
    2 Posts
    1k Views
    No one has replied