2013-10-11 75 views
2

我有以下用頂點數組繪製三角形的程序,如SFML教程中所述。SFML VertexArray不是sf的成員

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

int main() 
{ 
    try{ 
     sf::RenderWindow Mywindow(sf::VideoMode(800,600),"TriColor Triangle!"); 


     sf::VertexArray triangle(sf::Triangles, 3); 

     triangle[0].position = sf::Vector2f(5,5); 
     triangle[1].position = sf::Vector2f(50,5); 
     triangle[2].position = sf::Vector2f(50,50); 

     triangle[0].color = sf::Color::Red; 
     triangle[1].color = sf::Color::Blue; 
     triangle[2].color = sf::Color::Green; 

     Mywindow.draw(triangle); 
    } 
    catch(const std::runtime_error& e) 
    { 
     std::cout << e.what() << std::endl; 
     std::cin.ignore(); 
     return EXIT_FAILURE; 
    } 

    std::cin.ignore(); 
    return EXIT_SUCCESS; 
} 

的makefile我使用編譯如下:

all: exe 

exe: main.o 
     g++ main.o -o exe -lsfml-graphics -lsfml-window -lsfml-system 

main.o: main.cpp 
     g++ -c main.cpp 

正在顯示follwing錯誤:

make 
g++ -c main.cpp 
main.cpp: In function ‘int main()’: 
main.cpp:11:2: error: ‘VertexArray’ is not a member of ‘sf’ 
main.cpp:11:18: error: expected ‘;’ before ‘triangle’ 
main.cpp:13:2: error: ‘triangle’ was not declared in this scope 
main.cpp:21:11: error: ‘class sf::RenderWindow’ has no member named ‘draw’ 
main.cpp:23:33: error: expected unqualified-id before ‘&’ token 
main.cpp:23:33: error: expected ‘)’ before ‘&’ token 
main.cpp:23:33: error: expected ‘{’ before ‘&’ token 
main.cpp:23:35: error: ‘e’ was not declared in this scope 
main.cpp:23:36: error: expected ‘;’ before ‘)’ token 
make: *** [main.o] Error 1 

我不明白爲什麼跟它VertexArray不sf的成員!

+0

它完美對我很好。確保你的系統上沒有安裝兩個版本的SFML。 – Hiura

+0

我想我的系統沒有完全安裝SFML。許多頭文件不在那裏。無論如何謝謝你的回覆! –

回答

1

您必須提供SFML庫目錄的路徑和SFML包含目錄的路徑。

像這樣:

"-IC:\\Path\\to\\your\\project\\your-lib-sub-dir\\SFML-2.1\\include" 
"-LC:\\Path\\to\\your\\project\\your-lib-sub-dir\\SFML-2.1\\lib" 

另一件事,要能夠看到的東西,你應該是這樣的suround您繪製調用:

while(1){ 
    Mywindow.clear(sf::Color::Black); 
    Mywindow.draw(triangle); 
    Mywindow.display(); 
} 
+1

我想我的系統沒有完全安裝SFML。許多頭文件不在那裏。無論如何謝謝你的回覆! –

+0

也許[我的回答](http://stackoverflow.com/a/21541442/1218980)上的另一個SFML問題可能會幫助你。 –

+1

感謝您的鏈接! –

相關問題