其实,VS2013已经自带了OpenGL的核心库(gl前缀)和实用程序库(glu前缀)了!安装后VS后可以发现已经有相关文件了
但是没有安装实用程序工具包(OpenGL Utility Toolkit, GULT)。网上大部分教程就是安装这个GULT库的教程。gult提供了与平台无关的基于窗口的工具,例如窗口的初始化,多窗口管理,菜单管理等。使用这个工具包创建的程序可以在所有支持OpenGL的平台上运行。
包含头文件的时候,glut.h会保证gl.h和glu.h会被正确包含。
下面介绍glut的安装方法
1. 下载glut
https://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
2.将解压后的文件放在指定文件夹
glut.dll,glut32.dll 放到 C:\Windows\SysWOW64 这是64位操作系统 如果是32位就放倒C:\Windows\System32
两个.lib文件放到C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
3. 测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <GL/glut.h> /* glut.h includes gl.h and glu.h*/ void display(void) { /* clear window */ glClear(GL_COLOR_BUFFER_BIT); /* draw unit square polygon */ glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); /* flush GLbuffers */ glFlush(); } void init() { /* set clear color to black */ glClearColor(0.0, 0.0, 0.0, 0.0); /* set fill color to white */ glColor3f(1.0, 0.0, 0.0); /* set up standard orthogonal view with clipping */ /* box as cube of side 2 centered at origin */ /*This is default view and these statement could be removed */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } void main(int argc, char** argv) { /* Initialize mode and open a window in upper left corner of screen */ /* Window title is name of program (arg[0]) */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow("simple"); glutDisplayFunc(display); init(); glutMainLoop(); } |