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>,否则嘛,可就编译不了啊!!!

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值