• Linux OpenGL 实践篇-1 OpenGL环境搭建


    开发环境

    本次实践所使用环境为CentOS 7。

    参考:http://www.xuebuyuan.com/1472808.html

    OpenGL库安装

    1.opengl库安装

      opengl库使用mesa库,安装命令:

    yum intall mesa*

      mesa库是一个开源的三维计算机图形库,以开源的形式实现了opengl应用程序接口。具体介绍:https://www.mesa3d.org/intro.html。

    2.glut安装

      下载freeglut,下载地址为: https://github.com/dcnieho/FreeGLUT/releases。glut是opengl的实用工具库,opengl只是三维图形接口,并没有窗口,处理鼠标等设备输入输出方面的内容,glut提供了相关方面的内容。freeglut是glut的一个发行版本(还有一个是原始版本的glut)。

      因为我使用cmake安装,根据README.cmake中步骤及注意事项安装。

      命令:

      cmake . 
      make
      make install

    3.简单例子

    新建文件main.cpp

    #include <GL/glut.h>
    #include <stdlib.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();
    }

    编译命令:

    gcc -lglut -lGLU -lGL main.cpp

  • 相关阅读:
    2019牛客暑期多校训练营(第三场)D Big Integer
    ZOJ2432 Greatest Common Increasing Subsequence(最长公共上升子序列)
    AGC031 C
    UPC11456 视线(计算几何)
    tmp
    jQuery与Ajax
    JQuery介绍
    Week12(11月25日)
    Week11(11月21日)
    Week11(11月19日):补课
  • 原文地址:https://www.cnblogs.com/xin-lover/p/8367639.html
Copyright © 2020-2023  润新知