Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Window creation trouble on SMFL-Pi  (Read 2738 times)

0 Members and 1 Guest are viewing this topic.

CrazyNium

  • Newbie
  • *
  • Posts: 1
    • View Profile
Window creation trouble on SMFL-Pi
« on: September 05, 2018, 04:59:11 am »
I'm using SFML for a project on my Raspberry Pi running Raspbian Stretch (Library gotten from https://github.com/mickelson/sfml-pi), and the window positioning isn't working (the window decoration isn't working, either, but that's a secondary concern). I used this example code from the getting started tutorial:

Quote
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

This is supposed to make a typical window with a green circle fitting completely inside the borders. I'm not sure where on the screen it would normally appear, but since the default window position is <0,0>, I would guess that would be the upper left corner of the screen. What I actually see is a green circle in the upper left of the screen but positioned such that the top and left side are off the screen (I estimate that about 15-20% of the expected width/height of the window is cut off). It seems like the window position variables are negative compared to the desktop origin. I've tried setting the window position to something else after creating it, but it doesn't move at all. Also noteworthy is that it lacks any decorations. I've tried running the program before starting the desktop, but the results are the same. Does anyone know what's going on?

One more piece of information is that I'm doing a remote build and run over ssh, but I don't see how that would affect it since the pi is still doing the building and running.

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Window creation trouble on SMFL-Pi
« Reply #1 on: September 05, 2018, 10:49:21 am »
I used the pi version in a project a while back and I remember some similar problems (I can't check the project any more because it went to a client). I was running without an x session, that I do remember, and to stop the cropping I think I had to adjust the overscan settings for the pi itself, which can be done with config.txt

https://www.raspberrypi.org/documentation/configuration/config-txt/video.md

Window creation looked something like:

    const sf::Vector2f ScreenArea(1920.f, 1080.f);

    auto mode = sf::VideoMode::getDesktopMode();
    sf::RenderWindow window;
    window.create(mode, "Buns.");
    window.setVerticalSyncEnabled(true);

    //fix the view at 1080p
    auto vModeWidth = static_cast<float>(mode.width);
    auto vModeHeight = static_cast<float>(mode.height);

    if(mode.width == 720)
    {
        //we're using composite output so the display handles letterboxing
        //we just need to adjust the pixel aspect ratio
        sf::View view({0.f, 0.f, ScreenArea.x, ScreenArea.y});
        view.setCenter(ScreenArea / 2.f);
        window.setView(view);
    }
    else
    {
        float windowRatio = vModeWidth / vModeHeight;
        float viewRatio = 16.f / 9.f;
        float sizeY = windowRatio / viewRatio;
        float top = (1.f - sizeY) / 2.f;

        sf::View view({0.f, 0.f, ScreenArea.x, ScreenArea.y});
        view.setCenter(ScreenArea / 2.f);
        view.setViewport({ { 0.f, top }, { 1.f, sizeY } });
        window.setView(view);
    }
 

Hope this is some help

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Window creation trouble on SMFL-Pi
« Reply #2 on: September 05, 2018, 10:54:07 am »
Isn't the point of not using X11 to not have windows with decorations and custom size? If you want to operate with a normal window etc, you should be able to just install X11 and compile the official SFML for ARM/Pi, I think.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/