|
@@ -2,7 +2,6 @@
|
|
|
#include "spdlog/spdlog.h"
|
|
|
#include <qopenglext.h>
|
|
|
#include <QVariant>
|
|
|
-#include <QDateTime>
|
|
|
|
|
|
|
|
|
|
|
@@ -13,66 +12,75 @@ PlayerGLWidget::PlayerGLWidget(QWidget *parent) : QOpenGLWidget(parent)
|
|
|
|
|
|
PlayerGLWidget::~PlayerGLWidget()
|
|
|
{
|
|
|
+ if(m_shaderRGBA != nullptr) {
|
|
|
+ delete m_shaderRGBA;
|
|
|
+ m_shaderRGBA = nullptr;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
+/* 显示RGBA图片 */
|
|
|
+void PlayerGLWidget::showOneRGBAImage(const QImage& image)
|
|
|
+{
|
|
|
+ m_shaderRGBA->clearTexture(); // 清空纹理
|
|
|
+ m_shaderRGBA->createTexture(image, "textureRGBA"); // 创建纹理
|
|
|
+
|
|
|
+ m_shaderCurr = m_shaderRGBA; // 设置当前着色器为显示RGBA图片的着色器
|
|
|
+ update(); // 更新界面,触发paintGL函数
|
|
|
+}
|
|
|
|
|
|
|
|
|
void PlayerGLWidget::initializeGL()
|
|
|
{
|
|
|
+ SPDLOG_DEBUG("编译着色器...");
|
|
|
/* 初始化OpenGL函数,OpenGL的函数是在运行时才确定函数指针的 */
|
|
|
initializeOpenGLFunctions();
|
|
|
|
|
|
- m_shaderObj = new ShaderRect();
|
|
|
+ /* 初始化显示RGBA图片的着色器 */
|
|
|
+ m_shaderRGBA = new ShaderRect();
|
|
|
+
|
|
|
+ m_shaderRGBA->initShape(); // 初始化形状
|
|
|
|
|
|
- m_VAO1 = m_shaderObj->initShape(); // 初始化形状
|
|
|
- if(m_VAO1 == 0)
|
|
|
- {
|
|
|
- SPDLOG_ERROR("初始化形状失败");
|
|
|
- return;
|
|
|
- }
|
|
|
/* 初始化着色器 */
|
|
|
- QString vertexShaderFile = ":/shader/vertexShader.glsl";
|
|
|
- QString fragmentShaderFile = ":/shader/fragmentShader.glsl";
|
|
|
- if (!m_shaderObj->loadShaderCode(vertexShaderFile, fragmentShaderFile))
|
|
|
+ QString vertexShaderFile = ":/shaderCode/vertexShaderRGBA.glsl";
|
|
|
+ QString fragmentShaderFile = ":/shaderCode/fragmentShaderRGBA.glsl";
|
|
|
+ if (!m_shaderRGBA->loadShaderCode(vertexShaderFile, fragmentShaderFile))
|
|
|
{
|
|
|
SPDLOG_ERROR("加载着色器代码失败");
|
|
|
return;
|
|
|
}
|
|
|
/* 编译着色器 */
|
|
|
- m_shaderObj->compileShader();
|
|
|
- /* 创建纹理 */
|
|
|
- QString imageFile1 = QString(":/Image/image/1.jpg");
|
|
|
- QString imageFile2 = QString(":/Image/image/awesomeface.png");
|
|
|
+ m_shaderRGBA->compileShader();
|
|
|
|
|
|
- if (!m_shaderObj->createTexture(imageFile1, "ourTexture1"))
|
|
|
- {
|
|
|
- SPDLOG_ERROR("创建纹理失败");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!m_shaderObj->createTexture(imageFile2, "ourTexture2"))
|
|
|
- {
|
|
|
- SPDLOG_ERROR("创建纹理失败");
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
+ SPDLOG_DEBUG("着色器编译完成");
|
|
|
}
|
|
|
|
|
|
void PlayerGLWidget::resizeGL(int w, int h)
|
|
|
{
|
|
|
-
|
|
|
+ /* 设置视口 */
|
|
|
+ glViewport(0, 0, w, h);
|
|
|
+ /* 设置投影矩阵 */
|
|
|
+ // m_shaderObj->setProjectionMatrix(w, h);
|
|
|
+ // SPDLOG_INFO("resizeGL: width = {}, height = {}", w, h);
|
|
|
}
|
|
|
|
|
|
void PlayerGLWidget::paintGL()
|
|
|
{
|
|
|
+
|
|
|
/* glClearColor函数是一个状态设置函数,而glClear函数则是一个状态使用的函数,
|
|
|
* 它使用了当前的状态来获取应该清除为的颜色。 */
|
|
|
glClearColor(0.1f, 0.3f, 0.3f, 1.0f);
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
+ if(m_shaderCurr == nullptr)
|
|
|
+ {
|
|
|
+ // SPDLOG_WARN("当前着色器对象为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- m_shaderObj->useShader(); // 使用着色器
|
|
|
- m_shaderObj->drawShape(); // 绘制图形
|
|
|
+ m_shaderCurr->useShader(); // 使用着色器
|
|
|
+ m_shaderCurr->drawShape(); // 绘制图形
|
|
|
|
|
|
}
|