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
  • Welcome!

    Pinned
    42
    1 Votes
    42 Posts
    34k Views
    JKSHJ

    Hi,

    [quote author="cseder" date="1423513071"]But Qt has an excellent solution which makes working with OpenGL a lot simpler:
    The QGLWidget class is a widget for rendering OpenGL graphics.

    Read all about it: "QGLWidget docs":http://doc.qt.io/qt-5/qglwidget.html#details.[/quote]QGLWidget is deprecated. Use "QOpenGLWidget":http://doc.qt.io/qt-5/qopenglwidget.html instead.

    Also check out "VoltAir":http://blog.qt.io/blog/2014/07/21/google-labs-voltair-game-built-with-qt/ -- it is a game that Google built on top of Qt Quick.

  • QPainterPath to draw curve with fading

    Unsolved
    4
    0 Votes
    4 Posts
    530 Views
    BondrusiekB

    @Ejok88 Hi,
    you can see official Qt examples: https://doc.qt.io/qt-6/examples-widgets-opengl.html. Additionally, you can review the chapter of the free book Qt6 QML Book and see the chapter on shaders. I can recommend my repository where I use OpenGL: https://github.com/Przemekkkth/camera-opengl-qt.

  • No way to use particle system directly from C++?

    Unsolved
    2
    0 Votes
    2 Posts
    61 Views
    BondrusiekB

    Hi,
    i was also looking for such a module in pure Qt/C++ some time ago. Unfortunately, as far as I know, there is no such equivalent. If you want to achieve such results, you have to use either QPainter or OpenGL.

  • QRhi rendering question

    Unsolved
    2
    0 Votes
    2 Posts
    62 Views
    D

    FWIW, the fixed code (thanks to github copilot)

    void SpectralChannel::render(QRhiCommandBuffer *cb) { //update resources first updateTextures(); Area scaledDisplayArea=convert.toScaled(displayArea); scaledDisplayArea.moveLeft(0.); QMatrix4x4 scaledDisplayMatrix=scaledDisplayArea.toMatrix(); resourceUpdateBatch()->updateDynamicBuffer(...); for(QHash<LayerPtr, SpectralTextureMeta2>::iterator tex = textureList.begin(); tex != textureList.end(); tex++) { resourceUpdateBatch()->updateDynamicBuffer(...); ... } cb->resourceUpdate(resourceUpdateBatch(true)); //start drawing commands cb->beginPass(renderTarget(), Qt::black, { 1.0f, 0 }, resourceUpdateBatch(true)); cb->setViewport({ 0, 0, float(width()*devicePixelRatio()), float(height()*devicePixelRatio()) }); for(QHash<LayerPtr, SpectralTextureMeta2>::iterator tex = textureList.begin(); tex != textureList.end(); tex++) { cb->setGraphicsPipeline(tex.value().spectralPipeline.get()); const QRhiCommandBuffer::VertexInput vbufBinding(tex.value().vertexBuf.get(), 0); cb->setVertexInput(0, 1, &vbufBinding); cb->setShaderResources(); cb->draw(4); } cb->endPass(updateFrameBuffer()); }
  • Using OpenSSL 3 https connection

    Unsolved
    10
    0 Votes
    10 Posts
    220 Views
    piervalliP

    @JonB in the release notes openssl 3 is added in the 5.15.10

  • New version of Qt I am trying to write again the code

    Unsolved
    4
    0 Votes
    4 Posts
    108 Views
    F

    I will have a look thanks for the answer

    I uploaded zipfile with compilation errors on github
    https://github.com/fulgorit/mazegen/raw/refs/heads/master/qMazeGen-QT6-SRC-COMPILATIONERRORS.zip

  • 0 Votes
    3 Posts
    272 Views
    D

    Thank you @Christian-Ehrlicher it worked!
    Could it be considered as a bug? (I would expect the cmake files of Qt to link openGL as I'm using Qt6::OpenGL)

  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • Simple Qt/C++ games

    Unsolved
    79
    7 Votes
    79 Posts
    35k Views
    BondrusiekB

    Procedural Generation
    alt text

    Source code: https://github.com/Przemekkkth/qt-procedural-generation

  • Development of a GameController for QtQuick3D

    Unsolved
    1
    1 Votes
    1 Posts
    112 Views
    No one has replied
  • Using Qt to build an editor for an OpenGL ES3 game engine

    Unsolved
    3
    1 Votes
    3 Posts
    282 Views
    S

    For that you'd need DX and OpenGL interop, i.e. you can share a DXGI resource (i.e. a texture) with OpenGL. There are extensions for that. BUT, on Windows Qt uses libAngle which normally uses DX so basically if the right APIs are available you don't need to do any OpenGL - DX interop since everything would be DX at the end of the day.

  • 3 Votes
    41 Posts
    5k Views
    8Observer88

    Critical problems for WebAssembly

    Background color of parent window is changed to black: https://bugreports.qt.io/browse/QTBUG-120651 emscripten_request_pointerlock() returns EMSCRIPTEN_RESULT_UNKNOWN_TARGET: https://bugreports.qt.io/browse/QTBUG-126513 Dealing with keyboard layout for input on Qt WebAssembly: https://forum.qt.io/post/790688
  • QRHI Compute Shader

    Unsolved
    3
    0 Votes
    3 Posts
    242 Views
    SGaistS

    Hi,

    I haven't tested QRhi yet but did you try the RHI Window example to see if things are running on all the backends you have on your machine ?

  • QRhi Device Choose

    Unsolved
    7
    0 Votes
    7 Posts
    393 Views
    SGaistS

    Can you post a link to the ticket ? It will make it easier to find for other people looking for a similar functionality.

  • Moving away from Qt3D, is QtQuick3D ready?

    Unsolved
    5
    1 Votes
    5 Posts
    676 Views
    R

    Closed source, sorry. But its not too hard to implement.

  • SFML to Qt...

    Unsolved
    10
    0 Votes
    10 Posts
    3k Views
    O

    It looks like now I can't connect Qt and SFML, because there are new virtual methods in QWidget, so vtable isn't being builded

  • 0 Votes
    4 Posts
    319 Views
    L

    I used X2L for game machine.
    When I render a1920x1080 image with freeGLUT, I can get fps up to over 100.
    But in case of QOpenGLWidget, I can't get even 20 fps.
    So I decided to use X4, but I want to know the reason.
    Thanks

    https://radxa.com/products/x/x2l

  • Rendering distance in Qt Quick 3D

    Solved
    4
    0 Votes
    4 Posts
    336 Views
    johngodJ

    @bluezoo Hi again

    Here is quick fix fully working, I just checked OrbitCameraController.qml code, indeed it has the clipNear and clipFar values hardcoded. Add a new qml file to your project, call it NewController or whatever, copy paste the OrbitCameraController.qml code and remove the connection that is causing the bug. Then just use the NewController component instead of OrbitCameraController.

    NewController.qml:

    // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick3D Item { id: root required property Node origin required property Camera camera property real xSpeed: 0.1 property real ySpeed: 0.1 property bool xInvert: false property bool yInvert: true property bool mouseEnabled: true property bool panEnabled: true readonly property bool inputsNeedProcessing: status.useMouse || status.isPanning implicitWidth: parent.width implicitHeight: parent.height /*Connections { target: root.camera function onZChanged() { // Adjust near/far values based on distance let distance = root.camera.z if (distance < 1) { root.camera.clipNear = 0.01 root.camera.clipFar = 100 if (camera.z === 0) { console.warn("camera z set to 0, setting it to near clip") root.camera.z = camera.clipNear } } else if (distance < 100) { root.camera.clipNear = 0.1 root.camera.clipFar = 1000 } else { root.camera.clipNear = 1 root.camera.clipFar = 10000 } } }*/ DragHandler { id: dragHandler target: null enabled: root.mouseEnabled acceptedModifiers: Qt.NoModifier onCentroidChanged: { root.mouseMoved(Qt.vector2d(centroid.position.x, centroid.position.y), false); } onActiveChanged: { if (active) root.mousePressed(Qt.vector2d(centroid.position.x, centroid.position.y)); else root.mouseReleased(Qt.vector2d(centroid.position.x, centroid.position.y)); } } DragHandler { id: ctrlDragHandler target: null enabled: root.mouseEnabled && root.panEnabled acceptedModifiers: Qt.ControlModifier onCentroidChanged: { root.panEvent(Qt.vector2d(centroid.position.x, centroid.position.y)); } onActiveChanged: { if (active) root.startPan(Qt.vector2d(centroid.position.x, centroid.position.y)); else root.endPan(); } } PinchHandler { id: pinchHandler target: null enabled: root.mouseEnabled property real distance: 0.0 onCentroidChanged: { root.panEvent(Qt.vector2d(centroid.position.x, centroid.position.y)) } onActiveChanged: { if (active) { root.startPan(Qt.vector2d(centroid.position.x, centroid.position.y)) distance = root.camera.z } else { root.endPan() distance = 0.0 } } onScaleChanged: { root.camera.z = distance * (1 / scale) } } TapHandler { onTapped: root.forceActiveFocus() // qmllint disable signal-handler-parameters } WheelHandler { id: wheelHandler orientation: Qt.Vertical target: null enabled: root.mouseEnabled acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad onWheel: event => { let delta = -event.angleDelta.y * 0.01; root.camera.z += root.camera.z * 0.1 * delta } } function mousePressed(newPos) { root.forceActiveFocus() status.currentPos = newPos status.lastPos = newPos status.useMouse = true; } function mouseReleased(newPos) { status.useMouse = false; } function mouseMoved(newPos: vector2d) { status.currentPos = newPos; } function startPan(pos: vector2d) { status.isPanning = true; status.currentPanPos = pos; status.lastPanPos = pos; } function endPan() { status.isPanning = false; } function panEvent(newPos: vector2d) { status.currentPanPos = newPos; } FrameAnimation { id: updateTimer running: root.inputsNeedProcessing onTriggered: status.processInput(frameTime * 100) } QtObject { id: status property bool useMouse: false property bool isPanning: false property vector2d lastPos: Qt.vector2d(0, 0) property vector2d lastPanPos: Qt.vector2d(0, 0) property vector2d currentPos: Qt.vector2d(0, 0) property vector2d currentPanPos: Qt.vector2d(0, 0) function negate(vector) { return Qt.vector3d(-vector.x, -vector.y, -vector.z) } function processInput(frameDelta) { if (useMouse) { // Get the delta var rotationVector = root.origin.eulerRotation; var delta = Qt.vector2d(lastPos.x - currentPos.x, lastPos.y - currentPos.y); // rotate x var rotateX = delta.x * xSpeed * frameDelta if (xInvert) rotateX = -rotateX; rotationVector.y += rotateX; // rotate y var rotateY = delta.y * -ySpeed * frameDelta if (yInvert) rotateY = -rotateY; rotationVector.x += rotateY; origin.setEulerRotation(rotationVector); lastPos = currentPos; } if (isPanning) { let delta = currentPanPos.minus(lastPanPos); delta.x = -delta.x delta.x = (delta.x / root.width) * camera.z * frameDelta delta.y = (delta.y / root.height) * camera.z * frameDelta let velocity = Qt.vector3d(0, 0, 0) // X Movement let xDirection = origin.right velocity = velocity.plus(Qt.vector3d(xDirection.x * delta.x, xDirection.y * delta.x, xDirection.z * delta.x)); // Y Movement let yDirection = origin.up velocity = velocity.plus(Qt.vector3d(yDirection.x * delta.y, yDirection.y * delta.y, yDirection.z * delta.y)); origin.position = origin.position.plus(velocity) lastPanPos = currentPanPos } } } }

    In main.qml replace OrbitCameraController with NewController

    NewController { anchors.fill: parent origin: originNode camera: cameraNode }

    Edit: I created a bug report here https://bugreports.qt.io/browse/QTBUG-129253

    Edit 2: I see you also created a bug report, thank you, I did search before I post the bug report but since I did not find it, I went ahead, sorry :)

  • Hi all

    Unsolved
    10
    0 Votes
    10 Posts
    783 Views
    BondrusiekB

    @Joshika_Namani Which version of Qt do you use? I think that using Qt6 is a better option but here is a doc for Qt5 https://doc.qt.io/qt-5/qopenglwidget.html if you want to see.

  • Qt3d - how to render lots of lights?

    Unsolved
    6
    0 Votes
    6 Posts
    364 Views
    J

    Thanks for the cleanup!