Record of pitfalls in the early stages of OpenGL learning - installation

​Note
: The installation is based on the process shown in the creation window - LearnOpenGL-CN. You need to take a look at this process first. The following records are some of the pitfalls involved.

  1. When CMake generates a GLFW project, if the wrong version of Visual Studio is set in the Configure step (for example, it is not available on your computer, or it is inconsistent with the version supported by GLFW), it is easy to report the error "Configuring incomplete, errors occurred" after clicking Configure. , and then no matter how you click Configure, this error remains, and you can no longer set the Visual Studio version.

This is because CMake has a cache, which needs to be cleaned before it can be reset. It is located in File/Delete Cache in the top window bar of CMake.

d

  1. When you open the sln project in the generated build, the "generate solution" mentioned in the process is the usual run button of Visual Studio. Of course, you can also generate it in the way mentioned in the tutorial. If you find an error saying LNK1104, please pay attention. Check whether a Chinese path is used and whether you changed the name of the folder after CMake generated the build folder.

Because the path may be encoded into the content generated by CMake, it is best not to modify the name of the build folder. If you want to change it, it can only be determined when CMake generates it.

  1. Then use the generated glfw3.lib and the include folder in the glfw folder you downloaded to add it to the linker. The location of the linker is as shown below. Right-click the workspace, select "Properties" at the bottom, and then the pop-up box will pop up. The rest of the settings are the same as in the tutorial. (The path below is what I have changed. Before the modification, it was almost the same as in the tutorial)
    Here is the quote
    Insert image description here

  2. Pay attention to whether the platforms of an SDK and the workspace are consistent. For example, I am both 64-bit, so the glfw3.lib I generated and the location in the picture below of the workspace should both be 64, otherwise there will be a warning (if you switch, then the above The settings will be reset, and you need to reset them at this time, otherwise there will be an error message like GLFW/glfw3.h not found)
    Here is the quote
    Insert image description here

  3. The GLEW mentioned in the tutorial is basically no longer used. It is recommended to use GLAD. You can find Baidu tutorial on this setting, which is relatively simple.

  4. If you have set the path in the properties, but find that include still fails, please check whether the following location is consistent with your current platform (it is very confusing, it is recommended to select "all platforms" when configuring the "linker" above. That way you can avoid these problems)
    Insert image description here

  5. In addition to the include folder downloaded by glad, which needs to be configured in the project in the "linker" like glfw's include, there is also a src folder with a glad.c file in it. This file is placed directly into the project. Compiled (of course you can compile it into a .lib file separately, and then configure it through the "linker" like glfw3.lib), which contains the specific implementation of the glad.h header file. If it is missing, you may be calling glClear () when waiting for the method, you get an error message such as "unresolved external symbol", "LNK: 2001 xxxx_gl_clearxxx", etc., which reminds you that you do not have a specific implementation of this method.
    Insert image description here

  6. The following provides detection code that can be run after the environment is successfully configured normally (reprinted from the link: https://blog.csdn.net/u013412391/article/details/108690963)

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
i
nt main(void)
{
    
    
    //必须先初始化该库,然后才能使用大多数GLFW函数。成功初始化后,GLFW_TRUE将返回。如果发生错误,GLFW_FALSE则返回。
    if (!glfwInit())
        return -1;

    //创建窗口(OpenGL上下文似乎也一并创建了)
    GLFWwindow* window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
    
    
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    //使用GLAD来加载OpenGL的函数地址
    gladLoadGL();

    //循环直到用户关闭窗口
    while (!glfwWindowShouldClose(window))
    {
    
    
        //清理屏幕所用的颜色:
        glClearColor(0.4f, 0.5f, 0.6f, 1.0f);
        //清理屏幕
        glClear(GL_COLOR_BUFFER_BIT);

        //交换前后缓冲
        glfwSwapBuffers(window);

        //轮询并处理事件
        glfwPollEvents();
    }

    //使用GLFW完成操作后,通常是在应用程序退出之前,需要终止GLFW
    glfwTerminate();

    return 0;
}
————————————————
版权声明:本文为CSDN博主「YakSue」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u013412391/article/details/108690963

Guess you like

Origin blog.csdn.net/qq_37421018/article/details/124171993