OpenGL learning notes part I - environment configuration and basic knowledge

preface:

Before starting to learn opengl, the blogger learned the first ten sections (rendering pipeline part) of games101 graphics foundation and the first two sections (basic part) of games202. This note was expanded by the second section of games202, and the subsequent content came from learnopungl (originally wanted to read the blue book, I felt that the environment gltools and sb7 of the blue book were a little troublesome, and I found that learnopungl was better to use)

Some learning resources:

LearnOpenGL CN

GLFW: Main Page

OpenGL:

A set of graphical API s for calling GPU on CPU. The work is similar to painting an oil painting:

1. Placing objects: model selection and model placement. Use VBO (vertex buffer object) to store the model in GPU.

Use OpenGL to complete the placement and movement of objects.

2. Place easel: place camera (set camera for view transformation) and create framebuffer

3. Add canvas: after specifying a framebuffer, it can be used to render multiple images. Rendering once is equivalent to using one canvas.

4. Painting: shading and shading with shaders. For vertex shading return value and interpolation in fragment shader, you need to complete vertex and fragment shader by yourself, and other functions can be encapsulated and used.

Shading Language GLSL of OpenGL

vertex+fragment coloring language

Render Equation (visibility is used to deal with environmental care, which is considered in real-time rendering)

Environment configuration

The environment configuration really bothered me for a while. Thank you very much for sharing.

Configuration of VS2017+OpenGL environment (conclusion)_ BLUEHEART-CSDN blog_ Vs configuring opengl

I searched many tutorials on the Internet because I was too lazy to download cmake, and then I successfully configured glut and glfw by using the method of the blogger above.

First window

GLFW configuration

The following code initializes glfw and tells glfw to use OpenGL version 3.3 and use core mode.

 glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//The first three parameters are width, height and name. The following parameters will be used later
    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
    //Check whether the creation is successful. After the creation is successful, terminate glfw (with glfwTerminate())
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
// ---------------------------------------
    //Enable glad -- manage the function pointer of OpenGL, and pass the function pointer address of OpenGL used to load the system conduit to the loader of glad
    //From glfwgetprocaddress 
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;

After glad is enabled in the above code, set the viewport. Since the viewport size should change with the change of window size, design the callback function to change synchronously each time. The glViewport method is used to set the size of the rendering window. The designed callback function has a wide range of applications, such as processing input change error information and so on.

void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    // make sure the viewport matches the new window dimensions; note that width and 
    // height will be significantly larger than specified on retina displays.
    glViewport(0, 0, width, height);
}

If you want to call this function to update the size of the rendering window every time you resize the window, you need to use the following statement:

glfwSetFramebufferSizeCallback(window,framebuffer_size_callback);

Some other functions:

glfwWindowShouldClose: check whether GLFW is required to be pushed out

glfwPollEvents: check whether any events are triggered

glfwSwapBuffers: exchange color buffers (double buffering technology: the front buffer saves the final output image, the rear buffer draws, and the image is presented before and after the exchange)

glfwTerminate(): terminate glfw

glfwGetKey (window, GLFW_KEY_ESCAPE) means to check the status of ESC key. If it is pressed, there is

glfwGetKey(window,GLFW_KEY_ESCAPE)==GLFW_PRESS

The picture that is not pressed will return to GLFE_RELEASE

The four parameters glClearColor(0.1f,0.2f,0.3f,1.0f) represent the red, green and blue transparency respectively.

glClear (GL_COLOR_BUFFER_BIT) calls these two functions successively, and then the color buffer is adjusted to the color set up by the above function after the color buffer is removed.

glClear() can accept a Buffer Bit with COLOR \DEPTH \SETNCIL

We will continue in the next section

Keywords: OpenGL

Added by aerodromoi on Thu, 03 Mar 2022 17:06:30 +0200