Common problems and basic concept knowledge of OpenGL

OpenGL FAQ and basic concept knowledge (continuously updated!!)
1. The concept of matrix in OpenGL, what is Model,View,Project?
We know the World in the OpenGL Matrix (World Matrix)/View Matrix (the View Matrix and Projection Matrix (the Projection matirx)
in the Model: the Matrix determine the World coordinates of a unified, mainly aimed at the Model of translation, rotation, scaling, shear, and other functions, is the Model from local space into World space.

Projection matrix is the part of the scene that we can see, with the camera/observer position and so on (set mouse movement, scroll wheel, etc.), and converts all world coordinates to View coordinates.
2. Scheduling between CPU and GPU in OpenGL

OpenGL program involves two types of processing unit CPU and GPU.
engl main program has CPU call to run, image processing part through GLSL to GPU execution.
Data transfer between CPU and GPU is divided into three steps:
1. First use the built-in OpenGL function to generate an ID number
2. According to the need for the ID number of memory types of binding, binding to be used in the receiving system after the completion of the GPU memory of the data in the “identifier” will be ready,
3. This part of memory is initialized. The initialized content is from the system memory, and this part of function is completed by the glBufferData function. After the data is submitted to the GPU dedicated memory, it is necessary to allocate the data according to the application scenarios, such as some data as vertices, some as colors, some for illumination control and so on
In addition, due to the high parallel structure of GPUs, all GPUs have high computational efficiency in processing graphics and complex algorithms. Most of the CPU area is controllers and registers, while GPUs have more ALUs, logical operational units for data processing, rather than data caching and flow control.
The concept of buffers in OpenGL
[1] Frame Buffer: A frame buffer is a combination of the following buffers. Using frame buffers allows you to render your scene into a different frame buffer, which allows you to create mirrors in the scene, or create cool effects that store data for the display.
[2] Color Buffer: Stores the color of all fragments: that is, the effect of visual output.
[3] Depth Buffer: determines which facets are occluded according to the Z value of the buffer. Automatically generated by GLFW.
[4] stencil buffer: Similar to depth testing, the template value is compared to the default value to determine whether to discard the fragment.
Data is processed in OpenGL in the following order: vertex shader – fragment shader – template test – depth test
The concept of depth testing
1. What is depth?

OpenGL will have a special area for storing Z value (the Z value on each pixel), which is the depth cache.
2. Depth Buffer Function?
In general, when we draw a graph, the later drawing overrides the previous graph, and the general drawing order is drawn from the back to the front. So there is a performance problem with the “covered part”, where the first part is covered, and all you see is the top part of the module and the bottom part of the covered part is not meaningful!
depth test appears to solve the covering problem
nction: when the depth test is turned on, the Z value will be checked. The same area close to the observer will be drawn, and other covered areas will not be drawn, regardless of the order of drawing.
3. How to use the deep cache test?

enable (GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
in the above code open depth test by default, the Z value under the condition of small will be overwritten
If the observer is in the positive direction of the Z axis, the Z value is close to the observer
If the observer is in the negative direction of the z-axis, the smaller z-value is closer to the observer

How to solve the conflict problem caused by the same depth value (same Z value)?
The first method: in the second drawing the same Z value, the tiny offset cover problems
note: must be very careful to ensure that the Z value of the gap, or like a refrigerator on the refrigerator as suspended risk
The second method is to sample the GLPolygonOffset function so that the depth value of the fragment can be adjusted so that the depth value is offset without creating a suspended emphasis

Read More: