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
  • 0 Votes
    2 Posts
    547 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
  • 0 Votes
    2 Posts
    350 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
    493 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
    296 Views
    No one has replied
  • Hundreds of thousands of points

    Unsolved
    16
    0 Votes
    16 Posts
    1k 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
    3k 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:

    0000f57d-78c6-4878-91d2-c26e4469bf11-image.png

  • 0 Votes
    2 Posts
    839 Views
    No one has replied
  • 0 Votes
    2 Posts
    726 Views
    aarelovichA

    So In case anyone comes across this. I figured out the issue but it makes littles sense.

    As I said in my question I had deactivated my Intel UHD Adapter.

    However upon exploring on windows Graphics/Display Settings I saw that actual screen for the laptop was connected to "Microsoft Display Adapter" while the HMD was connected to the NVIDIA Graphics Card.

    So on a whim I enabled the UHD adapter and and now the Windows Advaced Display Settings tell me that the laptops screen is connected to the Intel UHD Driver. (Instead of the Microsoft Display Adapter).

    Now the code works, withouth having to connect a second monitor but it's weird. The stuff gets displayed on the VR Helmet, which is indicated everywhere that I can see, to be connected to the NVIDIA Graphics Card, but the OpenGL Initialization is somehow happening because of the Intel UHD Driver?

    The message clearly gives the idea that the lack of OpenGL was the problem which makes sense given that the Microsoft Display Adapter would not have it. But I still don't understand how it works. And I feel I'm missing an important piece fo the puzzle. If anyone could shed some light that would be greatly appreciated.

  • QTgamepad, how to install and .pro configurations

    Unsolved
    4
    0 Votes
    4 Posts
    2k Views
    SGaistS

    @Davidisi hi and welcome to devnet,

    Did you follow my suggestions ?

  • QGLWidget and Threads [SOLVED]

    8
    0 Votes
    8 Posts
    6k Views
    T

    where is the solution? Sorry, I can't see.

  • QOpenGLWidget creates 6kx3k fbos on macOS with 4k display

    Locked Unsolved
    2
    0 Votes
    2 Posts
    335 Views
    SGaistS

    Hi,

    Please do not post the same question in multiple sub forum. One is enough

    Duplicate

    Closing this one

  • 0 Votes
    5 Posts
    694 Views
    W

    @AI_Messiah
    There isn't any simple/supported way to do that. The intended workflow from Blender is to bake your textures to images, and export as something other than .blend for import into other applications. If you want to use Blender procedural textures in your own renderer, you'll either need to use a ton of Blender code in your app, or study their behavior and try to reimplement them from scratch.

  • 0 Votes
    9 Posts
    828 Views
    SGaistS

    I thought that this image only failed on your system.
    Does it have any other properties beside the size that makes it different from your other images ?
    Would it be possible for you to create a minimal compilable example using it ?

  • Where can I find how to use QMesh and QScene in QML

    Unsolved
    1
    0 Votes
    1 Posts
    254 Views
    No one has replied
  • 0 Votes
    2 Posts
    335 Views
    sierdzioS

    In Qt 5, QML is implemented using OpenGL. Can't get more "compatible" than that ;-) Check out QQuickItem documentation for more info.

    In Qt 6 it is different, because implementation is independent of the 3D API (it uses OpenGL, DirectX, Metal etc. depending on platform).

    For offscreen rendering, run your app with offscreen platform plugin:

    yourApp.exe -platform=offscreen
  • 0 Votes
    2 Posts
    341 Views
    A

    Another thing is how would I use physics like gravity, center of mass and collision detection and other stuff

  • How do I add Vertex Induces to this OpenGL code

    Unsolved
    1
    0 Votes
    1 Posts
    620 Views
    No one has replied
  • How do I create an instance of QPaintedTextureImage

    Unsolved
    2
    0 Votes
    2 Posts
    294 Views
    SGaistS

    Hi,

    As the class documentation states, the QPaintedTextureImage must be attached to a texture.

    The paint method provides you the QPainter instance you have to use.

  • Where can I find a good QT OpenGL tutorial

    Unsolved
    3
    0 Votes
    3 Posts
    991 Views
    8Observer88

    You do not need special Qt OpenGL tutorials. Just use a few simple Qt OpenGL examples from Qt Examples https://doc.qt.io/qt-5/examples-widgets-opengl.html and use general OpenGL tutorials like:

    https://learnopengl.com http://opengl-tutorial.org http://ogldev.org https://open.gl https://thebookofshaders.com

    My simple examples in Qt OpenGL:

    Triangle: https://rextester.com/ZTRI45421 Texture: https://rextester.com/BJW63108 3D cube: https://rextester.com/IPI73465 Snake 2D: https://rextester.com/MMC15477 (I translated this example to Qt OpenGL 3.3 from the Python OpenGL 1.1 tutorial: https://noobtuts.com/python/snake-game)
  • Converting From Hexadecimal to QString

    Unsolved
    4
    0 Votes
    4 Posts
    590 Views
    kshegunovK

    What's the point of c here?