OpenGL教程1:打开一个窗口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// GLFW

#include <iostream>
#include <GLFW/glfw3.h>

int main(int argc, const char * argv[]) {

//初始glfw
glfwInit();

//glfw 设置
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

// only in mac
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

// 建立一个窗口
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);
if (window == nullptr)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}

// 上下文
glfwMakeContextCurrent(window);


while(!glfwWindowShouldClose(window))
{
glfwPollEvents();
glfwSwapBuffers(window);

}


glfwTerminate();
return 0;
}