zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    ElasticSearch入门 第一篇:Windows下安装ElasticSearch
    Elasticsearch+Logstash+Kibana教程
    MySQL组合索引最左匹配原则
    mysql 有哪些索引
    MySQL配置优化
    MySQL分区和分表
    MySQL优化
    MySQL锁详解
    MySQL各存储引擎
    MySQL索引类型
  • 原文地址:https://www.cnblogs.com/xin-lover/p/8367639.html
Copyright © 2011-2022 走看看