summaryrefslogtreecommitdiff
path: root/src/sdlgraphics.cpp
AgeCommit message (Collapse)AuthorFilesLines
6 daysWork around issue with minimizing maximized windowsThorbjørn Lindeijer1-1/+0
Only call `SDL_ShowWindow` once, since it seems old SDL versions (like 2.30.0, shipping with Ubuntu 24.04) do not allow a maximized window to be minimized when `SDL_ShowWindow` is called each frame.
14 daysFixed issues related to wrong alpha mod set on texturesThorbjørn Lindeijer1-35/+21
Due to the use of SubImage, there can be multiple images pointing to the same SDL_Texture with different alpha values. However, since the alpha mod set on the texture was only set from Image::setAlpha, images were not always rendered with the correct alpha value. Now the alpha mod is always set right before rendering each image. Most of the time the alpha will remain the same, but I don't expect this to become a performance issue so I've not added extra variables and checks to suppress such calls when they aren't needed. On the upside, this simplifies the "use color" option, which previously had to restore the previously set alpha mod. Closes #117
2025-07-04Added logging priorities and use SDLs logging facilitiesThorbjørn Lindeijer1-15/+15
By using SDL logging, we can rely on SDL to filter the log messages by their priority before they get sent to our custom output function. For example, we now no longer get entries for created and destroyed Window instances by default, since these have only "debug" priority whereas the default priority for the "app" category is "info". We can also get log messages raised by SDL itself in our log now. Log levels can be controlled per category through the "SDL_LOGGING" environment variable. Many existing log messages have been assigned a category based on their existing prefix.
2025-07-02Delay showing of the window to avoid startup flickerThorbjørn Lindeijer1-3/+5
Otherwise, at least on X11, the window is (visibly) re-created once the SDL renderer is created. Also the window icon can be seen changing on startup. Showing the window only after all related setup has been completed avoids this. On X11 this appears to have the added benefit of putting a "windowed fullscreen" window on the active screen (in terms of where the mouse is) rather than always using the primary screen. On Windows, showing the window only after the initial paint avoids the window initially appearing with its contents entirely black. The window is still immediately shown in the following cases: * In exclusive fullscreen mode, because on Windows this caused the initial show of a fullscreen window to take much longer and on X11 it could cause the resolution of the primary screen to be changed while maximizing the Mana window on the active screen. * In "windowed fullscreen" mode when the legacy OpenGL renderer is used, where it was causing an additional flicker on Windows.
2025-04-25Simplified ImageRect handlingThorbjørn Lindeijer1-16/+16
We don't need to keep an array of SubImage instances, but can just remember the top, left, right and bottom margins and use those when rendering the scaled ImageRect. Graphics::drawRescaledImagePattern had to be extended to allow specifying the source rectangle.
2025-03-31Use color modulation to render text in different colorsThorbjørn Lindeijer1-2/+37
No need to cache the image in different colors since color modulation is cheap these days.
2025-03-31GUI: Apply clipping only where necessaryThorbjørn Lindeijer1-21/+9
Clipping has been disabled globally by taking it out of Graphics::pushClipArea. Now its name is a little confusing, but it can't just be changed since it is part of Guichan. Widgets that do need to clip their children use the new Graphics::pushClipRect, which pushes a clipping rectangle without affecting the local coordinates. These are: * ScrollArea * TextField * TabbedArea (scrolling tabs) * MiniMap While it might count as a small optimization, I'm actually disabling clipping because it is not always desired. For example it gets in the way of rendering the complete ResizeGrip in the Jewelry theme because that's a child widget.
2025-03-17Fixed small issue in SDLGraphics::drawRescaledImagePatternThorbjørn Lindeijer1-1/+2
It wasn't setting the size of the srcRect correctly when the last drawn images were partially cut off and the image wasn't being rendered at 1:1 scale. This issue might have affected ambient layers with mKeepRatio set to true.
2025-01-25snap: Updated to core24Thorbjørn Lindeijer1-0/+2
2024-10-18Take only const pointers to images in GraphicsThorbjørn Lindeijer1-3/+3
Helps making sure we're not modifying the images in the rendering code. Re-applies 4eea727b7649726670d8963d11ab4fd429624b3e (and reverts 363f71157a8107190b3bd2ba656faf0a0e63ab36).
2024-10-15Fixed crash when taking screenshot with scaled graphicsThorbjørn Lindeijer1-6/+14
Because the allocated surface was based on the unscaled size, writing the actual pixels was overwriting random memory.
2024-03-26Added support for HiDPI fontsThorbjørn Lindeijer1-0/+1
* TrueTypeFont class now takes into account the graphics scale, in order to render an appropriate higher-resolution texture. * Removed TrueTypeFont::fontCounter, since TTF_Init/TTF_Quit already keep a counter. * Avoid copying the rendered string needlessly, when it already exists in the cache. Avoid another copy, when inserting a new chunk into the cache.
2024-03-26Added functions to draw images at sub-pixel positionsThorbjørn Lindeijer1-0/+31
This can be used for smoother mouse cursor movement when rendering our own mouse cursor (already changed in this commit) and is also necessary for implementing support for HiDPI font rendering. Also dropped some almost duplicated OpenGL code.
2024-03-22Added support for scaling the outputThorbjørn Lindeijer1-4/+47
* Added "Scale" user option, which can either by "Auto" or an explicit scaling factor. Its maximum value depends on the current resolution. The "Auto" factor is based on keeping the logical resolution on at least 800x600, wheres the maximum scale is based on keeping the logical resolution on at least 640x480. * Enabled support for High DPI. This means the rendering target can now have a different resolution than the window size, which can happen on macOS, Windows and Wayland. The resulting scale is multiplied by the above user-controlled scale. Currently, this looks ugly for non-integer scales, which are not used on macOS and can only be configured on some Wayland compositors. Has not been tested on Windows. * Simplified OpenGL initialization (moved out of _beginDraw). * Made sure _beginDraw/_endDraw sets a clip area also for SDLGraphics.
2024-03-07Fixed ambient layers "keepratio" optionThorbjørn Lindeijer1-4/+4
I had broken this in 264be2108c51837fa92085f6c839e66aebbcfc9e by no longer reading out the property. Made some further simplifications and two more fixes: * When the original image's size was not 800x600, it wouldn't get scaled as expected due to the integer division being performed before the multiplication. * I had changed the default resolution to 1280x720, while mKeepRatio expects to scale the original image as if it was displayed on an 800x600 screen. So now it's hardcoded on 800x600 rather than using the defaultScreenWidth/Height variables. * Removed the confusing x/y parameters from AmbientLayer::draw, which were actually set to the graphics width/height. * Changed SDLGraphics::drawRescaledImagePattern to not repeatedly set the source origin.
2024-02-27Added VSync and windowed fullscreen optionsThorbjørn Lindeijer1-0/+304
The configuration and setup UI were adjusted to the new options. This also fixes issues in applying new video settings. Default resolution was changed from 800x600 to 1280x720. VSync is enabled by default while FPS limit was disabled. Display aspect ratio for the resolution options. I had to work around some macOS issues: * Don't change window size when it appears to be "maximized", since it just changes the rendering area while leaving the window maximized. * Unset fullscreen display mode temporarily to allow changing resolutions, otherwise the rendering area no longer matches the screen and mouse input is also off. * Removed SDL_WINDOW_ALLOW_HIGHDPI for now because it causes issues on macOS, since we're not actually handling the scaling factor. A Video class and an SDLGraphics subclass were split off from Graphics. This setup has Less duplication and leaves the OpenGLGraphics and SDLGraphics better separated. Fixes #57 Fixes #58