[Solved] SVG scaling

Started by RGPaul, 05 April 2023, 11:19:20

RGPaul

Hey texus,

I'm wondering what is happening with SVG images in textures.

The following code produces a very blurry image:
auto testTexture = tgui::Texture(resourcePath + "/images/test.svg");
auto testPic = tgui::Picture::create(testTexture);
testPic->setOrigin({0.5f, 0.5f});
testPic->setPosition("50%", "50%");
testPic->setScale(5);

If I scale the image using setSize() it is far less blurry but still not sharp.

2 Questions:
  • Is the image rasterized again if the size is changed?
  • Is High DPI considered for rasterization?

texus

setScale will always lead to a blurry result, it simply stretches the output when rendering to the screen.

setSize will cause rasterization to be performed. If you don't change the view then it should result in a sharp image.

I'm assuming however that you are still calling setRelativeView on the gui as otherwise everything was rendered too small? The rasterization doesn't take that into account. So I might need to change the code to let rasterization also use the FontScale factor to compensate for the high DPI.

RGPaul

Hey texus,

thanks for your quick answer.  :)

Yes indeed I call setRelaticeView using data from SDL in my code:

    SDL_GetWindowSize(window, &windowSizeScreenCoords.x, &windowSizeScreenCoords.y);
    SDL_GetWindowSizeInPixels(window, &windowSizePixels.x, &windowSizePixels.y);
    float dpiScale = static_cast<float>(windowSizePixels.y) / static_cast<float>(windowSizeScreenCoords.y);
    gui.setRelativeView({0, 0, 1.0f / dpiScale, 1.0f / dpiScale});

texus

It should be fixed now.
When "tgui::getBackend()->setFontScale(dpiScale)" is called, the SVG images will be internally rasterized to a higher resolution.

RGPaul

Works - thank you very much!  :)