文章目录
窗口的创建
初始化GLFW并进行配置
#include <glad/glad.h>
#include <glfw3.h>
//must include GLAD before GLFW. The include file for GLAD includes the required OpenGL headers(GL/gl.h ... )
int main() {
glfwInit(); //initialize GLFW
//configure the options prefixed with GLFW_
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
return 0;
}
步骤:
- 初始化glfw
- 声明我们使用的OpenGL的最大和最小版本都为3
- 指明使用core-profile(只使用OpenGL特性的子集,没有向后兼容的功能)
要保证OpenGL是3.3版本以上的,查看OpenGL版本的软件。
创建窗口对象
创建的窗口对象容纳了所有的窗口数据(初始化之后的代码段)。
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL_0_Start", NULL, NULL);//window witdth,height,name
if (window == NULL) {
cout << "create window failed" << endl;
glfwTerminate();
return -1;
}
//tell GLFW to make the context of our window the main context on the current threaed
glfwMakeContextCurrent(window);