Skip to content

HiDPI scaling and glfw 3.4 #691

@arntanguy

Description

@arntanguy

Hi,

First of all, thanks for all the work on magnum and related projects, hugely useful!

I am in the process of packaging magnum in nixpkgs. Getting it to build and run, including the plugins was not an issue. However I'm running into issues regarding HiDPI scaling in glfw 3.4.0. Considering #243 this seems to be quite a sticky point (no surpises there ^^).

If I link the TriangleExample, against glfw 3.4.0, with Plateform::GlfwApplication, I get a very low resolution window, scaled up multiple times bigger than expected:

Image

Whereas running the same code against the Plateform::Sdl2Application, I get the expected behaviour:

Image

Tested with

add_executable(TriangleExample TriangleExample.cpp)
target_link_libraries(TriangleExample PRIVATE 
          Magnum::Sdl2Application
          # Magnum::GlfwApplication
          Magnum::GL
          Magnum::Magnum
          Magnum::Primitives
          Magnum::Shaders
        )
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/Math/Color.h>
#include <Magnum/Platform/GlfwApplication.h> // or #include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/Shaders/VertexColorGL.h>
#include <iostream>

namespace Magnum { namespace Examples {

class TriangleExample: public Platform::Application {
    public:
        explicit TriangleExample(const Arguments& arguments);

    private:
        void drawEvent() override;

        void viewportEvent(ViewportEvent & event) override
        {
        GL::defaultFramebuffer.setViewport({{}, event.framebufferSize()});
        std::cout << "windowSize: " << event.windowSize().x() << "x" << event.windowSize().y()
                  << ", framebufferSize: " << event.framebufferSize().x() << "x" << event.framebufferSize().y()
                  << ", dpiScaling: " << event.dpiScaling().x() << "x" << event.dpiScaling().y() << std::endl;

        }

        GL::Mesh _mesh;
        Shaders::VertexColorGL2D _shader;
};

TriangleExample::TriangleExample(const Arguments& arguments):
    Platform::Application{arguments, Configuration{}
        .setTitle("Magnum Triangle Example")
        .addWindowFlags(Configuration::WindowFlag::Resizable)
    }
{
    using namespace Math::Literals;

    struct TriangleVertex {
        Vector2 position;
        Color3 color;
    };
    const TriangleVertex vertices[]{
        {{-0.5f, -0.5f}, 0xff0000_rgbf},    /* Left vertex, red color */
        {{ 0.5f, -0.5f}, 0x00ff00_rgbf},    /* Right vertex, green color */
        {{ 0.0f,  0.5f}, 0x0000ff_rgbf}     /* Top vertex, blue color */
    };

    _mesh.setCount(Containers::arraySize(vertices))
         .addVertexBuffer(GL::Buffer{vertices}, 0,
            Shaders::VertexColorGL2D::Position{},
            Shaders::VertexColorGL2D::Color3{});
}

void TriangleExample::drawEvent() {
    GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);

    _shader.draw(_mesh);

    swapBuffers();
}

}}

MAGNUM_APPLICATION_MAIN(Magnum::Examples::TriangleExample)
  • dpiScaling is reported as 1x1 in the SDL2 case, versus 2.97x3 in the glfw 3.4 case.
  • I am running on NixOS 25.11 with Wayland + Niri compositor.

More visual example from our standalone robot visualizer mc_rtc-magnum built with magnum + imgui:

Image

vs expected:

Image

Both are running on NixOS 25.11, however the difference here is that:

Are you aware of similar issues with glfw 3.4.0? What steps can I take to debug this further?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    TODO

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions