SFML community forums

Help => Graphics => Topic started by: new-sfml-developer on February 08, 2024, 10:03:00 pm

Title: Running into errors with using SFML on WSL
Post by: new-sfml-developer on February 08, 2024, 10:03:00 pm
Hi! I'm running into some pretty major issues trying to start using sfml in a new project. I'm trying to render a rectangle to a window and cannot get it to work. I'm able to change the color of the window with the clear() method, but drawing doesn't seem to work. I've included <SFML/Graphics.hpp> in the header. Here's the code:

int main() {
    sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");
    sf::RectangleShape shape;
    shape.setPosition(590, 310); // Adjusted position to fit within the window
    shape.setSize(sf::Vector2f(100, 100));
    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(sf::Color::White);
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

I've followed tons of forum posts and asked ChatGPT what it thinks, and so far I haven't been able to find a solution. The window that appears when the draw line is not commented out is black as well. Some things I've tried: Fixing CMakeLists.txt files (I can post snippits from here too if it would help) Debugging and tracing through call stack (it seems to get mad at glXSwapBuffers) Installing dependencies manually with sudo Changing shapes, sprites, etc. to try and render something Following CMake tutorial in the tutorial section.
Title: Re: Running into errors with using SFML on WSL
Post by: eXpl0it3r on February 09, 2024, 08:45:12 am
What do you get when you run wsl --version?
Title: Re: Running into errors with using SFML on WSL
Post by: new-sfml-developer on February 09, 2024, 01:47:47 pm
Thanks for your reply!  I get this in my powershell
WSL version: 2.0.14.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.3930
 
Title: Re: Running into errors with using SFML on WSL
Post by: eXpl0it3r on February 12, 2024, 08:41:02 am
Hmm odd. It works fine for me, but I'm also on Windows 11 and not 10

Any specific reason you want to develop under WSL2 with SFML?
Title: Re: Running into errors with using SFML on WSL
Post by: new-sfml-developer on February 12, 2024, 03:50:28 pm
Ok well at least now I know it may be in the setup  :( but I want to use WSL2 and SFML to develop a C++ app that's essentially a balance game using force plates, but I've only really worked with mac/linux in the past and so when I initially set up my development environment I opted for WSL for the smoother starting process.  I was thinking of maybe trying to restart in windows but I'm not sure if that'll even work.