Could not create C ++ / SFML window

Well, I tried to do everything as shown in the tutorial , but it just shows the console and nothing else. I tried this hourly program and it works fine. I connected all the libraries and copied all the DLL files, so I really don't know where I am going wrong. Please tell me what to do to show it display a window. I am using VS2010, SFML 1.6 and here is my code.

    #include <SFML\Window.hpp>

    int main()
    {

         sf::Window App(sf::VideoMode(640, 480, 32), "wut");

         while (App.IsOpened())
         {
              sf::Event Event;
              while (App.GetEvent(Event))
              {
               // Window closed
               if (Event.Type == sf::Event::Closed)
                   App.Close();

               // Escape key pressed
               if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                  App.Close();        
               };
              App.Display();

          }
     };
+5
source share
3 answers

Try the following:

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear the screen (fill it with black color)
        App.Clear();

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}
0
source

Are you contacting sfml-main library? If not, try; if that fails, try instead of WinMain. Also, make sure that Visual Studio has not installed your project in the console program.

0

SFML. , :

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

sf:: RenderWindow, sf:: Window

This should while (App.isOpen())not be IsOpened ()

Unless you have the "isOpen" function on your RenderWindow, you probably don't have SFML2, which I recommend getting immediately.

Did you rebuild the libraries for your computer, or did you just try to use the .dlls that they provide? You may need to rebuild them using Cmake and any of your compilers. I know what I did.

Finally, I also recommend using the latest Code :: Blocks instead of your IDE, but I think only switch as a last resort.

0
source

All Articles