LearnOpenGL 3 安装与创建窗口
LearnOpenGL CN 相关链接:https://learnopengl-cn.github.io/01%20Getting%20started/03%20Hello%20Window/
本节代码
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
# 导入需要的库
import glfw
import moderngl as mgl
# 初始化 GLFW
if not glfw.init():
raise Exception('GLFW出错')
# 创建窗口
window = glfw.create_window(800, 600, 'LearnOpenGL', None, None)
if not window:
glfw.terminate()
raise Exception('窗口出错')
# 获得上下文
glfw.make_context_current(window)
ctx = mgl.create_context()
# 视口
def framebuffer_size_callback(window, width, height):
ctx.viewport = (0, 0, width, height)
glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
# 渲染循环
while not glfw.window_should_close(window):
glfw.poll_events()
glfw.swap_buffers(window)
# 终止 GLFW
glfw.terminate()
本文由作者按照 CC BY 4.0 进行授权