0

I am on an M1 Macbook if that changes anything. I am using SFML 2.5.1 also. Here is what the code looks like:

// Include important libraries here
#include <SFML/Graphics.hpp>

// Make code easier to type with "using namespace"
using namespace sf;

// This is where our game starts from
int main()
{
    // Create a video mode object
    VideoMode vm(1920, 1080);

    // Create and open a window for the game
    RenderWindow window(vm, "Timber!!!", Style::Fullscreen);

    while (window.isOpen())
    {
    
        // Handle the players input
    
        if (Keyboard::isKeyPressed(Keyboard::Escape))
        {
            window.close();
        }
    
        // Update the scene
    
        // Draw the scene
    
        // Clear everything from the last scene
        window.clear();
    
        // Draw our game scene here
    
        // Show everything we just drew
        window.display();
    
    }
    return 0; 
}

However, when I run this, no window opens and I get multiple warnings. Now I have no idea if these warning have anything to do with the window not opening, but I thought I would include that detail.

The warnings I receive are as follows:

/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window/Keyboard.hpp:161:41: Declaration is marked with '\deprecated' command but does not have a deprecation attribute
/Users/charlescreighton/Desktop/stuff/xcode_projects/Timber/Timber/main.cpp:9:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/Timber/Timber/main.cpp:9:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics.hpp:32:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics.hpp:32:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window.hpp:37:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window.hpp:37:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window/Event.hpp:33:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window/Event.hpp:33:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window/Event.hpp:105:10: Declaration is marked with '\deprecated' command but does not have a deprecation attribute
/Users/charlescreighton/Desktop/stuff/xcode_projects/Timber/Timber/main.cpp:9:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/Timber/Timber/main.cpp:9:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics.hpp:32:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics.hpp:32:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window.hpp:37:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Window.hpp:37:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/PrimitiveType.hpp:52:43: Declaration is marked with '\deprecated' command but does not have a deprecation attribute
/Users/charlescreighton/Desktop/stuff/xcode_projects/Timber/Timber/main.cpp:9:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/Timber/Timber/main.cpp:9:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics.hpp:34:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics.hpp:34:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/CircleShape.hpp:32:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/CircleShape.hpp:32:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/Shape.hpp:34:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/Shape.hpp:34:
/Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/VertexArray.hpp:33:10: in file included from /Users/charlescreighton/Desktop/stuff/xcode_projects/External Libraries/SFML/include/SFML/Graphics/VertexArray.hpp:33:

And if that is confusing, here is an image of the warnings:

Warnings I described above

When I click on the 3 warnings to see where they appear, this is what it shows:

First warning location:

First warning location

Second warning location:

Second warning location

Third warning location:

Third warning location

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Time to read a few more [good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Jesper Juhl Dec 22 '22 at 20:22

1 Answers1

0

I am assuming that the issue is related to how you manage your window event handling system! the way you handle your event is by using sf::Keyboard! instead of using the properly way with sf::Event! if your not using the sf::Event to handle the window event then the window will freeze on windows Operating system. And maybe on mac the window will not be created!

The properly way to create a window is

// Include important libraries here
#include <SFML/Graphics.hpp>

// Make code easier to type with "using namespace" = false
// 
// stop using namespace because this will bug your code in 
// bigger project
//using namespace sf;

// This is where our game starts from = false
// This is the main entry point of our application
int main()
{
    // Create a video mode object
    // you dont really need to create VideMode object you 
    // can directly include it in the constructor of sf::RenderWindow
    // VideoMode vm(1920, 1080);

    // Create and open a window for the game
    RenderWindow window(sf::VideoMode(1920, 1080), "Timber!!!", Style::Fullscreen);

    //Create An Event Variable to poll the events from the window
    //and then to manage them 
    sf::Event event{};

    //This is the Game Loop
    while (window.isOpen())
    {
        // Handle the players input

        //poll event from the window
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Escape)
                window.close();
        }

        // Update the scene

        // Draw the scene

        // Clear everything from the last scene
        window.clear(sf::Color::Blue);

        // Draw our game scene here

        // Show everything we just drew
        window.display();
    }
    return 0;
}
The BOSS
  • 1
  • 1