Hi,
Currently writing an app in SFML which loads an image from file and displays it.
I know I'm not doing something quite right as I get strange results. Allow me to explain the problem...
I open an SFML window, with a "default" videomode of 800x600.
The reason is that the user chooses the image to display so the VM resolution (size) is not known at start time and it is not constant during the runtime of the app.
... You can probably see where this is going, and guess what the problem is?
At some point during the app runtime the user chooses an image to display. If the image is smaller than 800 x 600, I want the (non-resizable) window to change size such that it crops itself to fit the image. To clarify, I have set sf::Style::Titlebar and sf::Style::Close to make the window "non-resizable".
First I tried to:
1: Load the image into a texture
2: Create sprite and set texture
3: Change window size to match the size given by the texture
4: Draw the sprite
I "cout" the texture size, the sprite global bounds, the sprite scale and the window size. They all agree except sprite scale which is 1.0.
However the image does not fill the window. It is smaller than the window.
My code is simple and I can provide it, but without an image to test it on (perhaps I can find one online which we can agree to all use?) it won't give the same results for everyone who runs the code...
Since this didn't work, my suspicions were that the video mode (which is larger than the texture size) was causing the issue.
In other words, the VM is 800 x 600, and the BMP image is 640 x 480... Therefore when I call window.resize(640, 480) a 800 x 600 VM is "mapped" onto a display area of 640 x 480... So obviously the bitmap will be scaled down by the same factor and it will appear smaller than 640 x 480.
This appears to be what is happening.
So the second thing I tried was:
1: Calling window.close()
2: Calling window.create() with a new VM which is the correct size (same size as sprite)
Since I was doing this in a loop it creates a flickering effect as the window is destroyed and re-made over and over.
I can sort of resolve this issue by checking to see if the window needs to be created again, rather than doing it each time... However this still causes a flickering when the "user image choice" is changed between different size images.
Is there a solution to this in SFML or would changing the VM without destroying the window require a new patch to SFML?
I assume the videomode has something to do with allocating memory for OpenGL somewhere? Is it possible for me to resize the "opengl surface" while also resizing the window?
Alternatively is this a bug in SFML?