eryar

PipeCAD - Plant Piping Design Software.
RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
posts - 603, comments - 590, trackbacks - 0, articles - 0

使用OpenGL中的GLUT

Posted on 2011-11-20 15:36 eryar 阅读(5678) 评论(4)  编辑 收藏 引用

 

为了使作图部分更简单,从而更好地理解曲线、曲面的理论,所以使用了OpenGL的GLUT工具来实现。

从OpenGL网站http://www.opengl.org下载GLUT,下载后有以下几个文件且需要手动安装:

glut.h ——— glut头文件;

glut32.lib—— glut静态库;

glut32.dll—— glut动态库;

安装分为以下几步:

1. 将glut.h放到编译器默认的包含文件夹中,如 ...\include\GL, gl.h和glu.h应该就在那个文件夹内;

2. 将glut32.lib放到编译器默认的静态库中,如 ...\Lib\;

3. 最后将glut32.dll放在操作系统的System32文件夹中: 如C:\Windows\System32;

安装完GLUT库后,若要在Visual C++中使用,需要做以下设置:

在菜单Project->Settings中,或按快捷键Alt+F7出现Project Settings对话框,在Link选项中,在如图A1所示位置添加上要使用的OpenGL库:

opengl32.lib glu32.lib glut32.lib

clip_image002

图A1. 添加GLUT库

一个简单的GLUT示例程序的源程序如下所示:

 

 1 // An Example OpenGL Program 
 2 
 3 #include <gl\glut.h> 
 4 
 5 void    Initialize(void); 
 6 void    DrawScene(void); 
 7 
 8 void main(int argc, char* argv[]) { 
 9     glutInit(&argc, argv);                            // Initialize GLUT 
10     glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);        // Set display mode 
11     glutInitWindowPosition(50,100);                    // Set top-left display window position 
12     glutInitWindowSize(400300);                    // set display window width and height 
13     glutCreateWindow("An Example OpenGL Program");    // Create display window 
14 
15     Initialize();                                    // Execute initialization procedure 
16     glutDisplayFunc(DrawScene);                        // Send graphics to display window 
17 
18     glutMainLoop();                                    // Display everything and wait 
19 
20 
21 /* 
22 */ 
23 void    Initialize(void) { 
24     //glClearColor(1.0, 1.0, 1.0, 0.0);                // Set Display-window color to white 
25     glMatrixMode(GL_PROJECTION);                    // Set projection parameters 
26     glLoadIdentity(); 
27     gluOrtho2D(0.02000.0150);                    // 
28 // Initialize 
29 
30 /* 
31 */ 
32 void    DrawScene(void) { 
33     glClear(GL_COLOR_BUFFER_BIT);                    // Clear display window 
34 
35     glColor3f(1.00.00.0f);                        // set line segment geometry color to red 
36     glBegin(GL_LINES); 
37         glVertex2i(00); 
38         glVertex2i(190140); 
39     glEnd(); 
40 
41     glFlush();                                        // Process all OpenGL routines as quickly possible 
42 // DrawScene
43 

 

Feedback

# re: 使用OpenGL中的GLUT[未登录]  回复  更多评论   

2013-09-28 10:01 by Young
opengl32.lib这个东西是在哪里的?

# re: 使用OpenGL中的GLUT  回复  更多评论   

2013-09-28 10:37 by eryar
在VisualStudio的目录里面,OpenGL32.dll是在Windows的系统目录里面。
安装好VisualStudio后,库OpenGL32.lib就已经有了
@Young

# re: 使用OpenGL中的GLUT[未登录]  回复  更多评论   

2014-05-15 15:29 by Jerry
1>------ 已启动生成: 项目: wy_2, 配置: Debug Win32 ------
1>生成启动时间为 2014/5/15 星期四 15:25:20。
1>InitializeBuildStatus:
1> 正在对“Debug\wy_2.unsuccessfulbuild”执行 Touch 任务。
1>ClCompile:
1> 1.cpp
1>ManifestResourceCompile:
1> 所有输出均为最新。
1>LINK : fatal error LNK1104: 无法打开文件“opengl32.lib glu32.lib glut32.lib”
1>
1>生成失败。
1>
1>已用时间 00:00:01.39
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
这是怎么回事啊??

# re: 使用OpenGL中的GLUT  回复  更多评论   

2014-05-15 17:55 by eryar
没有找到opengl32.lib, glu32.lib和glut32.lib。

@Jerry

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理