这段时间总是想使用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
- Make a directory "C:/mingw".
- Download the MinGW installer to your "C:/mingw" directory and run it. Leave the selected items to install as is, and click "Next."
- Download the MSYS installer to your "C:/mingw" directory and run it.
- If prompted, annswer "yes" to the finish-up script, and type in the path to MinGW ("C:/mingw") when prompted.
- Download MSYS DTK 1.0 to your "C:/msys/1.0" directory and run it.
- Download MSYS Core 1.0.11 to your "C:/msys/1.0" directory, and unzip it there.
- 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>".
- You can now use your editor to create C++ files, save them under this directory somewhere, and then use "make" to compile them.
- Move on to the "installing GLUT" section below, if you need to.
Installing GLUT
- Download this GLUT archive to your "C:/mingw" directory.
- 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).
- When compiling, use
#include <gl/glut.h>
to include the glut header. - When linking, use "-lglut32win" in the link line of your make file
- 不过那个如何才能将黑框框消失还是需要考虑一下啊。
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>,否则嘛,可就编译不了啊!!!
好了,现在万事具备,可以开工了!!!!!!