当前位置:网站首页>OpenGL learning notes
OpenGL learning notes
2022-07-03 08:22:00 【cuncaojin】
Current learning status :day01
Hello triangle
Chinese Course https://learnopengl-cn.github.io/
course http://www.opengl-tutorial.org/cn/beginners-tutorials/tutorial-1-opening-a-window/
Course source code https://github.com/opengl-tutorials/ogl/archive/master.zip
Vertex array object :Vertex Array Object,VAO
Vertex buffer object :Vertex Buffer Object,VBO
Index buffer object :Element Buffer Object,EBO or Index Buffer Object,IBO
Graphics rendering pipeline : It can be divided into two main parts : The first part is to put your 3D The coordinates are converted to 2D coordinate , The second part is to put 2D Coordinates change to actual colored pixels .
Schematic diagram of each stage of graphic rendering pipeline :
The blue part represents the part where we can inject custom shaders . but Most of the time , Just configure vertex and fragment shaders , But you must also define at least one vertex shader and one fragment shader ( because GPU There is no default vertex in / Fragment Shader ).
Vertex Attribute (Vertex Attribute): Coordinates and color values
Primitives (Primitive): The rendering type to be represented by the vertex attribute . Such as GL_POINTS、GL_TRIANGLES、GL_LINE_STRIP etc.
Fragment Shader : The main purpose is to calculate the final color of a pixel
Vertex buffer object (VBO): Send a large number of vertex data to video memory at one time ( Memory of graphics card ), For vertex shaders .VBO The buffer type of is :GL_ARRAY_BUFFER
Vertex shader type :GL_VERTEX_SHADER
Clip shader type :GL_FRAGMENT_SHADER
Fragment Shader : Calculate the final color output of pixels
( The vertices 、 fragment ) Shader usage steps :
1. Use Shader Language GLSL(OpenGL Shading Language) Write shaders 2. Compiling shaders 3. Using shaders
Shader program : Link multiple shaders , Link the output of each shader to the input of the next shader . When the output and input don't match , You will get a link error .
Link vertex properties :
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0); // Turn on vertex properties , 0: Vertex attribute position value
0 —— Vertex attributes to configure , Vertex shader program location value
3 —— The size of the vertex attribute
GL_FLOAT —— location The data type of the variable to which the value refers
GL_FALSE —— Whether you want the data to be standardized , Don't want to
3 * sizeof(float) —— step (Stride)
(void*)0 —— Location (location) The offset of the starting position of the data in the buffer
Vertex array object (Vertex Array Object, VAO) Can be bound like a vertex buffer object , Any subsequent vertex attribute calls are stored in this VAO in . The good thing is , When configuring vertex attribute pointers , You only need to execute those calls once , When drawing objects later, you only need to bind the corresponding VAO That's it . This makes it easy to switch between different vertex data and attribute configurations , Just bind different VAO That's it . All the States just set will be stored in VAO in .
Vertex data > ( Vertex array object VAO Mark 1) Vertex buffer object (VBO)> Set vertex property pointer > Vertex shader > Fragment Shader > Shader program + Tag before binding 1 Vertex array object VAO > The screen
// ..:: Initialization code ( Only run once ( Unless your objects change frequently )) :: ..
// 1. binding VAO
glBindVertexArray(VAO);
// 2. Copy the vertex array to the buffer for OpenGL Use
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// 3. Set vertex property pointer
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
[...]
// ..:: Draw code ( In the rendering loop ) :: ..
// 4. Draw objects
glUseProgram(shaderProgram); // Using shader programs
glBindVertexArray(VAO); // Bind again when using VAO object ,VAO There are... In the object VBO All vertex attributes .
someOpenGLFunctionThatDrawsOurTriangle();
// Such as drawing triangles :
// glDrawArrays(GL_TRIANGLES, 0, 3);
// Parameter meaning :OpenGL The type of element , The starting index of the vertex array , The number of vertices involved in painting
Index buffer object
Index buffer object (Element Buffer Object,EBO, Also called Index Buffer Object,IBO)
Vertex array object VAO, You can save vertex buffer objects VBO Properties of , You can also save index buffer objects IBO The binding state of 
边栏推荐
- Use filechannel to copy files
- Lua hot update basic grammar
- Luaframwrok handles resource updates
- Scite change background color
- Redis data structure
- Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
- 十六进制编码简介
- matlab神經網絡所有傳遞函數(激活函數)公式詳解
- Solution détaillée de toutes les formules de fonction de transfert (fonction d'activation) du réseau neuronal MATLAB
- P1596 [USACO10OCT]Lake Counting S
猜你喜欢

Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“

C course design employee information management system

Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products

MySQL 8
![[cloud native] introduction and use of feign of microservices](/img/39/05cf7673155954c90e75a8a2eecd96.jpg)
[cloud native] introduction and use of feign of microservices

Introduction to hexadecimal coding

Introduction to Base64 coding

Three characteristics

简易入手《SOM神经网络》的本质与原理

Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
随机推荐
简易入手《SOM神经网络》的本质与原理
796 · 开锁
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
Clion toolchains are not configured configure disable profile problem solving
数据分析练习题
Golang's range
Haproxy+kept cluster setup 02
KunlunBase MeetUP 等您来!
Sequence of map implementation classes
go 解析身份证
LinkList
Simple demo of solving BP neural network by gradient descent method
Multi traveling salesman problem -- overview of formula and solution process
Constraintlayout's constraintset dynamically modifies constraints
Conversion between JSON and object
Lua framwrok framework starts
MySQL containerization (1) docker installation MySQL
the installer has encountered an unexpected error installing this package
数据的存储
Shader foundation 01