当前位置:网站首页>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 
边栏推荐
- 数据的存储
- Introduction to hexadecimal coding
- Editor Extensions
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
- Unity4.3.1 engine source code compilation process
- Osgearth north arrow display
- Chocolate installation
- Why can void * be a general pointer
- Golang string segmentation, substitution and interception
- 100 GIS practical application cases (78) - Multi compliance database design and data warehousing
猜你喜欢

Image processing 8-cnn image classification

數據庫應用技術課程設計之商城管理系統

Minimap plug-in

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

ArrayList

Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S

Chocolate installation
![[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)](/img/de/1c75b5e7ed79aca47462de365428a7.jpg)
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)

Youyou1 of xlua knapsack system
随机推荐
Xlua task list youyou
redis集群系列四
Sequence of map implementation classes
Unity2019_ Natural ambient light_ Sky box
Redis data structure
Why can void * be a general pointer
使用base64编码传图片
【更新中】微信小程序学习笔记_3
Wpf: solve the problem that materialdesign:dialoghost cannot be closed
C语言-入门-精华版-带你走进编程(一)
Use of ue5 QRcode plug-in
Image processing 8-cnn image classification
数据库应用技术课程设计之商城管理系统
【云原生】微服务之Feign的介绍与使用
Osgearth target selection
A tunnel to all ports of the server
數據庫應用技術課程設計之商城管理系統
Ue5 opencv plug-in use
Pulitzer Prize in the field of information graphics - malofiej Award
Explain sizeof, strlen, pointer, array and other combination questions in detail