SFML community forums

Help => General => Topic started by: pallen@fgcu.edu on March 03, 2022, 10:18:03 pm

Title: Visual Studio 17 Black RenderWindow
Post by: pallen@fgcu.edu on March 03, 2022, 10:18:03 pm
I'm trying to get a sample project working for the University C++ courses I teach.  I've used SFML in my courses before. It's just supposed to open a window with white background, and then draw a blue circle in the middle.  I have it working fine on Windows with MinGW64 and CLion using binaries downloaded from sfml-dev.org. I have it working on MacOS with CLion using command line cmake.  I can't get it to work on Windows with Visual Studio 17, I only get a black window.  I'm using the same cpp file.  I've tried binaries with static and non-static linking.  I've built the libraries using cmake-gui and VS 17 and tried static linking.  Same results.  Any ideas?

Here's my code:

#include <SFML/Graphics.hpp>

// Global Defines
// --------------------------------------------------------
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;

const sf::Color WINDOW_COLOR = sf::Color::White;
const sf::Color BALL_COLOR = sf::Color::Blue;

int main() {

    // create a 2d graphics window
    sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Hello SFML");

    sf::CircleShape ball;
    ball.setOrigin(10.0, 10.0);
    ball.setPosition(WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0);

    while (window.isOpen())
        // Process user input
        // ------------------------------------------------
        sf::Event event;
        while (window.pollEvent(event))
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)

        // Render drawing objects
        // ------------------------------------------------
    return 0;
Title: Re: Visual Studio 17 Black RenderWindow
Post by: eXpl0it3r on March 08, 2022, 01:04:38 pm
I can't see anything wrong with this and it works fine on my machine.
As such, I can only guess, that there's something funky going on with the setup.
Maybe you've configured things for release, but are running the debug build.
Or maybe you have the wrong start project set.

By Visual Studio 17 do you mean Visual Studio 2019?
Have you tried Visual Studio 2022?