当前位置:网站首页>OpenGL index cache object EBO and lineweight mode
OpenGL index cache object EBO and lineweight mode
2022-07-03 12:00:00 【wb175208】
index registers
When drawing some graphs of connection , Usually some points are continuous , Points that can be reused . For example, coincident points , I only need to define it in memory once , Then in the graphics card cache can be reused , Just tell the location of the data . The index buffer is used here (EBO).
Two points need to be noted here : First of all, you need to configure VBO, And then you can use it EBO
The code is as follows :
#pragma once
#include <QOpenGLWindow>
#include <QOpenGLShader>
#include <QOpenGLShaderProgram>
class QOpenGLFunctions_3_3_Core;
// Use of index cache objects
class EBOWnd : public QOpenGLWindow{
Q_OBJECT
public:
EBOWnd();
~EBOWnd();
void initializeGL()override;
void resizeGL(int w, int h)override;
void paintGL()override;
private:
QOpenGLFunctions_3_3_Core* _openGLCore;
GLuint _EBO;
GLuint _VBO;
GLuint _VAO;
QOpenGLShaderProgram _shaderProgram;// Shader program , All shaders in the system
};
#include "EBOWnd.h"
#include <QOpenGLFunctions_3_3_Core>
EBOWnd::EBOWnd(){
}
EBOWnd::~EBOWnd(){
}
void EBOWnd::initializeGL() {
_openGLCore = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>();
/* ** First, list the points of all figures in a certain order , Then list an index table , Indicate which data is a group */
GLfloat ver[] = {
0.5f, 0.5f, 0.0f, // First quadrant
0.5f, -0.5f, 0.0f, // Quadrant four
-0.5f, -0.5f, 0.0f, // The third quadrant
-0.5f, 0.5f, 0.0f, // Beta Quadrant
};
GLuint idexVer[] = {
0, 1, 2, // The... In the array 0/1/2 Three points form the first triangle
1, 2, 3 // The first 1/2/3 Form the second triangle
};
// establish VAO, Used to record various data attributes
_openGLCore->glGenVertexArrays(1, &_VAO);
// binding VAO
_openGLCore->glBindVertexArray(_VAO);
// establish EBO VBO
_openGLCore->glGenBuffers(1, &_EBO);
_openGLCore->glGenBuffers(1, &_VBO);
// binding EBO VBO
_openGLCore->glBindBuffer(GL_ARRAY_BUFFER, _VBO);
_openGLCore->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _EBO);
// Transmit data
_openGLCore->glBufferData(GL_ARRAY_BUFFER, sizeof(ver), ver, GL_STATIC_DRAW);
_openGLCore->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idexVer), idexVer, GL_STATIC_DRAW);
/* ** Yes VBO Configure properties */
_openGLCore->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)0);
// Enable shader
_openGLCore->glEnableVertexAttribArray(0);
// Unbundling VAO
_openGLCore->glBindVertexArray(0);
// Unbundling VBO
_openGLCore->glBindBuffer(GL_ARRAY_BUFFER, 0);
// Unbundling EBO
_openGLCore->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
/* ** Shaders ** Shaders belong to dynamic compilation */
QOpenGLShader vertexShager(QOpenGLShader::Vertex);// Vertex shader
vertexShager.compileSourceFile("E:/Projects/QtGuiTest/OPenGLApp/shader/triangle.vert");
QOpenGLShader fragmentShager(QOpenGLShader::Fragment);// Fragment Shader
fragmentShager.compileSourceFile("E:/Projects/QtGuiTest/OPenGLApp/shader/triangle.frag");
_shaderProgram.addShader(&vertexShager);
_shaderProgram.addShader(&fragmentShager);
_shaderProgram.link();
}
void EBOWnd::resizeGL(int w, int h) {
}
void EBOWnd::paintGL() {
// Set clear color , Use the current color , Clear the background
_openGLCore->glClearColor(0.6f, 0.6f, 0.6f, 1.0f);
_openGLCore->glClear(GL_COLOR_BUFFER_BIT);
// Put the shader into the graphics card cache
_shaderProgram.bind();
_openGLCore->glBindVertexArray(_VAO);// Those states that will be remembered , It is equivalent to executing those functions once
/* ** The first parameter : Type of painting triangle ** The second parameter : Draw points , Two triangles are 6 A little bit ** The third parameter : data type , Type of index value idexVer Shaping for unsigned ** Fourth parameter : Set to 0 */
_openGLCore->glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
update();
}
Running results :
Wireframe mode
Let's reorder the dot index array
GLuint idexVer[] = {
0, 1, 2, // The... In the array 0/1/2 Three points form the first triangle , Clockwise
2, 0, 3 // The first 1/2/3 Form the second triangle , Anti-clockwise
};
Unbundling VAO This function is called before , You can see
The first parameter has multiple options :
#define GL_FRONT 0x0404
#define GL_BACK 0x0405
#define GL_FRONT_AND_BACK 0x0408
Respectively, before 、 after 、 Before and after .
Then what is the front and back of a polygon ?
stay OpenGL The normal vector of a face in , It is related to the order of points when drawing this face ;
Take the screen for example , If the point of a polygon is drawn clockwise , Then the normal vector goes inward from the screen , If it is counterclockwise, the direction of the normal vector is outward .
In accordance with the right-hand rule .
The outward direction of the normal vector is called the front , The inward direction of the normal vector is called the back
_openGLCore->glPolygonMode(GL_BACK, GL_LINE);
You can see the effect :
aaa
边栏推荐
- Raven2 of vulnhub
- [MySQL special] read lock and write lock
- Solve msvcp120d DLL and msvcr120d DLL missing
- STL教程8-map
- Hongmeng third training (project training)
- Notes on 32-96 questions of sword finger offer
- Deploying WordPress instance tutorial under coreos
- R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
- Oracle advanced (I) realize DMP by expdp impdp command
- 【学习笔记】dp 状态与转移
猜你喜欢

The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.

vulnhub之GeminiInc v2

外插散点数据

网络通讯之Socket-Tcp(一)

vulnhub之narak

Solve msvcp120d DLL and msvcr120d DLL missing

STL Tutorial 9 deep copy and shallow copy of container elements

【学习笔记】dp 状态与转移

解决msvcp120d.dll和msvcr120d.dll缺失

Excel quick cross table copy and paste
随机推荐
OpenGL 索引缓存对象EBO和线宽模式
vulnhub之raven2
Vulnhub's presidential
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
Vulnhub narak
Solve msvcp120d DLL and msvcr120d DLL missing
安裝electron失敗的解决辦法
Symlink(): solution to protocol error in PHP artisan storage:link on win10
DNS多点部署IP Anycast+BGP实战分析
shardingSphere分库分表<3>
Vulnhub's Nagini
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
同事写了一个责任链模式,bug无数...
php 获取文件夹下面的文件列表和文件夹列表
laravel 时区问题timezone
Dynamically monitor disk i/o with ZABBIX
Duplicate numbers in the array of sword finger offer 03
解决msvcp120d.dll和msvcr120d.dll缺失
Qt+vtk+occt reading iges/step model
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022