标签:QT lib OpenGL openGL Assimp 报错 include 加载
QT openGL Assimp 模型加载
前言
最近重温learnopengl 教程,开发中经常遇到模型加载,故记录下学习过程…
开发环境: Qt5.12.7 +MSVC2017 X64
一、Assimp 编译
Assimp 详情:https://learnopengl-cn.github.io/03%20Model%20Loading/01%20Assimp/
1.CMake 编译,生成vs工程
2.vs生成lib、dll
二、模型加载
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引起的
修改方式:在需要#include 头文件的地方 改用class 类名 代替,在cpp文件中#include头文件
2、glActiveTexture 、glBindBuffer…找不到标识符,但有些glxxx函数又没报错,这就很尴尬了,报错均在Mesh、Model类的.h文件中的函数
opengl 库函数提供的方式是:glew.h +glew32.lib
修改方式:
gl函数报错的类 public方式继承 QOpenGLExtraFunctions,并在构造函数中 执行
initializeOpenGLFunctions();!!! 一定要初始化,不然就是编译通过,运行崩溃
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,lib,OpenGL,openGL,Assimp,报错,include,加载 来源: https://blog.csdn.net/jiang173707/article/details/116295852
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。