本文整理汇总了Python中glfw.make_context_current方法的典型用法代码示例。如果您正苦于以下问题:Python glfw.make_context_current方法的具体用法?Python glfw.make_context_current怎么用?Python glfw.make_context_current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glfw
的用法示例。
在下文中一共展示了glfw.make_context_current方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def __init__(self, renderer, title="GlfwBaseApp"):
"Creates an OpenGL context and a window, and acquires OpenGL resources"
self.renderer = renderer
self.title = title
self._is_initialized = False # keep track of whether self.init_gl() has been called
if not glfw.init():
raise Exception("GLFW Initialization error")
# Use modern OpenGL version 4.5 core
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 5)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
self._configure_context()
self.window = glfw.create_window(self.renderer.window_size[0], self.renderer.window_size[1], self.title, None, None)
if self.window is None:
glfw.terminate()
raise Exception("GLFW window creation error")
glfw.set_key_callback(self.window, self.key_callback)
glfw.make_context_current(self.window)
示例2: main_glfw
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def main_glfw():
def glfw_init():
width, height = 1280, 720
window_name = "minimal ImGui/GLFW3 example"
if not glfw.init():
print("Could not initialize OpenGL context")
exit(1)
# OS X supports only forward-compatible core profiles from 3.2
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, gl.GL_TRUE)
# Create a windowed mode window and its OpenGL context
window = glfw.create_window(
int(width), int(height), window_name, None, None
)
glfw.make_context_current(window)
if not window:
glfw.terminate()
print("Could not initialize Window")
exit(1)
return window
window = glfw_init()
impl = GlfwRenderer(window)
while not glfw.window_should_close(window):
glfw.poll_events()
impl.process_inputs()
imgui.new_frame()
on_frame()
gl.glClearColor(1., 1., 1., 1)
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
imgui.render()
impl.render(imgui.get_draw_data())
glfw.swap_buffers(window)
impl.shutdown()
glfw.terminate()
示例3: impl_glfw_init
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def impl_glfw_init():
width, height = 1280, 720
window_name = "minimal ImGui/GLFW3 example"
if not glfw.init():
print("Could not initialize OpenGL context")
exit(1)
# OS X supports only forward-compatible core profiles from 3.2
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, gl.GL_TRUE)
# Create a windowed mode window and its OpenGL context
window = glfw.create_window(
int(width), int(height), window_name, None, None
)
glfw.make_context_current(window)
if not window:
glfw.terminate()
print("Could not initialize Window")
exit(1)
return window
示例4: init_gl
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def init_gl(self):
if self._is_initialized:
return # only initialize once
glfw.make_context_current(self.window)
if self.renderer:
self.renderer.init_gl()
self._is_initialized = True
示例5: render_scene
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def render_scene(self):
"render scene one time"
self.init_gl() # should be a no-op after the first frame is rendered
glfw.make_context_current(self.window)
self.renderer.render_scene()
# Done rendering
# glfw.swap_buffers(self.window) # avoid double buffering to avoid stalling
glFlush() # single buffering
glfw.poll_events()
示例6: dispose_gl
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def dispose_gl(self):
if self.window:
glfw.make_context_current(self.window)
if self.renderer:
self.renderer.dispose_gl()
glfw.destroy_window(self.window)
glfw.terminate()
self._is_initialized = False
示例7: b_init
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def b_init(self):
glfw.init()
glfw.window_hint(glfw.SAMPLES, 4)
self.window = glfw.create_window(self.companion_width, self.companion_height, 'hello_vr', None, None)
glfw.set_key_callback(self.window, self.key_callback)
glfw.make_context_current(self.window)
#
self.hmd = openvr.init(openvr.VRApplication_Scene)
#
vr_sys = openvr.VRSystem()
driver = vr_sys.getStringTrackedDeviceProperty(
openvr.k_unTrackedDeviceIndex_Hmd,
openvr.Prop_TrackingSystemName_String,
)
display = vr_sys.getStringTrackedDeviceProperty(
openvr.k_unTrackedDeviceIndex_Hmd,
openvr.Prop_SerialNumber_String,
)
glfw.set_window_title(self.window, f'hello_vr -- {driver} {display}')
self.b_init_gl()
assert openvr.VRCompositor()
action_path = pkg_resources.resource_filename('samples', 'hellovr_actions.json')
openvr.VRInput().setActionManifestPath(action_path)
self.action_hide_cubes = openvr.VRInput().getActionHandle('/actions/demo/in/HideCubes')
self.action_hide_this_controller = openvr.VRInput().getActionHandle('/actions/demo/in/HideThisController')
self.action_trigger_haptic = openvr.VRInput().getActionHandle('/actions/demo/in/TriggerHaptic')
self.action_analog_input = openvr.VRInput().getActionHandle('/actions/demo/in/AnalogInput')
self.action_set_demo = openvr.VRInput().getActionSetHandle('/actions/demo')
self.hand[Left].action_haptic = openvr.VRInput().getActionHandle('/actions/demo/out/Haptic_Left')
self.hand[Left].source = openvr.VRInput().getInputSourceHandle('/user/hand/left')
self.hand[Left].action_pose = openvr.VRInput().getActionHandle('/actions/demo/in/Hand_Left')
self.hand[Right].action_haptic = openvr.VRInput().getActionHandle('/actions/demo/out/Haptic_Right')
self.hand[Right].source = openvr.VRInput().getInputSourceHandle('/user/hand/right')
self.hand[Right].action_pose = openvr.VRInput().getActionHandle('/actions/demo/in/Hand_Right')
return True
示例8: __init__
# 需要导入模块: import glfw [as 别名]
# 或者: from glfw import make_context_current [as 别名]
def __init__(self, **kwargs):
super().__init__(**kwargs)
if not glfw.init():
raise ValueError("Failed to initialize glfw")
# Configure the OpenGL context
glfw.window_hint(glfw.CONTEXT_CREATION_API, glfw.NATIVE_CONTEXT_API)
glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, self.gl_version[0])
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, self.gl_version[1])
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
glfw.window_hint(glfw.RESIZABLE, self.resizable)
glfw.window_hint(glfw.DOUBLEBUFFER, True)
glfw.window_hint(glfw.DEPTH_BITS, 24)
glfw.window_hint(glfw.SAMPLES, self.samples)
monitor = None
if self.fullscreen:
monitor = glfw.get_primary_monitor()
mode = glfw.get_video_mode(monitor)
self._width, self._height = mode.size.width, mode.size.height
glfw.window_hint(glfw.RED_BITS, mode.bits.red)
glfw.window_hint(glfw.GREEN_BITS, mode.bits.green)
glfw.window_hint(glfw.BLUE_BITS, mode.bits.blue)
glfw.window_hint(glfw.REFRESH_RATE, mode.refresh_rate)
self._window = glfw.create_window(self.width, self.height, self.title, monitor, None)
self._has_focus = True
if not self._window:
glfw.terminate()
raise ValueError("Failed to create window")
self.cursor = self._cursor
self._buffer_width, self._buffer_height = glfw.get_framebuffer_size(self._window)
glfw.make_context_current(self._window)
if self.vsync:
glfw.swap_interval(1)
else:
glfw.swap_interval(0)
glfw.set_key_callback(self._window, self.glfw_key_event_callback)
glfw.set_cursor_pos_callback(self._window, self.glfw_mouse_event_callback)
glfw.set_mouse_button_callback(self._window, self.glfw_mouse_button_callback)
glfw.set_scroll_callback(self._window, self.glfw_mouse_scroll_callback)
glfw.set_window_size_callback(self._window, self.glfw_window_resize_callback)
glfw.set_char_callback(self._window, self.glfw_char_callback)
glfw.set_window_focus_callback(self._window, self.glfw_window_focus)
glfw.set_cursor_enter_callback(self._window, self.glfw_cursor_enter)
glfw.set_window_iconify_callback(self._window, self.glfw_window_iconify)
self.init_mgl_context()
self.set_default_viewport()