2010-12-22 77 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