Linux 下配置OpenGL开发环境

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ProgramVAE/article/details/79530316

Linux 下配置OpenGL开发环境

sudo apt-get install build-essential   
sudo apt-get install libgl1-mesa-dev  
sudo apt-get install libglu1-mesa-dev   
sudo apt-get install freeglut3-dev  

测试代码

  1 #include <GL/glut.h>
  2 
  3 void init(void)
  4 {
  5     glClearColor(0.0, 0.0, 0.0, 0.0);
  6     glMatrixMode(GL_PROJECTION);
  7     glOrtho(-5, 5, -5, 5, 5, 15);
  8     glMatrixMode(GL_MODELVIEW);                                                                      
  9     gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
 10 
 11     return;
 12 }
 13 
 14 void display(void)
 15 {
 16     glClear(GL_COLOR_BUFFER_BIT);
 17     glColor3f(1.0, 0, 0);
 18     glutWireTeapot(3);
 19     glFlush();
 20 
 21     return;
 22 }
 23 
 24 
 25 int main(int argc, char** argv)
 26 {
 27     glutInit(&argc, argv);
 28     glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
 29     glutInitWindowPosition(0, 0);
 30     glutInitWindowSize(300, 300);
 31     glutCreateWindow("Opengl First");
 32     init();
 33     glutDisplayFunc(display);
 34     glutMainLoop();
 35 }

编译运行

gcc -o test test.c -lglut -lGL -lGLU

效果如下
这里写图片描述

猜你喜欢

转载自blog.csdn.net/ProgramVAE/article/details/79530316