OpenGL(英语:Open Graphics Library,译名:开放图形库或者“开放式图形库”)是用于渲染2D、3D矢量图形的跨语言、跨平台的应用程序编程接口(API)。这个接口由近350个不同的函数调用组成,用来绘制从简单的图形到比较复杂的三维景象。OpenGL常用于CAD、虚拟现实、科学可视化程序和电子游戏开发。幽兰本上默认并没有包含这个库,如果你需要使用它,必须自己下载编译。

1. 下载OpenGL代码

git clone https://github.com/opengl-tutorials/ogl.git
Cloning into 'ogl'...
remote: Enumerating objects: 16016, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 16016 (delta 0), reused 0 (delta 0), pack-reused 16015
Receiving objects: 100% (16016/16016), 84.08 MiB | 5.22 MiB/s, done.
Resolving deltas: 100% (8357/8357), done.

2. 安装依赖

sudo apt-get install libgl1-mesa-dev \
    libglu1-mesa-dev \
    freeglut3-dev

3. 切换分支

cd ogl/

ls
BUILDING.txt                  tutorial05_textured_cube
CMakeLists.txt                tutorial06_keyboard_and_mouse
Makefile                      tutorial07_model_loading
common                        tutorial08_basic_shading
distrib                       tutorial09_vbo_indexing
external                      tutorial10_transparency
misc01_math_cheatsheet        tutorial11_2d_fonts
misc04_building_your_own_app  tutorial12_extensions
misc05_picking                tutorial13_normal_mapping
playground                    tutorial14_render_to_texture
tutorial01_first_window       tutorial15_lightmaps
tutorial02_red_triangle       tutorial16_shadowmaps
tutorial03_matrices           tutorial17_rotations
tutorial04_colored_cube       tutorial18_billboards_and_particles

git checkout 2.1_branch
branch '2.1_branch' set up to track 'origin/2.1_branch'.
Switched to a new branch '2.1_branch'

4. 编译

mkdir build
cd build/
cmake ..
make

5. 运行

完成编译后在build目录会生成的可执行脚本。

pwd
/home/geduer/ogl/build

ls
CMakeCache.txt                           launch-tutorial17_rotations.sh
CMakeDoxyfile.in                         launch-tutorial18_billboards.sh
CMakeDoxygenDefaults.cmake               launch-tutorial18_particles.sh
CMakeFiles                               misc05_picking_BulletPhysics
Makefile                                 misc05_picking_custom
cmake_install.cmake                      misc05_picking_slow_easy
external                                 playground
launch-misc05_picking_BulletPhysics.sh   tutorial01_first_window
launch-misc05_picking_custom.sh          tutorial02_red_triangle
launch-misc05_picking_slow_easy.sh       tutorial03_matrices
launch-playground.sh                     tutorial04_colored_cube
launch-tutorial01_first_window.sh        tutorial05_textured_cube
launch-tutorial02_red_triangle.sh        tutorial06_keyboard_and_mouse
launch-tutorial03_matrices.sh            tutorial07_model_loading
launch-tutorial04_colored_cube.sh        tutorial08_basic_shading
launch-tutorial05_textured_cube.sh       tutorial09_AssImp
launch-tutorial06_keyboard_and_mouse.sh  tutorial09_several_objects
launch-tutorial07_model_loading.sh       tutorial09_vbo_indexing
launch-tutorial08_basic_shading.sh       tutorial10_transparency
launch-tutorial09_AssImp.sh              tutorial11_2d_fonts
launch-tutorial09_several_objects.sh     tutorial12_extensions
launch-tutorial09_vbo_indexing.sh        tutorial13_normal_mapping
launch-tutorial10_transparency.sh        tutorial14_render_to_texture
launch-tutorial11_2d_fonts.sh            tutorial15_lightmaps
launch-tutorial12_extensions.sh          tutorial16_shadowmaps
launch-tutorial13_normal_mapping.sh      tutorial16_shadowmaps_simple
launch-tutorial14_render_to_texture.sh   tutorial17_rotations
launch-tutorial15_lightmaps.sh           tutorial18_billboards
launch-tutorial16_shadowmaps.sh          tutorial18_particles
launch-tutorial16_shadowmaps_simple.sh

运行./launch-tutorial03_matrices.sh后,就可以直接看到画面了。

作者:朱博渊  创建时间:2023-05-16 13:25
最后编辑:朱博渊  更新时间:2024-12-20 17:01