openGL的vc6.0配置
2016-06-21 00:00
387 查看
首先,下载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,64位系统则将glut32.dll放到C:\Windows\SysWOW64目录下,否则会提示:“计算机丢失 glut32.dll文件“)
其次,配置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。
注意:这里如果程序提示error LNK2001: unresolved external symbol _WinMain@16
则需要将上面“windows”的部分改回“console”即可。
完成配置,即可测试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
[cpp]view plaincopy
1. #include <stdafx.h>
2. void background(void)
3. {
4. //设置背景颜色为黑色
5. glClearColor(0.0,0.0,0.0,0.0);
6. }
7.
8. void myDisplay(void)
9. {
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. }
再附上一个测试程序~~~~
[cpp]view plaincopy
1. #include "stdafx.h"
2. #include <stdlib.h> //<math.h>
3. #include <GL/glut.h>
4. void myinit()
5. {
6. glClearColor(0.0,0.0,0.0,0.0); // white background
7. glColor3f(1.0,1.0,1.0); // draw in red
8.
9. // 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. }
测试成功就完成啦~~~
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,64位系统则将glut32.dll放到C:\Windows\SysWOW64目录下,否则会提示:“计算机丢失 glut32.dll文件“)
其次,配置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。
注意:这里如果程序提示error LNK2001: unresolved external symbol _WinMain@16
则需要将上面“windows”的部分改回“console”即可。
完成配置,即可测试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
[cpp]view plaincopy
1. #include <stdafx.h>
2. void background(void)
3. {
4. //设置背景颜色为黑色
5. glClearColor(0.0,0.0,0.0,0.0);
6. }
7.
8. void myDisplay(void)
9. {
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. }
再附上一个测试程序~~~~
[cpp]view plaincopy
1. #include "stdafx.h"
2. #include <stdlib.h> //<math.h>
3. #include <GL/glut.h>
4. void myinit()
5. {
6. glClearColor(0.0,0.0,0.0,0.0); // white background
7. glColor3f(1.0,1.0,1.0); // draw in red
8.
9. // 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. }
测试成功就完成啦~~~
相关文章推荐
- 查看CentOS版本方法
- Centos版本 32或64位查看命令
- Linux-Java线上故障排查一(高cpu使用率)
- 【 Linux 】Keepalived实现双主模型高可用集群
- Can't load AMD 64-bit .dll on a IA 32-bit platform
- Linux 盘符修改 & 开机自动挂载分区
- Linux下基于格式化命令 格式化的方法
- Linux centos 服务器乱码问题
- intellij 中 tomcate自动加载变更内容
- Linux下shell脚本的块注释
- xshell基于密钥登录
- 使用CXF动态客户端No operation was found with the name异常
- 站长如何选择合适的网站服务器
- shell 笔记
- 在Linux上使用的10种云备份方案
- docker上传镜像报错
- eclipse启动tomcat项目乱码而终端启动tomcat正常的解决办法
- 关于nohup命令
- Nginx禁止未定义的域名访问
- CentOS的ssh sftp配置及权限设置整理