OpenGL study notes "a" to create an empty window

  Recently this site to learn opengl related knowledge, and by writing blog way to deepen understanding.

  We first need to build a good environment

  Site recommended environment is visual studio2015 + glfw3.3 + glad, glfw from this place to download the code after the download, use cmake to generate vs project file, compile static library file. Then create an empty project, the introduction of dynamic link libraries. The site also mentioned, opengl is a set of graphics standards, related to the specific implementation drive with the graphics card vendors, and each vendor will have their own extensions, so if we directly use the various api opengl, you may need to do all kinds compatibility is determined. So this time, on the introduction of glad, help us to simplify these complex judgment, we can here to download the latest code. We will be glad to introduce to the project, will be the next step of work.

  Next we create a window

  First, we need to initialize opengl environment:

    glfwInit();
    // config glfw
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);    

  Glfw call to initialize the interface, and the statement that we use opengl version, using opengl the core profile.

  After initialization, we can create a window:

   // create window
    GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);if (nullptr == window) {
        std::cout << "Faild to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

    // initialize glad
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        std::cout << "Faild to initialize GLAD" << std::endl;
        return -1;
    }

  glfwCreateWindow method parameters to a width of the window, the window parameter for the height of two, three parameters of the window name, the latter two parameters can be transferred temporarily empty, and returns the object type GLFWwindow in need later;

  glfwMakeContextCurrent GLFWwindow objects created above the set to the current context, a state machine is as opengl, need to rely on the context;

  glfwSetFramebufferSizeCallback set a callback when the window size changed, it is necessary to adjust the parameters opengl to adapt to the impact of window size changes;

  gladLoadGLLoader is used to initialize the glad, each management api opengl mentioned above.

  In this case run the project, you can get a black bottom of the window, nothing, really empty.

Guess you like

Origin www.cnblogs.com/zhong-dev/p/11594015.html