Prechádzať zdrojové kódy

V0.7.3
1、修改了PlayerGLWidget

apple 3 týždňov pred
rodič
commit
4714b072de

+ 32 - 9
demo/VideoPlayerGL/GLWidget/PlayerGLWidget.cpp

@@ -1,6 +1,7 @@
 #include "PlayerGLWidget.h"
 #include "spdlog/spdlog.h"
 #include <gl/gl.h>
+#include <qopenglext.h>
 
 
 
@@ -26,25 +27,23 @@ void PlayerGLWidget::initializeGL()
     /* -------------------------------------------------------------------------------------
      * 顶点数组对象
      * ------------------------------------------------------------------------------------ */
-    /* 创建一个顶点数组对象 */
-    GLuint VAO1;
     /* 生成一个VAO,返回的ID存储在VAO1中 */
     glGenVertexArrays(1, &VAO1);
-    /* 绑定VAO1到 GL_VERTEX_ARRAY 上,表示VAO1是一个顶点数组对象 */
     glBindVertexArray(VAO1);
 
+
     /* 创建一个三角形坐标数组,这里的z坐标都是0,表示平面2维 */
     float vertices[] = {
+        0.5f, 0.5f, 0.0f,   // 右上角
+        0.5f, -0.5f, 0.0f,  // 右下角
         -0.5f, -0.5f, 0.0f, // 左下角
-         0.5f, -0.5f, 0.0f, // 右下角
-         0.0f,  0.5f, 0.0f  // 顶部
+        -0.5f, 0.5f, 0.0f   // 左上角
     };
 
     /* -------------------------------------------------------------------------------------
      * 创建顶点数组缓冲区
      * (GLuint就是unsigned int) 
      * ------------------------------------------------------------------------------------ */
-    GLuint VBO1;
     /* 生成一个VBO,返回的ID存储在VBO1中 */
     glGenBuffers(1, &VBO1);
     /* OpenGL有很多缓冲对象类型,顶点缓冲对象的缓冲类型是GL_ARRAY_BUFFER
@@ -53,6 +52,22 @@ void PlayerGLWidget::initializeGL()
     /* 将顶点数据复制到缓冲区的内存中 */
     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
 
+    /* ---------------------------------------------------------------------------------------
+     * 创建EBO
+     * ------------------------------------------------------------------------------------ */
+    unsigned int indices[] = {
+        0, 1, 3, // 第一个三角形
+        1, 2, 3  // 第二个三角形
+    };
+    /* 创建一个EBO,返回的ID存储在EBO1中 */
+    glGenBuffers(1, &EBO1);
+    /* 绑定缓冲区 */
+    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO1);
+    glBufferData(EBO1, sizeof(indices), indices, GL_STATIC_DRAW);
+
+    
+
+
     /* -------------------------------------------------------------------------------------
      * 链接顶点属性
      * ------------------------------------------------------------------------------------ */
@@ -160,8 +175,7 @@ void PlayerGLWidget::initializeGL()
     /* 删除着色器对象,因为它们已经链接到着色器程序对象上了 */
     glDeleteShader(vertexShader);
     glDeleteShader(fragmentShader);
-    /* 使用着色器程序对象 */
-    glUseProgram(shaderProgram);
+    
     
 }
 
@@ -182,5 +196,14 @@ void PlayerGLWidget::paintGL()
      * 第二个参数是起始索引,这里是0,表示从第一个顶点开始绘制。
      * 第三个参数是顶点数量,这里是3,表示绘制3个顶点。
      */
-     glDrawArrays(GL_TRIANGLES, 0, 3);
+    //  glDrawArrays(GL_TRIANGLES, 0, 3);
+
+    /* 使用着色器程序对象 */
+    glUseProgram(shaderProgram);
+    /* 绑定VAO1到 GL_VERTEX_ARRAY 上,表示VAO1是一个顶点数组对象 */
+    glBindVertexArray(VAO1);
+    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
+    /* 解绑VAO1 */
+    glBindVertexArray(0);
+    
 }

+ 6 - 0
demo/VideoPlayerGL/GLWidget/PlayerGLWidget.h

@@ -4,6 +4,8 @@
 
 #include <QOpenGLWidget>
 #include <QOpenGLFunctions_3_3_Core>
+#include <gl/gl.h>
+#include <qopenglext.h>
 
 
 /**
@@ -30,6 +32,10 @@ protected:
 
 private:
 
+    GLuint VAO1 = 0; // 顶点数组对象的ID
+    GLuint VBO1 = 0; // 顶点缓冲对象的ID
+    GLuint EBO1 = 0; // 索引缓冲对象的ID
+    GLuint shaderProgram = 0; // 着色器程序对象的ID
 
 };