openGL 学习1--ubuntu中安装openGL与第一个绘图程序

来源:互联网 发布:airplay for windows 编辑:程序博客网 时间:2024/06/06 23:18

ubuntu 中安装openGL:

1.建立基本编译环境:

$ sudo apt-get install build-essential  

2.安装OpenGL Library

$sudo apt-get install libgl1-mesa-dev

3.安装OpenGL Utilities

$sudo apt-get install libglu1-mesa-dev

4.安装OpenGL Utility Toolkit
$sudo apt-get install libglut-dev
注意在这一步的时候,如果出现 E: 未发现软件包 libglut-dev情况,

请输入将上述$sudo apt-get install libglut-dev命令改成$sudo apt-get install freeglut3-dev


openGL测试程序:

#include void init();void display();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;}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);}void display(){    glClear(GL_COLOR_BUFFER_BIT);    glColor3f(1.0, 0, 0);    glutWireTeapot(3);    glFlush();} 


编译与执行:

gcc example.c -o main -lGL -lGLU -lglut

./main


参考:

http://www.linuxidc.com/Linux/2012-05/60771.htm###





0 0
原创粉丝点击