ubuntu下openGL的配置方法
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源码:
- #include <GL/glut.h>
- void init(void)
- {
- glClearColor(0.0, 0.0, 0.0,
0.0); - glMatrixMode(GL_PROJECTION);
- glOrtho(-5, 5,
-5, 5, 5, 15); - glMatrixMode(GL_MODELVIEW);
- gluLookAt(0, 0, 10, 0, 0, 0,
0, 1, 0); - return;
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0, 0, 0);
- glutWireTeapot(3);
- glFlush();
- return;
- }
- int main(int argc, char
*argv[]) - {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB
| GLUT_SINGLE); - glutInitWindowPosition(0, 0);
- glutInitWindowSize(300, 300);
- glutCreateWindow("OpenGL 3D View");
- init();
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
编译程式时,执行以下指令:
- $ gcc -o test test.c -lGL -lGLU -lglut
执行:
- $ ./test
- 效果图如下:

- codeblocks IDE 要使用的话,需要在建立了控制台程序后,对内部调试环境进行配置。
- 具体步骤如下:
- 1.新建一个Console Application 工程
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的配置方法的更多相关文章
- ubuntu下boost的配置方法
boost版本为: boost_1_52_0ubuntu版本为:ubuntu-12.04.1-desktop-i386 这里有两种安装方法: =============第一种: 也是最简单的:进入li ...
- Ubuntu下安装并配置VS Code编译C++
作者:tongqingliu 转载请注明出处:http://www.cnblogs.com/liutongqing/p/7069091.html Ubuntu下安装并配置VS Code编译C++ 安装 ...
- Ubuntu下安装并配置TexStudio
作者:tongqingliu 转载请注明出处:http://www.cnblogs.com/liutongqing/p/7069715.html Ubuntu下安装并配置TexStudio Ubunt ...
- ubuntu下安装和配置最新版JDK8傻瓜教程
ubuntu下安装和配置最新版JDK8傻瓜教程 听语音 | 浏览:18940 | 更新:2014-07-14 22:13 | 标签:ubuntu 1 2 3 4 5 6 分步阅读 ubuntu系统通常 ...
- Ubuntu下apache2安装配置(内含数字证书配置)
Ubuntu下apache2安装配置(内含数字证书配置)安装命令:sudo apt-get updatesudo apt-get install apache2 配置1.查看apache2安装目录命令 ...
- Ubuntu下安装和配置Apache2,小编觉得挺不错的,现在就分享给大家
本篇文章主要介绍了详解Ubuntu下安装和配置Apache2,小编觉得挺不错的,现在就分享给大家,也给大家做个参考.有兴趣的朋友可以了解一下.(http://xz.8682222.com) 在Ubun ...
- Ubuntu下PHP开发配置(新增redis、sphinx、sqlserver相关配置)
由于本人比较懒,所以一般都是用xampp的直接拿来改的…………(当然xampp中一般php版本都是比较新的用的过程中请大家注意哈,可能会和老版本冲突) 此次除了使用xampp外,还扩展了sphinx, ...
- Ubuntu下的网络配置(USTC)
1. 配置静态ip ubuntu的网络配置信息放在 /etc/network/interfaces 中 sudo gedit /etc/network/interfacesauto lo 下 ...
- linux之ubuntu下php环境配置
本文主要说明如何在Ubuntu下配置PHP开发环境LAMP. Ubuntu 搭建 php 环境 所谓LAMP:Linux,Apache,Mysql,PHP 安装 Apache2:(注意可以 ...
随机推荐
- PostgreSQL相关的软件,库,工具和资源集合
PostgreSQL相关的软件,库,工具和资源集合. 备份 wal-e - Simple Continuous Archiving for Postgres to S3, Azure, or Swif ...
- http 与https 安全链接
安全连接 Web应用最常见的用途之一是电子商务,可以利用Web服务器端程序使人们能够网络购物,需要指出一点是,缺省情况下,通过Internet发送信息是不安全的,如果某人碰巧截获了你发给朋友的一则消息 ...
- java数组 数组工具类Arrays
一.数组 1.java有严格的数据类型限制,一个数组只能声明一个数据类型,存放同一种数据类型. 2.虽然只能存放一种数据类型,假设A , 如果数据类型B 继承A,依然能存放进入数组. 3.数组的初始化 ...
- oracle设定用户密码使用时间
强制用户定期更换密码,要怎么设置? 假设密码用10天之后必须修改,宽限期为2天: 把电脑时间往后调十天,然后登录: 系统提示用户密码两天内失效,这时把电脑系统再往后调两天,然后登录: 系统提示密码已经 ...
- Android 自定义View修炼-自定义View-带百分比进度的圆形进度条(采用自定义属性)
很多的时候,系统自带的View满足不了我们功能的需求,那么我们就需要自己来自定义一个能满足我们需求的View,自定义View我们需要先继承View,添加类的构造方法,重写父类View的一些方法,例如o ...
- WTL 自定义 Button类-自绘
WTL 自绘Button类,支持按钮三种形态,正常模式,hover模式,鼠标按下模式,支持png图片.使用方法很简单: MyButton* pButton = new MyButton; pBut ...
- .net缓存应用与分析
在 ASP.NET 提供的许多特性中,相比 ASP.NET 的所有其他特性,缓存对应用程序的性能具有最大的潜在影响,利用缓存和其他机制,ASP.NET 开发人员可以接受使用开销很大的控件(例如,Dat ...
- Jquery Call WebDav
最近研究了一下WebDav,尝试了一下用Jquery.ajax 发生请求访问WebDav. 代码如下: <!DOCTYPE html> <html xmlns="http: ...
- 【转】JavaScript中的constructor与prototype
最初对js中 object.constructor 的认识: 在学习JS的面向对象过程中,一直对constructor与prototype感到很迷惑,看了一些博客与书籍,觉得自己弄明白了,现在记录如下 ...
- [XML] Resource帮助类
点击下载 Resources.rar /// <summary> /// 类说明:Resources /// 编 码 人:苏飞 /// 联系方式:361983679 /// 更新网站:[u ...