-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathep01_glfw_window.py
43 lines (33 loc) · 1.28 KB
/
ep01_glfw_window.py
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
import glfw
from OpenGL.GL import *
# initializing glfw library
if not glfw.init():
raise Exception("glfw can not be initialized!")
# Configure the OpenGL context.
# If we are planning to use anything above 2.1 we must at least
# request a 3.3 core context to make this work across platforms.
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
# 4 MSAA is a good default with wide support
glfw.window_hint(glfw.SAMPLES, 4)
# creating the window
window = glfw.create_window(1280, 720, "My OpenGL window", None, None)
# check if window was created
if not window:
glfw.terminate()
raise Exception("glfw window can not be created!")
# Query the actual framebuffer size so we can set the right viewport later
# -> glViewport(0, 0, framebuffer_size[0], framebuffer_size[1])
framebuffer_size = glfw.get_framebuffer_size(window)
# set window's position
glfw.set_window_pos(window, 400, 200)
# make the context current
glfw.make_context_current(window)
# the main application loop
while not glfw.window_should_close(window):
glfw.poll_events()
glfw.swap_buffers(window)
# terminate glfw, free up allocated resources
glfw.terminate()