首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Ubuntu上搭建OpenGL开发环境-HelloWorld

2012-09-08 
Ubuntu下搭建OpenGL开发环境-HelloWorld首先用Eclipse搭建C++开发环境。这里不强求Eclipse,有其他的如CodeB

Ubuntu下搭建OpenGL开发环境-HelloWorld

首先用Eclipse搭建C++开发环境。这里不强求Eclipse,有其他的如CodeBlockc等。环境搭建好了之后,进行第一个程序。沿用教课数的习惯,我们叫他HelloWorld程序,当然这里并没有HelloWorld字样。改程序仅用来测试开发环境是否已经搭建好。

?

首先新建工程,然后添加两个文件:

1.main.cpp

#include <GL/glut.h>#include <stdlib.h>#include <stdio.h>#include "app.h"using namespace std;int main(int argc, char **argv){    glutInit(&argc, argv);    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);    glutInitWindowPosition(0, 0);    glutInitWindowSize(300, 300);    glutCreateWindow("OpenGl 3D View");    Application::Init();    glutDisplayFunc(Application::display);    glutMainLoop();    return 0;}
?

2. app.h

#ifndef APP_H_#define APP_H_#include <GL/glu.h>class Application{public:    static void Init()    {        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);    }    static void display()    {        glClear(GL_COLOR_BUFFER_BIT);        glColor3f(1.0, 0, 0);        //glutWireTeapot(3);        glutWireIcosahedron();        glFlush();    }};#endif /* APP_H_ */
?

其次,配置库,对工程添加libGL.so,libGLU.so,libglut.so。

?

?

执行编译并运行。

?

?

附录:

参考网站:www.linuxidc.com/Linux/2011-09/42146.htm

?

热点排行