I was looking through the documentation on ways to make a window the size of the screen. I found this page:
http://www.sfml-dev.org/tutorials/2.3/window-window.php (http://www.sfml-dev.org/tutorials/2.3/window-window.php)
If you look at the bottom it says (in exact words):
For some reason, Windows doesn't like windows that are bigger than the desktop. This includes windows created with VideoMode::getDesktopMode(): with the window decorations (borders and titlebar) added, you end up with a window which is slightly bigger than the desktop.
I was almost certain there was a way to fix this and make it work for Windows. I'm using Windows 10 operating system, 64 bit version. I tested and it does indeed produce errors. It gets the correct size but places the window 9 pixels to the right. I managed to fix it with:
window.setPosition(-9, 0)
This was perfectly fine but I wanted to find out why it was 9 pixels difference. I managed to find out that that is the size of the frame surrounding the window. I created a C++ project in CodeBlocks not using SFML. Because according to the documentation this only happens in Windows OS's I was able to narrow it down to fixes that only involved Windows OS's. Thus, I could use the default <window.h> class in C++ for Windows. I produced this code which gets the window's surrounding frame size:
#include <windows.h>
#include <iostream>
int main()
{
std::cout << GetSystemMetrics(SM_CXSIZEFRAME) << std::endl;
}
That code produces the size frame's width. Which produced 9, confirming that it is the frame causing windows to be rendered 9 pixels to the right. In Window's you can change the frame size so you can't really just say minus 9 pixels as it can be changed. Thus I began work on a more dynamic solution. Here is my code which renders the window correctly:
#include <SFML/Graphics.hpp>
#include <windows.h>
int main()
{
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Majestic SFML Window");
window.setPosition(sf::Vector2i(0 - GetSystemMetrics(SM_CXSIZEFRAME), 0));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.clear(sf::Color::Black);
window.display();
}
return 0;
}
I am fairly certain that the developer of SFML (I think he's called Laurent) can edit SFML to include this. Obviously you cannot just do this as this wouldn't work on other OS's like Mac and Linux. But that's as simple as checking whether the operating system is Window's and if so then run another class to subtract the size frame's size.
So yeah, basically I was wondering if you could fix this bug.[/code]
I just tested it and the window, with decorations and desktop size, is correctly placed at (0, 0). If there's some empty space (9 pixels) for you then this is actually a real bug, and a proper & complete report would be welcome ;)
I'd just like to make sure. You are using Windows right?
I believe I may of misread the documentation saying there's a problem with oversizing but then I've discovered something different? Using just this code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Majestic SFML Window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.clear(sf::Color::Black);
window.display();
}
return 0;
}
On a Windows 10, 64 bit computer produces this:
(http://i.imgur.com/g0324jA.png)
I wonder why nobody has suggested just maximizing the window...
Obviously, with the current SFML API, there is no way of saying "give me a window whose outer extents match x,y". So instead of saying give me a window that is the same size as the desktop resolution, just maximize the window right after you create it. That is what you really want in the end anyway. The desktop resolution video mode should only really have to be used for fullscreen or positioning the window somehow, but not for creating floating windows, else you will end up with the problem described in this thread.
Since SFML doesn't support programmatically maximizing the window, you will have to use the Windows API for this:
ShowWindow(window.getSystemHandle(), SW_MAXIMIZE);
Don't forget to include <windows.h>.