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

Author Topic: Visual Studio 17 Black RenderWindow  (Read 778 times)

0 Members and 1 Guest are viewing this topic.

pallen@fgcu.edu

  • Newbie
  • *
  • Posts: 1
    • View Profile
Visual Studio 17 Black RenderWindow
« 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");
    window.clear(WINDOW_COLOR);

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

    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)
                window.close();
        }

        // Render drawing objects
        // ------------------------------------------------
        window.clear(WINDOW_COLOR);
        window.draw(ball);
        window.display();
    }
    return 0;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10224
    • View Profile
    • development blog
    • Email
Re: Visual Studio 17 Black RenderWindow
« Reply #1 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

 

anything