SFML window size?

Working on that book "Beginning C++ Game Programming" on the 1st Timber project. My desktop recommended display is 1360x768 & code asks us to use a window 1920x1080. Problem is that the background graphics (background.png) looks too big & instead of fitting the exact size of the background (1920x1080) on the 1920x1080 window, it cuts off from all ends & zooms in center...as if the window size is smaller than 1920x1080. Other sprites look oversized too.

So I forced my graphics card to 1920x1080, which looks horrible now on Windows end, & yet still the background is cut off on all ends & centered in middle and other sprites look oversized.

Line 23-27 verifies both VideoMode & window is indeed 1920x1080.
I also verified that the background picture is actually 1920x1080 as well.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include <SFML/Graphics.hpp>

using namespace sf;
using namespace std;

int main()
{
    //VideoMode vm(1360, 768);
    VideoMode vm(1920, 1080);                                   //Create VideoMode object & set resolution
    RenderWindow window(vm, "Timber!!!", Style::Fullscreen);    //Create windows, put title in, & run FullScreen


    /*BACKGROUND*/
    Texture textureBackground;                                  //Create texture to hold graphics in GPU
    textureBackground.loadFromFile("graphics/background.png");  //Load graphic into the texture in GPU
    //textureBackground.loadFromFile("graphics/background_1350.png");  //Load graphic into the texture in GPU

    Sprite spriteBackground;                                    //Create sprite
    spriteBackground.setTexture(textureBackground);             //Load texture from GPU into the sprite
    spriteBackground.setPosition(0,0);                         //Set at 0,0 as image is 1920x1080

    cout << VideoMode::getDesktopMode().width << endl;
    cout << VideoMode::getDesktopMode().height << endl;

    cout << "Window x = " << window.getSize().x << endl;
    cout << "Window y = " << window.getSize().y << endl;


    /**************TREE**************/
    Texture textureTree;
    textureTree.loadFromFile("graphics/tree.png");
    
    Sprite spriteTree;
    spriteTree.setTexture(textureTree);
    spriteTree.setPosition(810, 0);


    /**************BEE**************/
    Texture textureBee;
    textureBee.loadFromFile("graphics/bee.png");

    Sprite spriteBee;
    spriteBee.setTexture(textureBee);
    spriteBee.setPosition(0, 800);

    bool beeActive = false;     //Is bee currently moving
    float beeSpeed = 0.0f;      //Bee speed


    /**************CLOUDS**************/
    Texture textureCloud;
    textureCloud.loadFromFile("graphics/cloud.png");

    Sprite spriteCloud1, spriteCloud2, spriteCloud3;
    spriteCloud1.setTexture(textureCloud);
    spriteCloud2.setTexture(textureCloud);
    spriteCloud3.setTexture(textureCloud);

    spriteCloud1.setPosition(0, 0);
    spriteCloud2.setPosition(0, 250);
    spriteCloud3.setPosition(0, 500);

    //Are the clouds currently on the screen?
    bool cloud1Active = false;              
    bool cloud2Active = false;
    bool cloud3Active = false;

    //How fast is each cloud moving?
    float cloud1Speed = 0.0f;
    float cloud2Speed = 0.0f;
    float cloud3Speed = 0.0f;

    while (window.isOpen())                                     //Main game loop while the window is open
    {
        /*
        **********************************
        Handle the players input
        **********************************
        */
        
        if (Keyboard::isKeyPressed(Keyboard::Escape))
            window.close();

        /*
        **********************************
        Update the scene
        **********************************
        */


        /*
        **********************************
        Draw the scene
        **********************************
        */

        window.clear();   //Clear everything from the last frame

        //Draw our games scene here
        window.draw(spriteBackground);
        window.draw(spriteCloud1);
        window.draw(spriteCloud2);
        window.draw(spriteCloud3);
        window.draw(spriteTree);
        window.draw(spriteBee);

        window.display();   //Show everything we just drew (double buffering)

    }


    return 0;
}

Last edited on
I had rebooted Windows before, this time I decided to reboot again & noticed my TV (HDMI to Sony TV) flashed "1920x1080 1HZ" & then flashed again with text "1360x768 60HZ".

So it looks like the code might be handling it fine, but then the HDMI is fitting it to 1360x768 forced by the TV & cutting out the peripheral of the window.
If this was code you were selling on Steam, how do you handle this? Probably not much you can do?
I guess on my end I will have to resize the graphics & fit them to my screen, unless I use a different display.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// get screen resolution
void MainApp::GetDesktopResolution(int& horizontal, int& vertical)
{
    RECT desktop;
    const HWND hDesktop = GetDesktopWindow();
    GetWindowRect(hDesktop, &desktop);

    horizontal = desktop.right;
    vertical = desktop.bottom;
}

// ...
GetDesktopResolution(_H, _V);
        // creates the window - fullscreen according GetDesktopResolution function
        m_hwnd = CreateWindowEx(
            WS_EX_APPWINDOW,
            L"D2DMainApp",
            L"Game",
            WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            _H,
            _V,
            NULL,
            NULL,
            HINST_THISCOMPONENT,
            this
        );


I know that this is not what you meant asking us. However I struggled hard so as to resize my window, but for a project using Direct2D. Many people said to me that a fullscreen mode was impossible using Direct2D, but it is wrong. I used the function above so as to get right values which I applied on my window. I assume that it is totally different for SDL, but maybe you could adjust your window using this function. Sorry if I am completely mistaken ++
Last edited on
Topic archived. No new replies allowed.