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

本文介绍如何在Windows环境下使用VC6.0配置OpenGL类库,并提供了两个测试程序实例,帮助读者验证配置是否成功。
首先,下载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

01.#include <stdafx.h>   
02.void background(void)  
03.{  
04.   //设置背景颜色为黑色   
05.   glClearColor(0.0,0.0,0.0,0.0);  
06.}  
07.  
08.void myDisplay(void)  
09.{  
10.//buffer设置为颜色可写   
11.glClear(GL_COLOR_BUFFER_BIT);  
12.//开始画三角形   
13.glBegin(GL_TRIANGLES);  
14.//设置为光滑明暗模式   
15.glShadeModel(GL_SMOOTH);  
16.//设置第一个顶点为红色   
17.glColor3f(1.0,0.0,0.0);  
18.//设置第一个顶点的坐标为(-1.0,-1.0)   
19.glVertex2f(-1.0,-1.0);  
20.//设置第二个顶点为绿色   
21.glColor3f(0.0,1.0,0.0);  
22.//设置第二个顶点的坐标为(0.0,-1.0)   
23.glVertex2f(0.0,-1.0);  
24.//设置第三个顶点为蓝色   
25.glColor3f(0.0,0.0,1.0);  
26.//设置第三个顶点的坐标为(-0.5,1.0)   
27.glVertex2f(-0.5,1.0);  
28.//三角形结束   
29.glEnd();  
30.//强制OpenGL函数在有限时间内运行   
31.glFlush();  
32.}  
33.  
34.void myReshape(GLsizei w,GLsizei h)  
35.{  
36.glViewport(0,0,w,h);  
37.//设置视口   
38.  
39.glMatrixMode(GL_PROJECTION);  
40.//指明当前矩阵为GL_PROJECTION   
41.glLoadIdentity();  
42.//将当前矩阵置换为单位阵   
43.  
44.if(w <= h)  
45.gluOrtho2D(-1.0,1.5,-1.5,1.5*(GLfloat)h/(GLfloat)w);  
46.//定义二维正视投影矩阵   
47.else  
48.gluOrtho2D(-1.0,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5);  
49.glMatrixMode(GL_MODELVIEW);  
50.//指明当前矩阵为GL_MODELVIEW   
51.}  
52.  
53.int main(int argc, char* argv[])  
54.{  
55.// 初始化   
56.glutInit(&argc,argv);  
57.glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);  
58.glutInitWindowSize(400,400);  
59.glutInitWindowPosition(200,200);  
60.  
61.//创建窗口   
62.glutCreateWindow("Triangle");  
63.  
64.//绘制与显示   
65.background();  
66.glutReshapeFunc(myReshape);  
67.glutDisplayFunc(myDisplay);  
68.  
69.glutMainLoop();  
70.return(0);  
71.}   


 再附上一个测试程序~~~~    

01.#include "stdafx.h"   
02.#include <stdlib.h>  //<math.h>   
03.#include <GL/glut.h>   
04.void myinit()  
05.{  
06.    glClearColor(0.0,0.0,0.0,0.0); // white background   
07.    glColor3f(1.0,1.0,1.0); // draw in red   
08.  
09.    // set up viewing   
10.    // 50.0 x 50.0 camera coordinate window with origin lower left   
11.  
12.    glMatrixMode(GL_PROJECTION);  
13.    glLoadIdentity();  
14.    gluOrtho2D(0.0,50.0,0.0,50.0);  
15.    glMatrixMode(GL_MODELVIEW);  
16.}  
17.  
18.void display()  
19.{  
20.    // a triangle   
21.    GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}};  
22.  
23.    int j,k;  
24.    int rand(); // rand number generator   
25.    GLfloat p[2]={7.5,5.0}; // arbitrary initial point inside triangle   
26.    glClear(GL_COLOR_BUFFER_BIT); // clear the window   
27.    glBegin(GL_POINTS);  
28.  
29.    // compute and plot 5000 new points   
30.  
31.    for( k=0; k<5000; k++)  
32.    {  
33.        j=rand()%3; //pick a vertex at random   
34.  
35.        // compute point halfway between selected vertex and old point   
36.  
37.        p[0]= (p[0] + vertices[j][0])/2.0;  
38.        p[1]= (p[1] + vertices[j][1])/2.0;  
39.  
40.        // plot new point   
41.        glVertex2fv(p);  
42.  
43.    }  
44.  
45.    glEnd();  
46.    glFlush(); // clear buffers   
47.  
48.}  
49.int main(int argc, char *argv[])  
50.  
51.{  
52.  glutInit(&argc, argv); // if no , still ok   
53.  glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);  // if no , still ok   
54.  glutInitWindowPosition(100, 100);  
55.  glutInitWindowSize(500, 500); //if no, windows goes to up-left corner   
56.  glutCreateWindow("Sierpinski Gasket");  //error, if no   
57.  glutDisplayFunc(&display);  //error, if no   
58.  myinit();  // set attributes   
59.  glutMainLoop();  //error, if no   
60.  
61.  return 0;  
62.}  


测试成功就完成啦~~~

原文出处:http://blog.youkuaiyun.com/hazqfp/article/details/7433789



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值