在VC6.0环境下配置glut.h文件

首先,下载OpenGL类库的常用文件,配置应用环境。

    Windows环境下的GLUT下载地址:(大小约为150k)
    http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

    windows下glut的配置步骤:

    1、将下载的压缩包解开,将得到5个文件
    2、把解压得到的glut.h放到“Program Files\Microsoft VisualStudio\VC98\Include\GL“这个文件夹。
    3、把解压得到的glut.lib和glut32.lib放到“Program Files\Microsoft Visual Studio\VC98\lib”文件夹。
    4、把解压得到的glut.dll和glut32.dll放到操作系统目录下面的system32文件夹内。
        (典型的位置为:C:\Windows\System32)

    
    其次,配置VC6.0中的工程。

    

 

   1、新建一个Win32 Console Application工程,选择simple application,点击Finish
    2、 按照如下顺序选择:

         Project → Settings → Link选项卡

         然后,在Object/library modules下面的文本框的最前面添加如下库文件内容:

         Opengl32.lib glut32.lib GLAUX.LIB Glu32.lib

         最后,在Project Options中修改subsystem:console修改为subsystem:windows。点击OK。

    3、再按照如下顺序选择:

         Project → Settings → C/C++选项卡

         将Preprocessor definitions 中的_CONSOLE修改为_WINDOWS。点击OK。



     完成配置,即可测试OpenGL库是否配置成功。

    

     这里附上一个网上的测试程序~~
     经过测试,很好用哦~~~

     

     首先,在stdafx.h文件中加入

        #include <windows.h>
      #include <GL/glu.h>
      #include <GL/gl.h>

      #include <GL/glut.h>
      #include <GL/glaux.h>

      注意:#include <windows.h>是需要的,不引入的话有时会报错。
    
     其次, 编写主文件,例如 test.cpp

#include <stdafx.h>  
void background(void)  
{  
   //设置背景颜色为黑色  
   glClearColor(0.0,0.0,0.0,0.0);  
}  
  
void myDisplay(void)  
{  
//buffer设置为颜色可写  
glClear(GL_COLOR_BUFFER_BIT);  
//开始画三角形  
glBegin(GL_TRIANGLES);  
//设置为光滑明暗模式  
glShadeModel(GL_SMOOTH);  
//设置第一个顶点为红色  
glColor3f(1.0,0.0,0.0);  
//设置第一个顶点的坐标为(-1.0,-1.0)  
glVertex2f(-1.0,-1.0);  
//设置第二个顶点为绿色  
glColor3f(0.0,1.0,0.0);  
//设置第二个顶点的坐标为(0.0,-1.0)  
glVertex2f(0.0,-1.0);  
//设置第三个顶点为蓝色  
glColor3f(0.0,0.0,1.0);  
//设置第三个顶点的坐标为(-0.5,1.0)  
glVertex2f(-0.5,1.0);  
//三角形结束  
glEnd();  
//强制OpenGL函数在有限时间内运行  
glFlush();  
}  
  
void myReshape(GLsizei w,GLsizei h)  
{  
glViewport(0,0,w,h);  
//设置视口  
  
glMatrixMode(GL_PROJECTION);  
//指明当前矩阵为GL_PROJECTION  
glLoadIdentity();  
//将当前矩阵置换为单位阵  
  
if(w <= h)  
gluOrtho2D(-1.0,1.5,-1.5,1.5*(GLfloat)h/(GLfloat)w);  
//定义二维正视投影矩阵  
else  
gluOrtho2D(-1.0,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5);  
glMatrixMode(GL_MODELVIEW);  
//指明当前矩阵为GL_MODELVIEW  
}  
  
int main(int argc, char* argv[])  
{  
// 初始化  
glutInit(&argc,argv);  
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);  
glutInitWindowSize(400,400);  
glutInitWindowPosition(200,200);  
  
//创建窗口  
glutCreateWindow("Triangle");  
  
//绘制与显示  
background();  
glutReshapeFunc(myReshape);  
glutDisplayFunc(myDisplay);  
  
glutMainLoop();  
return(0);  
}   

 参考http://huxiaoheihei.iteye.com/blog/1477931

posted @ 2017-10-14 18:21  奇热行  阅读(893)  评论(0)    收藏  举报