Search code examples
androidc++qtopengl-eswebassembly

OpenGL lighting works incorrectly on Android and WebAssembly


I wrote an example that loads 3D model from DAE COLLADA using Qt 6. Source code: load-3d-model-from-dae-opengl-window-qt6-cpp.zip

OpenGL lighting works correctly on Desktop but incorrectly on Android and WebAssembly:

Desktop:

d138eecf-d8bd-4de3-86aa-c7669484c12b-image.png

Android:

094dc9ee-508f-4ba4-87c8-28c1444262ba-image.png

WebAssembly:

ef0b3e64-6deb-46ad-984b-9a9610509561-image.png

Added:

I added this line of code glEnable(GL_CULL_FACE); to OpenGLWindow::initializeGL(). The problem was solved for a cube on Android:

enter image description here

and WebAssembly:

enter image description here

When I change a model with Mario it works on Desktop:

enter image description here

But it doesn't work for Android:

enter image description here

and WebAssembly:

enter image description here

Source code: load-3d-model-from-dae-opengl-window-qt6-cpp.zip

Cross-refs:


Solution

  • I tried to set a depth buffer size to 24:

    OpenGLWindow::OpenGLWindow()
    {
        setTitle("OpenGL ES 2.0, Qt6, C++");
        resize(350, 350);
    
        QSurfaceFormat surfaceFormat;
        surfaceFormat.setDepthBufferSize(24);
        setFormat(surfaceFormat);
    }
    

    It works on WebAssembly at least from Windows 10, 64-bit: https://65d340535ef3fa042a6d1ce3--charming-malabi-d8d124.netlify.app/

    enter image description here

    And on Redmi 4X, Android 7:

    enter image description here