一、环境介绍
二、opengGL的环境配置
2.1 在这里我们有三个资源文件,分别为dll,GL和lib文件夹
动态链接库dll(dynamic link library)
C:\Windows\System32
C:\Windows\SysWOW
GL文件
D:\vs\VC\lib
2.3 在visual studio中进行环境配置
三、环境测试
#define GLUT_DISABLE_ATEXIT_HACK
#include <Windows.h>
#include <glut.h> // (or others, depending on the system in use)
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // Set display-window color to white.
glMatrixMode(GL_PROJECTION); // Set projection parameters.
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void lineSegment(void)
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window.
glColor3f(0.0, 0.4, 0.2); // Set line segment color to green.
glBegin(GL_LINES);
glVertex2i(180, 15); // Specify line-segment geometry.
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.
}
四、运行结果
五、问题与解决
OpenGL和C++有不太融合的地方,在include时要让标准C++类库的头文件位于GLUT图形库头文件之前。
#include <Windows.h>
#include <glut.h>
运行提示缺少OPENGL.DLL的原因
#include <Windows.h>
在glut.h头文件之前添加#define GLUT_DISABLE_ATEXIT_HACK
#define GLUT_DISABLE_ATEXIT_HACK
#include <Windows.h>
#include <glut.h>
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务