1

因此,正如标题所示,我正在尝试在Windows 7上的CodeBlocks (MinGW v.4.7.0)中使用SFML 1.6创建一个简单的窗口(不,我没有使用 ATI GPU)。

这是代码:

#include <SFML/Window.hpp>

int main()
{
    sf::Window App(sf::VideoMode(800, 600, 16), "SFML Window");
    App.Display();

    return 0;
}

每当我尝试运行此代码时,它只会说Program.exe is not responding并且必须使用Close this program. 有趣的是,SFML 教程网站上提供的第一个教程(sf::Clock在控制台中使用的那个)可以正常工作,因此可以正确加载库。

有人可以帮我找到错误的原因吗?

除了崩溃之外,我没有收到任何编译器或应用程序错误。

4

2 回答 2

1

The problem is that you haven't created the main loop which polls for events and handles OS messages. Append this to main() (yes, this is a snippet from the SFML documentation):

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
   App.Clear();

   // Put your update and rendering code here...

   // Update the window
   App.Display();
}

It is therefore not necessary for you to call App.Display() after you create the window.

于 2012-10-29T05:30:49.703 回答
0

对于那些想要整件事的人​​来说,这是从SFML 网站中提取的一个片段。

#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "SFML Window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }    

    return 0;
}

你会得到:

于 2019-01-17T15:32:04.753 回答