QT openGL Assimp 模型加载

QT openGL Assimp 模型加载

前言

最近重温learnopengl 教程,开发中经常遇到模型加载,故记录下学习过程…
开发环境: Qt5.12.7 +MSVC2017 X64

一、Assimp 编译

Assimp 详情:https://learnopengl-cn.github.io/03%20Model%20Loading/01%20Assimp/

1.CMake 编译,生成vs工程

QT openGL Assimp 模型加载_第1张图片QT openGL Assimp 模型加载_第2张图片QT openGL Assimp 模型加载_第3张图片

2.vs生成lib、dll

QT openGL Assimp 模型加载_第4张图片QT openGL Assimp 模型加载_第5张图片

二、模型加载

1.pro配置Assimp 库

在QT pro项目配置文件中添加Assimp 的include 和lib,
lib使用的绝对路径,显得不专业,demo嘛怎么方便怎么整啦
代码如下(示例):

INCLUDEPATH += $$PWD/Assimp/include
 LIBS += -L$$quote("D:\Works\code\opengl\QGLDemo\Assimp\libs\Debug") -lassimp-vc140-mt

2.Assimp 库使用

模型加载参照教程:https://learnopengl-cn.github.io/03%20Model%20Loading/03%20Model

这里记录下碰到的问题:
1、Model 类中用到stb_image.h 加载图片,而model类的函数实现均在.h文件,在其他.h文件中#include该文件时 报错,应该是
#define STB_IMAGE_IMPLEMENTATION引起的
QT openGL Assimp 模型加载_第6张图片QT openGL Assimp 模型加载_第7张图片

修改方式:在需要#include 头文件的地方 改用class 类名 代替,在cpp文件中#include头文件
QT openGL Assimp 模型加载_第8张图片

QT openGL Assimp 模型加载_第9张图片2、glActiveTexture 、glBindBuffer…找不到标识符,但有些glxxx函数又没报错,这就很尴尬了,报错均在Mesh、Model类的.h文件中的函数
opengl 库函数提供的方式是:glew.h +glew32.lib

QT openGL Assimp 模型加载_第10张图片
修改方式:
gl函数报错的类 public方式继承 QOpenGLExtraFunctions,并在构造函数中 执行
initializeOpenGLFunctions();!!! 一定要初始化,不然就是编译通过,运行崩溃
QT openGL Assimp 模型加载_第11张图片QT 对QOpenGLExtraFunctions的解释
This subclass of QOpenGLFunctions includes the OpenGL ES 3.0, 3.1 and 3.2 functions. These will only work when an OpenGL ES 3.x context, or an OpenGL context of a version containing the functions in question either in core or as extension, is in use. This allows developing GLES 3.x applications in a cross-platform manner: development can happen on a desktop platform with OpenGL 3.x or 4.x, deploying to a true GLES 3.x device later on will require no or minimal changes to the application.

Note: This class is different from the versioned OpenGL wrappers, for instance QOpenGLFunctions_3_2_Core. The versioned function wrappers target a given version and profile of OpenGL. They are therefore not suitable for cross-OpenGL-OpenGLES development.

总结

运行效果:
QT openGL Assimp 模型加载_第12张图片

你可能感兴趣的:(Troubleshoot,Opengl,qt,c++,opengl)