写在前面
通过本节,你可以毫不费力的--->创建一个窗口
OpenGL中窗口,即载体
导入头文件
#include <glad/glad.h>
#include <GLFW/glfw3.h>
初始化glfw窗口
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, );
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, );
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
创建窗口
//创建窗口
GLFWwindow* window = glfwCreateWindow(, , "LearnOpenGL", NULL, NULL);
// 防止创建失败
if (window == NULL){
std::cout<< "Failed to create glfw window" << std::endl;
glfwTerminate();
return -;
}
glfwMakeContextCurrent(window); if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -;
}
窗口长存
// 避免闪退,监听输入事件
while(!glfwWindowShouldClose(window))
{
if(glfwGetKey(window, GLFW_KEY_ESCAPE == GLFW_PRESS))
glfwSetWindowShouldClose(window, true); glfwPollEvents();
}
总结
这一节是入门章节,就是先搞一个窗口出来,方便我们以后的测试,下一节开始实现具体的渲染