博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
opengl glut vs2013配置
阅读量:4579 次
发布时间:2019-06-09

本文共 3760 字,大约阅读时间需要 12 分钟。

一.先下载opengl  glut库,解压缩后看里面的文件,应该包括glut.h,glut.lib,glut32.lib,glut.dll,glut32.dll.

二.将解压得到的头文件glut.h复制到目录如下目录下:X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL

 提示1:如果在incluce目录下没有GL文件夹,则需要手动创建。

 提示2:X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\是vs2013的安装目录。

三.解压后将得到的glut.lib和glut32.lib这两个静态函数库复制到文件目录的lib文件夹下 

X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib

四.将glut.dll,glut32.dll这两个动态库文件放到操作系统目录下面的C:\Windows\system32文件夹内(32位系统)或‪C:\Windows\SysWOW64(64位系统)。

为了兼容性考虑,最好在这两个目录下都复制相应的文件。

五.创建一个空的vs2013控制台应用平台。

六.将下面代码拷贝进项目中,此时应可无报错正确运行。

#include 
#include
#include
#include
static int year = 0,spin=0, day = 0;static GLint fogMode;const int n = 100;const GLfloat R = 1.0f;const GLfloat Pi = 3.1415926536f;void DrawCircle(){int i;glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_LINE_LOOP);for (i = 0; i < n; ++i){glColor3f(1.0, 0.0, 0.0);glVertex2f(R*cos(2 * Pi / n*i), R*sin(2 * Pi / n*i));}glEnd();glFlush();}void init(void){GLfloat position[] = { 0.5, 0.5, 3.0, 0.0 };glEnable(GL_DEPTH_TEST); //防止遮挡glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);{GLfloat mat[3] = { 0.1745, 0.01175, 0.01175 };glMaterialfv(GL_FRONT, GL_AMBIENT, mat);mat[0] = 0.61424; mat[1] = 0.04136; mat[2] = 0.04136;glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);mat[0] = 0.727811; mat[1] = 0.626959; mat[2] = 0.626959;glMaterialfv(GL_FRONT, GL_SPECULAR, mat);glMaterialf(GL_FRONT, GL_SHININESS, 0.6*128.0);}glEnable(GL_FOG);{GLfloat fogColor[4] = { 0.5, 0.5, 0.5, 1.0 };fogMode = GL_EXP;glFogi(GL_FOG_MODE, fogMode);glFogfv(GL_FOG_COLOR, fogColor);glFogf(GL_FOG_DENSITY, 0.35);glHint(GL_FOG_HINT, GL_DONT_CARE);glFogf(GL_FOG_START, 1.0);glFogf(GL_FOG_END, 5.0);}glClearColor(0.5, 0.9, 0.9, 1.0); /* fog color */}void display(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glColor3f(0.0, 1.0, 1.0); glPushMatrix(); //记住自己的位置glutSolidSphere(1.0, 20, 16); /* 画太阳半径、 20经度、16纬度*/glRotatef(spin, 0.0, 1.0, 0.0); //自转,绕着一个向量以给定角度旋转(正的为逆时针)glTranslatef(2.0, 1.0, 0.0);glRotatef(spin, 1.0, 0.0, 0.0); //公转glRectf(0.1,0.1,0.5,0.5);glColor3f(0.0, 0.0, 1.0);glutWireSphere(0.2, 8, 8); /* 画第一颗小行星 */glColor3f(1.0, 0.0, 0.0);glTranslatef(2.0, 1.0, 0.0);glRotatef(2 * spin, 0.0, 1.0, 0.0);glutSolidSphere(0.5, 16, 8);glPopMatrix();//回到原来的位置glutSwapBuffers();}void spinDisplay(void){spin = spin + 2;if (spin > 360)spin = spin - 360;glutPostRedisplay();}void mouse(int button,int state,int x,int y ){switch (button){case GLUT_LEFT_BUTTON:if (state == GLUT_DOWN)glutIdleFunc(spinDisplay);break;case GLUT_MIDDLE_BUTTON:if (state == GLUT_DOWN)glutIdleFunc(NULL);break;default:break;}}void reshape(int w, int h){glViewport(0, 0, (GLsizei)w, (GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60.0, (GLfloat)w / (GLfloat)h, 0.5, 20.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(0.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);}void keyboard(unsigned char key, int x, int y){switch (key) {case 'd':day = (day + 10) % 360;glutPostRedisplay();break;case 'D':day = (day - 10) % 360;glutPostRedisplay();break;case 'y':year = (year + 5) % 360;glutPostRedisplay();break;case 'Y':year = (year - 5) % 360;glutPostRedisplay();break;case 27:exit(0);break;default:break;}}int main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);glutInitWindowSize(400, 400);glutInitWindowPosition(100, 100);glutCreateWindow("OpengGL 程序设计--杨超");init();//glutDisplayFunc(DrawCircle);glutDisplayFunc(display);glutReshapeFunc(reshape);//glutKeyboardFunc(keyboard);glutMouseFunc(mouse);glutMainLoop();return 0;}

  

转载于:https://www.cnblogs.com/begoogatprogram/p/5787815.html

你可能感兴趣的文章
luogu_1015 回文数
查看>>
win7下怎么安装IIS
查看>>
linux服务器自动切割日志
查看>>
kali linux之操作系统识别/SMB扫描
查看>>
如何查看80端口是否被占用
查看>>
hdu 2119 Matrix 二分图
查看>>
GridControl 常用属性
查看>>
stream
查看>>
【深度学习基础】激活函数的理解和总结
查看>>
【Leetcode_easy】830. Positions of Large Groups
查看>>
好用的js模板
查看>>
Lightoj1084【DP啊DP】
查看>>
P3261 [JLOI2015]城池攻占
查看>>
[SCOI2009]windy数
查看>>
AngularJs ng-repeat指令中怎么实现含有自定义指令的动态html
查看>>
C++ Template 代码组织
查看>>
j2EE开发之代码优化心得
查看>>
Spring定时任务的几种实现
查看>>
Js 之将html转为图片html2canvas
查看>>
linux的 压缩与解压 命令集
查看>>