glut

本文详细介绍了如何在Linux环境下配置OpenGL和GLUT,包括解决链接问题、消除控制台窗口显示等常见问题。

这段时间总是想使用glut来学习opengl,可是在linux下总是不能发挥出最好的性能,因为linux对显卡的支持是在是太差了,说句心里话,虽然我的本配置的确不高,但是linux下连一半都发挥出来,还是微软的win7好啊。

起初是一连串的问题,不知道如何使用gcc链接。经过上网海量的google一下,再加上自己的连蒙带猜,终于知道如何了,哈哈哈。

gcc -o glutdemo glutdemo.c -lopengl32 -lglut32win

不过生成的程序离不开那个黑黑的窗口,这个很闹心啊。

这是我觉得最有用的一篇资料:

MinGW+OpenGL+GLUT "How-to-Install" Page

This page gives a quick explanation of how to install MinGW and OpenGL so that programs that use OpenGL + GLUT can be compiled and run under Windows.

More information on the MinGW tools can be found here .

 

Installing MinGW

  1. Make a directory "C:/mingw".
  2. Download the MinGW installer to your "C:/mingw" directory and run it. Leave the selected items to install as is, and click "Next."
  3. Download the MSYS installer to your "C:/mingw" directory and run it.
  4. If prompted, annswer "yes" to the finish-up script, and type in the path to MinGW ("C:/mingw") when prompted.
  5. Download MSYS DTK 1.0 to your "C:/msys/1.0" directory and run it.
  6. Download MSYS Core 1.0.11 to your "C:/msys/1.0" directory, and unzip it there.
  7. Upon completion, there should be a new item on your desktop to launch the MSYS shell (it looks like an "M"). Double click it, and you should be at a nice, Unix-like shell, in your home directory "/home/<your login name>".
  8. You can now use your editor to create C++ files, save them under this directory somewhere, and then use "make" to compile them.
  9. Move on to the "installing GLUT" section below, if you need to.

 

Installing GLUT

  1. Download this GLUT archive to your "C:/mingw" directory.
  2. Unpack the archive, and place the "GL/glut.h" file in "C:/mingw/include/gl" directory, the "winlib/libglut32win.a" file into the "C:/mingw/lib" directory, and "glut32.dll" into the "C:/windows/system32" directory (or leave it in the same directory as your executable).
  3. When compiling, use #include <gl/glut.h> to include the glut header.
  4. When linking, use "-lglut32win" in the link line of your make file
  5. 不过那个如何才能将黑框框消失还是需要考虑一下啊。

glut是OpenGL应用工具包(OpenGL Utility Toolkit),它为OpenGL提供了一个简易的窗口平台,使程序员不用过多的关心与平台相关的窗口系统.     建立工程时,我们一般都建立控制台程序(在vc6中即console win32 application)来使用glut库.但是在控制台程序下,运行时都会跳出控制台窗口,很不美观,我们可以用下面的方法将控制台窗口去掉:
#pragma comment(linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"" )
在主函数所在的.cpp文件的顶部加上上面的宏,就可以轻松将控制台窗口去掉,这样就只剩下glut窗口了

这个方法我试了,是不好使得,其实只要-mwindows就可以了。

这个-mwindows嘛,GCC手册上是这样说的:

The following is an excerpt from a makefile that will compile a Windows program
into a GUI executable:
hellowin.exe: hellowin.o hellowin.res
gcc -mwindows hellowin.o hellowin.res -o hellowin.exe

对于其他的控制台程序,如果也是用了-mwindows选项,则生成的程序双击运行时也不会产生窗口!甚至在控制台窗口输入名字都不显示!!!慎用!!!!

 

电脑没电了,郁闷,明天再弄!!!!!

还有那个头文件是一定要用#include <gl/gl.h> #include <gl/glut.h>的少一个也不行,多了一个也没用。

还有要说的是,顺序问题。一定要先#include <gl/gl.h>,否则嘛,可就编译不了啊!!!

好了,现在万事具备,可以开工了!!!!!!

### GLUT 工具包简介 GLUT(OpenGL Utility Toolkit)是一种用于简化 OpenGL 编程的工具包,主要用于创建和管理窗口以及处理输入事件。通过使用 GLUT,开发者可以更专注于核心图形渲染逻辑,而不必过多关注底层操作系统的细节[^2]。 --- ### GLUT 的功能特点 GLUT 提供了一系列的功能特性来支持 OpenGL 开发者的需求: - **跨平台支持**:尽管其原生设计主要针对 Unix/Linux 环境,但在 Windows 上也可以很好地运行。 - **简单的 API 接口**:提供了易于理解的函数接口,方便初学者快速入门。 - **多样的回调机制**:允许用户定义键盘、鼠标和其他交互行为的响应方式。 - **便捷的初始化流程**:可以通过几行代码完成窗口创建、上下文设置等工作[^3]。 --- ### GLUT 的下载与安装 #### 官方资源获取 可以从以下链接访问官方或社区维护的仓库以下载最新版本的 GLUT 文件: - [GitCode 下载页面](https://gitcode.com/open-source-toolkit/3c14d)[^2] 该压缩包通常会包含以下几个重要组件: - `glut.dll` / `glut32.dll`: 动态链接库文件,在程序运行时加载。 - `glut.lib` / `glut32.lib`: 静态链接库文件,编译阶段需要用到。 - `glut.h`: 头文件,声明了所有可用的 GLUT 函数原型。 #### Windows 平台下的环境配置步骤 以下是基于 Visual Studio IDE 进行 GLUT 库集成的具体指导[^4]: 1. 将头文件 (`glut.h`) 放入项目的 include 路径下; 2. 把静态库文件复制到 lib 目录,并告知链接器路径; 3. 对于动态库部分,则需将其放置至系统 PATH 中或者直接存放在可执行文件所在位置附近即可生效。 --- ### 基础示例代码展示 下面给出一段典型的 C++ 实现片段作为参考,演示如何利用 GLUT 创建一个基本的应用框架并绘制三角形形状对象: ```cpp #include <GL/glut.h> void display() { glClear(GL_COLOR_BUFFER_BIT); // 清屏命令 glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex2f(-0.5,-0.5); // 设置顶点颜色为红色 glColor3f(0.0, 1.0, 0.0); glVertex2f( 0.5,-0.5); // 设置顶点颜色为绿色 glColor3f(0.0, 0.0, 1.0); glVertex2f( 0.0, 0.5 ); // 设置顶点颜色为蓝色 glEnd(); glFlush(); // 刷新缓冲区使图像显示出来 } int main(int argc, char* argv[]) { glutInit(&argc, argv); // 初始化 GLUT glutCreateWindow("Simple Triangle"); // 创建窗口命名为 Simple Triangle glutDisplayFunc(display); // 注册绘图函数 glutMainLoop(); // 启动主消息循环 } ``` 上述例子展示了怎样借助 GLUT 构建起最简易形式的三维场景模型——即由三个不同色彩构成的一个平面几何体结构。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值