Ubuntu openGL环境搭建

阅读: 评论:0

Ubuntu openGL环境搭建

Ubuntu openGL环境搭建

Linux上的OpenGL开发环境搭建:

在Linux下你需要链接libGL.so库文件,这需要添加-lGL到你的链接器设置中。如果找不到这个库你可能需要安装Mesa (sudo apt install mesa-utils)

对于用GCC编译的Linux用户建议使用这个命令行选项-lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -ldl。没有正确链接相应的库会产生 undefined reference (未定义的引用) 这个错误。

查看OpoenGL版本:glxinfo | grep -i opengl

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: NVIDIA GeForce GTX 1050 Ti/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 510.60.02
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6.0 NVIDIA 510.60.02
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 510.60.02
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

可能需要安装如下信赖库:

sudo apt install libxinerama-devsudo apt install libxcursor-devsudo apt install libxi-dev

GLFW 窗口

GLFW is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan application development. It provides a simple, platform-independent API for creating windows, contexts and surfaces, reading input, handling events, etc.

- x@x:~/cppProj/depends/$ git clone git@github:glfw/glfw.git
- x@x:~/cppProj/depends/glfw$ mkdir build
- x@x:~/cppProj/depends/glfw$ cd build/
- x@x:~/cppProj/depends/glfw/build$ cmake ..
- x@x:~/cppProj/depends/glfw/build$ make 
- x@x:~/cppProj/depends/glfw/build$ make install 

安装目录:

Install 
-- Install configuration: ""
-- Installing: /usr/local/lib/libglfw3.a
-- Installing: /usr/local/include/GLFW
-- Installing: /usr/local/include/GLFW/glfw3.h
-- Installing: /usr/local/include/GLFW/glfw3native.h
-- Installing: /usr/local/lib/cmake/ake
-- Installing: /usr/local/lib/cmake/ake
-- Installing: /usr/local/lib/cmake/ake
`-- Installing: /usr/local/lib/cmake/ake
-- Installing: /usr/local/lib/pkgconfig/glfw3.pc

## GLEW

The OpenGL Extension Wrangler Library (GLEW) is a cross-platform open-source C/C++ extension loading library.

git clone git@github:nigels-com/glew.git

OpenGL扩展库是个简单的工具,用于帮助C/C++开发者初始化扩展(OpenGL扩展功能)并书写可移植的应用程序。GLEW当前支持各种各样的操作系统,包含Windows,Linux,Darwin,Irix与Solaris。

x@x:~/cppProj/depends$ git clone git@github:nigels-com/glew.gitx@x:~/cppProj/depends/glew$ sudo make install
install -d -m 0755 "/usr/local/include/GL"
install -m 0644 include/GL/wglew.h "/usr/local/include/GL/"or:
sudo apt-get install libglew-dev

GLM 矩阵库

OpenGL Mathematics (GLM) is a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.
GLM provides classes and functions designed and implemented with the same naming conventions and functionality than GLSL so that anyone who knows GLSL, can use GLM as well in C++.

GLM是OpenGL Mathematics的缩写,它是一个只有头文件的库,也就是说我们只需包含对应的头文件就行了,不用链接和编译。GLM可以在它们的网站上下载。把头文件的根目录复制到你的includes文件夹,然后你就可以使用这个库了。

x@x:~/cppProj/depends$ git clone git@github:g-truc/glm.git
x@x:~/cppProj/depends/glm$ mkdir build
x@x:~/cppProj/depends/glm$ cd build/x@x:~/cppProj/depends/glm/build$ cmake ..
x@x:~/cppProj/depends/glm/build$ make
x@x:~/cppProj/depends/glm/build$ sudo make install
[100%] Built target test-perf_vector_mul_matrixInstall 
-- Install configuration: ""-- Installing: /usr/local/include/glm
-- Installing: /usr/local/include/glm/mat4x2.hpp
-- Installing: /usr/local/include/glm/integer.hpp
-- Installing: /usr/local/include/glm/mat3x3.hpp-- Installing: /usr/local/include/glm/gtc
-- Installing: /usr/local/include/glm/gtc/matrix_inverse.hpp
-- Installing: /usr/local/include/glm/gtc/epsilon.inl
-- Installing: /usr/local/include/glm/gtc/bitfield.hpp-- Installing: /usr/local/include/glm/glm.hpp
-- Installing: /usr/local/include/glm/exponential.hpp
-- Installing: /usr/local/include/glm/packing.hpp-- Installing: /usr/local/include/glm/gtx
-- Installing: /usr/local/include/glm/gtx/intersect.hpp
-- Installing: /usr/local/include/glm/gtx/dual_quaternion.hpp-- Installing: /usr/local/include/glm/mat4x3.hpp
-- Installing: /usr/local/include/glm/vector_relational.hpp
-- Installing: /usr/local/include/glm/mat2x2.hpp
-- Installing: /usr/local/include/glm/vec4.hpp-- Installing: /usr/local/include/glm/detail
-- Installing: /usr/local/include/glm/detail/type_vec2.hpp
-- Installing: /usr/local/include/glm/detail/func_integer.inl-- Installing: /usr/local/include/glm/ext.hpp
-- Installing: /usr/local/include/glm/vec2.hpp
-- Installing: /usr/local/include/glm/geometric.hpp-- Installing: /usr/local/include/glm/simd
-- Installing: /usr/local/include/glm/simd/packing.h
-- Installing: /usr/local/include/glm/simd/exponential.h-- Installing: /usr/local/include/glm/mat2x4.hpp
-- Installing: /usr/local/include/glm/vec3.hpp-- Installing: /usr/local/include/glm/ext
-- Installing: /usr/local/include/glm/ext/vector_double2_precision.hpp
-- Installing: /usr/local/include/glm/ext/quaternion_transform.hpp-- Installing: /usr/local/include/glm/mat4x4.hpp
-- Installing: /usr/local/include/glm/common.hpp
-- Installing: /usr/local/include/glm/mat3x4.hpp
-- Installing: /usr/local/include/glm/fwd.hpp-- Installing: /usr/local/lib/cmake/ake
-- Installing: /usr/local/lib/cmake/ake

GLAD 图像加载

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.

GLAD的配置与大多数的开源库有些许的不同,GLAD使用了一个在线服务。在这里我们能够告诉GLAD需要定义的OpenGL版本,并且根据这个版本加载所有相关的OpenGL函数。

打开GLAD的在线服务,将语言(Language)设置为C/C++,在API选项中,选择3.3以上的OpenGL(gl)版本。之后将模式(Profile)设置为Core,并且保证选中了生成加载器(Generate a loader)选项。现在可以先(暂时)忽略扩展(Extensions)中的内容。都选择完之后,点击生成(Generate)按钮来生成库文件。

GLAD现在应该提供给你了一个zip压缩文件,包含两个头文件目录,和一个glad.c文件。将两个头文件目录(gladKHR)复制到你的Include文件夹中(或者增加一个额外的项目指向这些目录),并添加glad.c文件到你的工程中。

=c&specification=gl&api=gl%3D4.6&api=gles1%3Dnone&api=gles2%3D3.2&api=glsc2%3Dnone&profile=core&loader=on

经过前面的这些步骤之后,你就应该可以将以下的指令加到你的文件顶部了:

#include <glad/glad.h> 

将生成的文件复至系统目录下:

x@x:~/cppProj/depends/glad/include$ sudo cp -r . /usr/local/include/x@x:~/cppProj/depends/glad/src$ sudo cp -r . /usr/local/include/

ASSIMP 3D模型加载

/

Open Asset Import Library (assimp)
A library to import and export various 3d-model-formats including scene-post-processing to generate missing render data.

git clone git@github:assimp/assimp.git

/01%20Assimp/

一个非常流行的模型导入库是Assimp,它是Open Asset Import Library(开放的资产导入库)的缩写。Assimp能够导入很多种不同的模型文件格式(并也能够导出部分的格式),它会将所有的模型数据加载至Assimp的通用数据结构中。当Assimp加载完模型之后,我们就能够从Assimp的数据结构中提取我们所需的所有数据了。由于Assimp的数据结构保持不变,不论导入的是什么种类的文件格式,它都能够将我们从这些不同的文件格式中抽象出来,用同一种方式访问我们需要的数据。

当使用Assimp导入一个模型的时候,它通常会将整个模型加载进一个场景(Scene)对象,它会包含导入的模型/场景中的所有数据。Assimp会将场景载入为一系列的节点(Node),每个节点包含了场景对象中所储存数据的索引,每个节点都可以有任意数量的子节点

  • ubuntu安装assimp 方式1:

    x@x:~/cppProj/depends/$ git clone git@github:assimp/assimp.git
    x@x:~/cppProj/depends/assimp$ mkdir build
    x@x:~/cppProj/depends/assimp$ cd build/
    x@x:~/cppProj/depends/assimp/build$ cmake ..
    x@x:~/cppProj/depends/assimp/build$ make
    x@x:~/cppProj/depends/assimp/build$ sudo make install
    
x@x:~/cppProj/depends/assimp/build$ sudo make install
Install 
-- Install configuration: ""
-- Installing: /usr/local/lib/cmake/assimp-5.ake
-- Installing: /usr/local/lib/cmake/assimp-5.ake
-- Installing: /usr/local/lib/cmake/assimp-5.ake
-- Installing: /usr/local/lib/cmake/assimp-5.ake-- Installing: /usr/local/lib/pkgconfig/assimp.pc-- Installing: /usr/local/lib/libassimp.so.5.2.0
-- Installing: /usr/local/lib/libassimp.so.5
-- Installing: /usr/local/lib/libassimp.so-- Installing: /usr/local/include/assimp/anim.h
-- Installing: /usr/local/include/assimp/Compiler/pstdint.h-- Installing: /usr/local/bin/assimp
-- Set runtime path of "/usr/local/bin/assimp" to ""
  • ubuntu安装assimp 方式2:
    ubuntu有库支持,在软件中心或者命令行下安装libassimp-dev,libassimp3,assimp-utils

    sudo apt-get install libassimp-dev
    sudo apt-get install libassipm3
    sudo apt-egt install assimp-utils
    

SOIL 图像库

SOIL2 is a tiny C library used primarily for uploading textures into OpenGL.
SOIL2 is a fork of the Jonathan Dummer’s Simple OpenGL Image Library.
SOIL2 is a tiny C library used primarily for uploading textures into OpenGL. It is based on stb_image, the public domain code from Sean Barrett.
SOIL2 extended stb_image to DDS files, and to perform common functions needed in loading OpenGL textures.
SOIL2 can also be used to save and load images in a variety of formats (useful for loading height maps, non-OpenGL applications, etc.)

/
SOIL是简易OpenGL图像库(Simple OpenGL Image Library)的缩写,它支持大多数流行的图像格式,使用起来也很简单,你可以从他们的主页下载。像其它库一样,你必须自己生成.lib。你可以使用/projects文件夹内的任意一个解决方案(Solution)文件(不用担心他们的Visual Studio版本太老,你可以把它们转变为新的版本,这一般是没问题的。译注:用VS2010的时候,你要用VC8而不是VC9的解决方案,想必更高版本的情况亦是如此)来生成你自己的.lib文件。你还要添加src文件夹里面的文件到你的includes文件夹;添加SOIL.lib到你的链接器选项,并在你代码文件的开头加上#include <SOIL.h>

stb 图像库

stb

stb_image.h

single-file public domain (or MIT licensed) libraries for C/C++
stb single-file public domain libraries for C/C++

stb_image.h image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC

/06%20Textures/

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
x@x:~/cppProj/depends$ git clone git@github:nothings/stb.git
x@x:~/cppProj/depends$ cd stb/
x@x:~/cppProj/depends/stb$ sudo mkdir /usr/local/include/stb
x@x:~/cppProj/depends/stb$ sudo cp -. /usr/local/include/stb/ -r

Vulkan 安装:

sudo apt install vulkan-tools

模型下载:

.html
/
模型下载… obj格式 等

本文发布于:2024-02-02 17:35:55,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170686655345370.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

下一篇:linux PPTP
标签:环境   Ubuntu   openGL
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23