转载地址:http://blog.sina.com.cn/s/blog_6923201d0100wzye.html
本文假设读者已经在ubuntu下配置好了gcc/g++环境,并使用eclipse开发opengl程序
在ubuntu终端下运行以下命令,安装opengl所需要的库文件
$ sudo apt-get install build-essential
$ sudo apt-get install freeglut3-dev
运行一下opengl实例,测试配置的环境是否安装成功
在eclipse下新建一个工程文件,假设我们命名为Test,在工程Test里面新建一个C++源代码文件,这里我们把它命名为Main.cpp,在Main.cpp文件中打入以下代码:
#include <GL/glut.h>
void Init()
{
glClearColor(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);
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0, 0);
glutWireTeapot(3);
glFlush();
}
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;
}
添加库如图所示:
效果如图: