Win8.1下的OpenGL配置

2025-11-05 05:44:05

1、从网上下载GLUT后,解压即可。解压后共得到5个文件。

Win8.1下的OpenGL配置

2、我这里用VS版本是2013,安装在D盘。将解压后得到的glut.h放入“D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL”。注意:VS2013在include目录下没有GL文件夹,自己新建即可。

Win8.1下的OpenGL配置

3、将解压后得到的glut.lib 和 glut32.lib放入“D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib”。

Win8.1下的OpenGL配置

4、到此配置完毕。下面进行测试。打开VS2013,新建一个Win32控制台应用程序。在设置向导中选择“空项目”,然后向工程添加一个源文件“源.cpp”

Win8.1下的OpenGL配置

Win8.1下的OpenGL配置

5、在“源.cpp”中输入:

#include<GL\glut.h>

#include<math.h>

#include<iostream>

#define ColoredVertex(c,v)do{glColor3fv(c);glVertex3fv(v);}while(0)

#define WIDTH 400

#define HEIGHT 400

GLfloat angle = 0.0f;

void myDisplay(void)

{

static int list = 0;

if (list == 0)

{

GLfloat

PointA[] = { 0.5f, -sqrt(6.0f) / 12, -sqrt(3.0f) / 6 },

PointB[] = { -0.5f, -sqrt(6.0f) / 12, -sqrt(3.0f) / 6 },

PointC[] = { 0.0f, -sqrt(6.0f) / 12, sqrt(3.0f) / 3 },

PointD[] = { 0.0f, sqrt(6.0f) / 4, 0 };

GLfloat

ColorR[] = { 1, 0, 0 },

ColorG[] = { 0, 1, 0 },

ColorB[] = { 0, 0, 1 },

ColorY[] = { 1, 1, 0 };

list = glGenLists(1);

glNewList(list, GL_COMPILE);

glBegin(GL_TRIANGLES);

ColoredVertex(ColorR, PointA);

ColoredVertex(ColorG, PointB);

ColoredVertex(ColorB, PointC);

ColoredVertex(ColorR, PointA);

ColoredVertex(ColorB, PointC);

ColoredVertex(ColorY, PointD);

ColoredVertex(ColorB, PointC);

ColoredVertex(ColorG, PointB);

ColoredVertex(ColorY, PointD);

// 平面 BAD

ColoredVertex(ColorG, PointB);

ColoredVertex(ColorR, PointA);

ColoredVertex(ColorY, PointD);

glEnd();

glEndList();

glEnable(GL_DEPTH_TEST);

std::cout << list << std::endl;

}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();

glRotatef(angle, 1, 0.5, 0);

glCallList(list);

glPopMatrix();

glutSwapBuffers();

}

void myIdle(void)

{

angle+=0.01;

if (angle >= 360.0f)

angle = 0.0f;

myDisplay();

}

int main(int argc, char* argv[])

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

glutInitWindowPosition(200, 200);

glutInitWindowSize(WIDTH, HEIGHT);

glutCreateWindow("OpenGL 窗口");

glutDisplayFunc(&myDisplay);

glutIdleFunc(&myIdle);

glutMainLoop();

return 0;

}

运行结果如图。

Win8.1下的OpenGL配置

Win8.1下的OpenGL配置

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢