Do you really understand opengl? ——Master Meng

1. What is OpenGL?
Here is the answer from Baidu Baike:
OpenGL (English: Open Graphics Library, translation: Open Graphics Library or "Open Graphics Library") is a cross-language and cross-platform for rendering 2D and 3D vector graphics Application programming interface (API). This interface is composed of nearly 350 different function calls, used to draw from simple graphics bits to complex three-dimensional scenes. Simply put, it is used to draw pictures.
2. Is it useful to learn opengl?
Some friends may think that they can start game development after learning. Go back and make a chicken, csgo or something. This is pure nonsense in the eyes of Meng.
As far as the current IT environment is concerned, there are very few jobs that require opengl at work. The main direction of opengl at work is to be a game engine. Of course, there are many applications of opengl in the short video and AR application fields of the current big fire, but if you only know opengl, it can be said that basically you can't find work. So if it is for employment-oriented learning, the priority of opengl is not so high.
For student learning, data structure and algorithms are definitely the first priority. This is the soul of coding. OpenGL can be combined with computer vision, graph theory, etc. to learn together, after all, OpenGL is more inclined to be a tool and a relatively basic tool. To do some simple graphics, some basic rendering operations still have to be mastered.

3. What pre-knowledge
is needed to learn OpenGL Since OpenGL is a graphics API, not an independent platform, it needs a programming language to work, we usually use C and C++. (Of course there are programming languages ​​specific to opengl) So proficiency in programming languages ​​is essential. If you have almost forgotten your C language, go back and review it quickly.
In addition, some mathematical knowledge such as linear algebra, geometry, trigonometry will be used. Don't be scared by the necessary mathematical knowledge. Almost all concepts can be understood as long as you have a basic mathematical background. Most of the functions don't even require you to understand all the mathematical knowledge, as long as you can use it.

4.
OpenGL working principle/features OpenGL itself is a huge state machine (State Machine): a series of variables describe how OpenGL should behave at the moment. The state of OpenGL is usually called OpenGL context (Context).
If the current state of OpenGL is making triangular images, let it be changed to circular images. We need to change some context variables to change the OpenGL state, so as to tell OpenGL how to draw.
When using OpenGL, we will encounter some state-changing functions, which will change the context. And state-using functions, which perform some operations based on the current OpenGL state. As long as you remember that OpenGL is essentially a large state machine, it will be easier to understand its large

5.
Object in Opengl This object is not an object, it is an object in a programming language, not the kind of object you want.
An object in OpenGL refers to a collection of options, which represents a subset of the OpenGL state. For example, we can use an object to represent the settings of the drawing window, and then we can set its size, the number of supported colors, and so on. You can think of the object as a C-style structure (Struct):

struct object_name {
    
    
    GLfloat  option1;    GLuint   option2;    GLchar[] name;};
// 创建对象
GLuint objectId = 0;
glGenObject(1, &objectId);
// 绑定对象至上下文
glBindObject(GL_WINDOW_TARGET, objectId);
// 设置当前绑定到 GL_WINDOW_TARGET 的对象的一些选项
glSetObjectOption(GL_WINDOW_TARGET, GL_OPTION_WINDOW_WIDTH, 800);
glSetObjectOption(GL_WINDOW_TARGET, GL_OPTION_WINDOW_HEIGHT, 600);
// 将上下文对象设回默认
glBindObject(GL_WINDOW_TARGET, 0);

This small piece of code shows a common workflow when you use OpenGL in the future. We first create an object, and then save its reference with an id (the actual data is stored in the background). Then we bind the object to the target position of the context (the target position of the window object in the example is defined as GL_WINDOW_TARGET). Next we set the options of the window. Finally, we set the object id of the target location back to 0 and unbind the object. The set options will be saved in the object referenced by objectId. Once we rebind this object to the GL_WINDOW_TARGET location, these options will take effect again. Just like a sub-function in C language, when the same problem needs to be solved multiple times in a program, you only need to call this sub-function again, which is very convenient.

6. The core mode
of OpenGL Early OpenGL used immediate rendering mode (Immediate mode, that is, fixed rendering pipeline), which is very convenient to draw graphics. Most of OpenGL's functions are hidden by the library, and developers rarely have the freedom to control how OpenGL performs calculations. That is, you can't arbitrarily code and map according to your own needs. The developers are eager to have more flexibility. Over time, the specification has become more and more flexible, and developers have more control over drawing details. The immediate rendering mode is indeed easy to use and understand, but it is too inefficient. Therefore, starting from OpenGL 3.2, the specification document began to abandon the immediate rendering mode, and introduced the Core-profile, which completely removed the old features.
When using the core mode of OpenGL, OpenGL forces us to use modern functions. When we try to use a deprecated function, OpenGL will throw an error and terminate the drawing. The advantages of modern functions are greater flexibility and efficiency, but they are also more difficult to learn. The immediate rendering mode abstracts away a lot of details from the actual operation of OpenGL, so while it is easy to learn, it is also difficult to grasp how OpenGL actually works. Modern functions require users to truly understand OpenGL and graphics programming. It has some difficulties, but it provides more flexibility, higher efficiency, and more importantly, a deeper understanding of graphics programming.

7. A major feature of
OpenGL A major feature of OpenGL is the support for extensions. When a graphics card company proposes a new feature or a major optimization in rendering, it is usually implemented in the driver in an extended manner. If a program runs on a graphics card that supports this extension, developers can use some of the more advanced and effective graphics features provided by this extension. In this way, developers can use these new rendering features without waiting for a new OpenGL specification to be available, and simply check whether the graphics card supports this extension. Usually, when an extension is very popular or very useful, it will eventually become part of the future OpenGL specification.
Most of the code that uses the extension looks like this:

if(GL_ARB_extension_name)
{
    
        // 使用一些新的特性}else{    // 不支持此扩展: 用旧的方式去做}

8. Is it necessary to use a new version of OpenGL?
All higher versions of OpenGL are based on 3.3, introducing additional features without changing the core architecture. The new version just introduces some more efficient or useful ways to accomplish the same function. Therefore, all concepts and techniques remain the same in modern OpenGL versions. When using the new version of OpenGL, only a new generation of graphics cards can support your application, so most developers write programs based on the lower version of OpenGL.

The next section talks about the configuration of the opengl environment, let you start the first part of the opengl journey.

Guess you like

Origin blog.csdn.net/weixin_44202478/article/details/108438921