OpenGL基础函数

函数参考

GLFW初始化

 glfwInit();

 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);//设置OpenGL主版本号

 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);//设置OpenGL副版本号

 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);//OpenGL选择核心模式

窗体创建

 GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);

 if (window == NULL)

 {

     std::cout << "Failed to create GLFW window" << std::endl;

     glfwTerminate();

     return -1;

 }

 glfwMakeContextCurrent(window);

加载所有OpenGL函数指针

 if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))

 {

     std::cout << "Failed to initialize GLAD" << std::endl;

     return -1;

 }

设置处理窗体尺寸变化的回调函数

glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

设置清除窗体的颜色

glClearColor(0.2f, 0.3f, 0.3f, 1.0f);

窗体渲染、键盘按键消息处理

 while (!glfwWindowShouldClose(window))

 {

     processInput(window);

     glClear(GL_COLOR_BUFFER_BIT);

     glfwSwapBuffers(window);//切换缓冲区

     glfwPollEvents();

 }

释放GLFW资源

 glfwTerminate();

你可能感兴趣的:(计算机图形学,c++,开发语言)