【问题标题】:C++/SFML Window creation failC++/SFML 窗口创建失败
【发布时间】:2012-07-22 03:09:31
【问题描述】:

好吧,我尝试按照tutorial 中所示的方式执行所有操作,但它只显示控制台,仅此而已。试过这个时钟程序,它工作得很好。我连接了所有库,并复制了所有 .dll 文件,所以真的不知道我错在哪里。请告诉我如何显示使其显示窗口。我正在使用 VS2010,SFML 1.6,这是我的代码。

    #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();

          }
     };

【问题讨论】:

    标签: c++ visual-studio-2010 window sfml


    【解决方案1】:

    试试这个:

    #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;
    }
    

    【讨论】:

    • 仍然只显示控制台,并且窗口不会显示。我的 VS 2010 中既没有错误也没有警告。我需要这一切尽快。我希望有办法让它工作,或者有一些像 SMFL(面向对象的 ofc)一样简单的图形引擎。
    【解决方案2】:

    您是否链接到 sfml-main 库?如果没有,请尝试,如果失败,请尝试执行 WinMain 而不是 main() 函数。另外,请确保 Visual Studio 没有将您的项目设置为控制台程序。

    【讨论】:

      【解决方案3】:

      我最近一直在使用 SFML。按顺序尝试这些建议,保留之前的每个更改:

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

      应该是 sf::RenderWindow,而不是 sf::Window

      应该是while (App.isOpen())而不是IsOpened()

      如果您的 RenderWindow 上似乎没有“isOpen”功能,您可能没有 SFML2,我建议您立即获取。

      您是否为您的计算机重建了库,或者您是否只是尝试使用它们提供的 .dll?您可能需要使用 Cmake 重建它们,无论您的编译器是什么。我知道我做到了。

      最后,我还建议您使用最新的 Code::Blocks 作为您的 IDE,但我想只能在万不得已的情况下切换。

      【讨论】:

        【解决方案4】:

        老问题..但这是我的回答:当你说; “我正在使用 VS2010,SFML 1.6...”,在下载页面中说对于 Windows 中的 sfml-1.6,可以使用 VScode 2005 和 VScode 2009。尝试使用不同的Vscode 版本(并链接所有内容进行测试),看看它是否有效。

        (对我来说,您的代码在 SFML-1.6 上看起来不错,所以我认为这不是问题)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-06-03
          • 2013-02-01
          • 2021-05-15
          • 1970-01-01
          • 1970-01-01
          • 2021-03-17
          • 2021-12-10
          • 1970-01-01
          相关资源
          最近更新 更多