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工程

在这里插入图片描述在这里插入图片描述在这里插入图片描述

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.

总结

运行效果:
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值