Qt中配置glut庫 ( Windows )
2012.05.03
Qt本身不包括glut工具庫,如果要使用glut庫,該怎么做呢?
下面來簡述一下Qt下怎么安裝glut庫:
1.首先需要去opengl的官網下載glut庫:
http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
2.解壓后,將glut32.lib和glut.lib兩個文件拷貝到qt目錄下的./lib文件夾中;
3.將glut.dll和glut32.dll兩個動態鏈接庫拷貝到C:\windows\system32中;
4.將glut.h文件拷貝到qt目錄下的\include\QtOpenGL中,並建立glut文件【內容寫上 #include "glut.h"】,保存為沒有后綴名的文件;
5.切換到自己的程序中,在 **.pro 文件中添加:
LIBS += -lgut32
LIBS += -LC:\glut
6. 在main.cpp中加入“#include<glut>”或者“#include<glut.h>”,這樣就可以使用glut中的函數了。
7. 下面來看一個簡單的例子:
1 #include <windows.h> 2 #include <glut.h> 3 void init(void) 4 { 5 glClearColor(1.0, 1.0, 1.0, 0.0); 6 glMatrixMode(GL_PROJECTION); 7 gluOrtho2D(0.0, 200.0, 0.0, 160.0); 8 } 9 void lineSegment(void) 10 { 11 glClear(GL_COLOR_BUFFER_BIT); 12 glColor3f(1.0, 0.0, 0.0); 13 glBegin(GL_LINES); 14 glVertex2i (180, 15); 15 glVertex2i (10, 145); 16 glEnd(); 17 glFlush(); 18 } 19 int main(int argc, char **argv) 20 { 21 glutInit(&argc, argv); 22 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 23 glutInitWindowPosition(50, 100); 24 glutInitWindowSize(400, 300); 25 glutCreateWindow("Example OpenGL Program"); 26 init(); 27 glutDisplayFunc(lineSegment); 28 glutMainLoop(); 29 }
運行效果如下圖所示: