参考:https://blog.csdn.net/jjhfen00/article/details/50646834,但是vs的路径相比原文有变化。
1. glut下载
2. 环境配置
.h文件
glut.h 放入路径 D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\ 14.12.25827 (版本可能不一样) \include\GL\
,GL文件夹手动创建。
.lib 文件
glut32.lib 放入路径 D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib\x86\
glut.lib 放入路径 D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib\x64\
.dll文件
glut.dll 和 glut32.dll 放入C:\Windows\SysWOW64\
glut32.dll 放入C:\Windows\System32\
3. 测试程序
#include <GL/glut.h>
void init()
{
glClearColor(1.0, 1.0, 1.0, 1.0); // set display-window color to white
glMatrixMode(GL_PROJECTION); // set projection parameters
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void lineSegment()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0, 0.0, 0.0); // Set line segment color to red
glBegin(GL_LINES);
glVertex2i(180, 15);
glVertex2i(10, 145);
glEnd();
glFlush(); // Process all OpenGL routines as quickly as possible
}
void main(int argc, char ** argv)
{
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Set display mode
glutInitWindowPosition(50, 100); // Set top-left display-window position
glutInitWindowSize(400, 300); // Set display-window width and height
glutCreateWindow("An Example OpenGL Program"); // Create display window
init(); // Execute initialization procedure
glutDisplayFunc(lineSegment); // Send graphics to display window
glutMainLoop(); // Display everything and wait
}
网友评论