linux环境下安装OpenGL

mac2024-04-10  32

环境配置:Ubuntu-16.04
1) 下载与安装
sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev sudo apt-get install libglu1-mesa-dev sudo apt-get install libegl1-mesa-dev sudo apt-get install freeglut3-dev
2) 新建test.c
#include <GL/glut.h>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(); }
3) 编译并运行
gcc -o test test.c -lGL -lGLU -lglut ./test

最新回复(0)