标签:des style class blog c code
This
is a simple tutorial to show a new linux user (such as myself) how to setup
freeglut and OpenGl.
OS: ubuntu 12.1
I have just
recently become a linux user and wanted to install freeglut to do my graphics
assignments on my laptop. Although the install did not turn out to be very
difficult it took me a while to do. So I have written this tutorial in case
another young linux user comes along and decides he/she wants to install
freeglut and OpenGL.
**This tutorial assumes that you have your
operating system installed and you have access to the internet**
Steps:
From a terminal
1) sudo apt-get update
-This will update your apt database to the most recent available packages.
2) sudo apt-get install build-essential
- This installs the
necessary development tools for building source code.
3) sudo apt-get
install freeglut3-dev
- This installs the development libraries and
headers for freeglut.
Your done! Extremely simple! However you must
remember that when compiling you must add a ‘-lglut‘ as a comand line argument
to gcc. If you don‘t it cannot find the library‘s and you will get undefined
reference errors.
example command line: gcc simple.c -lglut
At this point if your program compiles and runs then you are finished. However
the first time I tried to run mine I received a ‘libGL warning: 3D driver
claims to not support visual 0x42‘. This error means I cannot display the
required colors to run the program. In my case I had the most recent drivers
for my video card. So I did some research on my monitor and found out it can
display a color depth of 24 instead of the 16 it was set at. To fix this
problem you must edit the /etc/X11/xorg.conf file as root and set the
‘DefaultDepth 24‘. Reboot and the problem is solved.
This is my first
post (and tutorial) on the ubuntuforums. If people feel that this tutorial is
not needed they can feel free to remove it. If anyone wants to add anything
related to freeglut or OpenGl please feel free.
完成上述操作,可以通过以下程序进行验证环境安装的正确性。
测试
示例test.c源码:
编译程式时,执行以下指令:
执行:
2.使工程包含OpenGL/Glut 等相关的链接库
菜单的“project” ----- “Build Options” ---------“ Linkersettings”中进行设置
添加文件:libGL.so libglut.so libGLU.so
如下图
选择“加入”按钮,根据自己ubuntu中的具体位置进行添加。
完成上述步骤后,就可以进行Debug了。
也可以进行下面这几个步骤,可以实现在codeblocks下直接创建openGL工程。
$ sudo apt-get install build-essential gdb subversion
$ sudo apt-get
install automake autoconf libtool
$ sudo apt-get install libgtk2.0-dev
libxmu-dev libxxf86vm-dev
这样,在codeblocks里面新建工程就可以了,新建glut工程的话,会自带一个例子。如果只做了前两步,编译的时候就会报错,说找不到Xxf86vm。去Ubuntu论坛逛了一圈,回来,做了后3个步骤,就顺利的编译运行了。
创 建 GLUT 工程时,选择 GULT‘s Location时,直接输入 /usr 即可。因为/usr下面就有include和lib两个子文件夹。可是在Windows下面,我就搞不定如何能有这两个子文件夹的文件夹。每次都说不能包 含进去glut.h头文件。没有办法,只能到linux下面来折腾。不过还是要研究一下。
这个是codeblocks自带的glut工程的例子。新建工程的时候出来的。编译运行后的图:
ubuntu下openGL的配置方法,布布扣,bubuko.com
标签:des style class blog c code
原文地址:http://www.cnblogs.com/L-Arikes/p/3737451.html