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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SimonB

Pages: [1]
1
SFML Forum. I come to you in a time of great need.

I am starting to learn C++, after learning Python, and I want to learn C++ in an entreating way; that is, by making games with SFML. I am following a book which you can find [here][1]. The problem is that, when using a basic example, listed below, SFML does not create a window. (Sorry for my use of using namespace)

My Code:

    // Include important C++ libraries here
    #include <SFML/Graphics.hpp>
   
    // Make code easier to type with "using namespace"
    using namespace sf;
   
    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);
   
        // Low res code
        RenderWindow window(vm, "Timber!!!");
   
        // Create a texture to hold a graphic on the GPU
        Texture textureBackground;
   
        // Load a graphic into the texture
        textureBackground.loadFromFile("graphics/background.png");
   
        // Create a sprite
        Sprite spriteBackground;
   
        // Attach the texture to the sprite
        spriteBackground.setTexture(textureBackground);
   
        // Set the spriteBackground to cover the screen
        spriteBackground.setPosition(0, 0);
   
   
        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 frame
            window.clear();
   
            // Draw our game scene here
            window.draw(spriteBackground);
   
            // Show everything we just drew
            window.display();
   
   
        }
   
        return 0;
    }

An image of what happens when I build and execute is below
[![The Image][2]][2]

I tried to reinstall SFML, make the window smaller (the book suggests that I create a smaller, 960-pixel-wide VideoMode object and then window.draw() the original 1920/1080 picture*, but this did not work), re-build the project, execute it from XCode, and copy the SFML.dll files into my main project directory (and also I checked for my project directory).

Is this normal? Do you know how I can fix it? Notice how it takes up my screen as if it were the app which I am currently using. Thank you for your time.



*  As a footnote, I ran some other SFML examples to check the correctness of my SFML installation. The ran successfully.

  [1]: https://www.amazon.com/Beginning-Game-Programming-program-building/dp/1838648577/ref=sr_1_2?dchild=1&keywords=learn%20c%2B%2B%20by%20making%20games&qid=1593817894&sr=8-2
 

The link to my photo is here: https://i.stack.imgur.com/D8KuF.png

Pages: [1]