Win8.1下的OpenGL配置

 时间:2026-02-14 18:00:35

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配置

  • 福昕PDF编辑器如何设置自定义复选框
  • 语音芯片、语音IC选型表
  • 在家怎么做帐篷泥
  • SAI教程【No.1】:认识paint的精简版Photoshop
  • 中医怎么治疗牛皮癣
  • 热门搜索
    腮帮子疼怎么回事 日均存款怎么算 端午节的手抄报怎么画 肝肾阴虚怎么调理 肠胃炎怎么办 我的世界怎么输入指令 石家庄职业技术学院怎么样 siri怎么读 智能电表怎么看度数 新闻评论怎么写