2010-12-22 73 views
2

我最近开始尝试使用SFML。出于某种原因,我的简单程序不会渲染窗口。我试着把所有东西都扔进主体,看看我的代码中是否有一个错误,与多个文件等有关,但无济于事。窗口拒绝渲染

我会发动我的程序并没有什么会出现。

有什么问题?

//main.h 
#ifndef MAIN_H 
#define MAIN_H 

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

#include <iostream> 
#include <fstream> 

using namespace std; 
using namespace sf; 

class game 
{ 
    public: 
    void startLoop(int SCREEN_W, int SCREEN_H, string SCREEN_NAME); 
    void log(const string logging); 

    game() 
    { 
     QUIT = false; 

     pendingFile.open("Log.txt", ios::out); 
     pendingFile << "---Brain Bread Log---"; 
    } 

    ~game() 
    { 
     pendingFile.close(); 
    } 

    private: 
    bool QUIT; 
    ofstream pendingFile; 
}; 

#endif 


//main.cpp 
#include "main.h" 

void game::log(const string logging) 
{ 
    pendingFile << logging; 
} 

void game::startLoop(int SCREEN_W, int SCREEN_H, string SCREEN_NAME) 
{ 
    Window Game(VideoMode(SCREEN_W, SCREEN_H, 32), SCREEN_NAME); 
    while(QUIT == false) 
    { 
     Game.Display(); 
    } 
} 


int main(int argc, char* argv[]) 
{ 
    game gameObj; 

    gameObj.startLoop(800, 600, "Brain Bread"); 

    return 0; 
} 

回答

2

我想你的代码,它的行为完全按照我期望它 - 这是说,采用黑色机身的iconless窗口弹出,并没有对事件做出响应。那是你正在得到什么?如果没有,你可能需要重建SFML。

你可能想尝试引入事件处理,使您的startLoop看起来更像是这样的:

void game::startLoop(int SCREEN_W, int SCREEN_H, string SCREEN_NAME) 
{ 
    // Init stuff 

    while (Game.IsOpened()) 
    { 
     sf::Event newEvent; 

     while (Game.GetEvent(newEvent)) 
     { 
      // Process event 
     } 

     // Do graphics stuff 

     Game.Display(); 
    } 
} 
+0

1)感谢您对循环尖端!和2.)我会尝试重新加载SFML。 – Lemmons 2010-12-23 07:00:28