Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
monitor = glfw.get_primary_monitor()
display_width, display_height = glfw.get_video_mode(monitor)[0]
if scale == 0:
scale = max(
min(
(display_width // width) - APP_SCREEN_SCALE_CUTDOWN,
(display_height // height) - APP_SCREEN_SCALE_CUTDOWN,
),
APP_SCREEN_SCALE_MINIMUM,
)
window_width = width * scale + border_width
window_height = height * scale + border_width
self._window = glfw.create_window(
window_width, window_height, caption, None, None
)
if not self._window:
glfw.terminate()
exit()
glfw.set_window_pos(
self._window,
(display_width - window_width) // 2,
(display_height - window_height) // 2,
)
glfw.make_context_current(self._window)
glfw.set_window_size_limits(
self._window, width, height, glfw.DONT_CARE, glfw.DONT_CARE
def initMuJoCo(filename, width2, height):
''' load model, init simulation and rendering '''
global window, sim, ctx
assert glfw.init(), 'Could not initialize GLFW'
glfw.window_hint(glfw.SAMPLES, 0)
glfw.window_hint(glfw.DOUBLEBUFFER, True)
glfw.window_hint(glfw.RESIZABLE, 0)
window = glfw.create_window(width2 // 4, height // 2, "mjvive.py", None, None)
assert window, "Could not create GLFW window"
glfw.make_context_current(window)
glfw.swap_interval(0)
# GLEW init required in C++, not in Python
sim = MjSim(load_model_from_xml(open(filename).read()))
sim.forward()
sim.model.vis.global_.offwidth = width2
sim.model.vis.global_.offheight = height
sim.model.vis.quality.offsamples = 8
ctx = MjRenderContext(sim)
ctx.scn.enabletransform = 1
ctx.scn.translate[1:3] = -0.5
ctx.scn.rotate[0:2] = math.cos(-0.25 * math.pi), math.sin(-0.25 * math.pi)
ctx.scn.scale = 1
ctx.scn.stereo = STEREO_SIDEBYSIDE
self._window,
(display_width - window_width) // 2,
(display_height - window_height) // 2,
)
glfw.make_context_current(self._window)
glfw.set_window_size_limits(
self._window, width, height, glfw.DONT_CARE, glfw.DONT_CARE
)
self._hidpi_scale = (
glfw.get_framebuffer_size(self._window)[0]
/ glfw.get_window_size(self._window)[0]
)
self._update_viewport()
glfw.set_key_callback(self._window, self._key_callback)
glfw.set_mouse_button_callback(self._window, self._mouse_button_callback)
glfw.set_window_icon(self._window, 1, [get_icon_image()])
glfw.set_input_mode(self._window, glfw.CURSOR, glfw.CURSOR_HIDDEN)
# initialize renderer
self._renderer = Renderer(width, height)
# initialize audio player
self._audio_player = AudioPlayer()
# export module functions
pyxel.btn = self.btn
pyxel.btnp = self.btnp
pyxel.btnr = self.btnr
pyxel.mouse = self.mouse
def main():
# start GLFW
if not glfw.init():
return -1
# setup GLFW window options
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1)
# open the window
window = glfw.create_window(800, 600, "Oculus Test", None, None)
if not window:
glfw.terminate()
# always call this before setting up render layers
glfw.make_context_current(window)
# load textures from file
texture_ref_l = load_image(r"C:\Users\mdc\Desktop\test_images\original\left\Aryaa1.ppm")
texture_ref_r = load_image(r"C:\Users\mdc\Desktop\test_images\original\right\Aryaa1.ppm")
texture_cmp_l = load_image(r"C:\Users\mdc\Desktop\test_images\compressed\left\Aryaa1_dec.ppm")
texture_cmp_r = load_image(r"C:\Users\mdc\Desktop\test_images\compressed\right\Aryaa1_dec.ppm")
# disable v-sync, we are syncing to the v-trace of head-set, leaving this on
# will cause the HMD to lock to the frequency/phase of the display.
glfw.swap_interval(0)
# start an Oculus session
rift.start_session()
def main():
# start GLFW
if not glfw.init():
return -1
# setup GLFW window options
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1)
# open the window
window = glfw.create_window(800, 600, "Oculus Test", None, None)
if not window:
glfw.terminate()
# always call this before setting up render layers
glfw.make_context_current(window)
# load textures from file
def setup_module():
import glfw
glfw.init()
def create_window_glfw(width, height, name, instance_handle):
import glfw
glfw.init()
# todo: depends on what backend is used, I guess?
if BACKEND in ("CTYPES", "FFI"):
# Create Window
glfw.window_hint(glfw.CLIENT_API, glfw.NO_API)
glfw.window_hint(glfw.RESIZABLE, False)
window = glfw.create_window(width, height, name, None, None)
# todo: how to get the window handle for glfw?
# This would have been nice ... but glfw.get_win32_window does not exist
# https://github.com/gfx-rs/wgpu/blob/master/examples/triangle/main.c#L167
# hwnd = glfw.glfwGetWin32Window(window)
# HINSTANCE hinstance = GetModuleHandle(NULL);
# surface = wgpu_create_surface_from_windows_hwnd(hinstance, hwnd);
else:
glfw.window_hint(glfw.RESIZABLE, False)
# if button 'A' is released on the touch controller, recenter the
# viewer in the scene.
if rift.get_buttons('touch', 'A', 'falling'):
rift.recenter_tracking_origin()
elif rift.get_buttons('touch', 'B', 'falling'):
# exit if button 'B' is pressed
break
elif rift.get_buttons('touch', 'X', 'falling'):
rift.set_render_high_quality(False)
elif rift.get_buttons('touch', 'Y', 'falling'):
rift.set_render_high_quality(True)
# flip the GLFW window and poll events
glfw.swap_buffers(window)
glfw.poll_events()
# switch off the performance summary
rift.perf_hud_mode("Off")
# end the rift session cleanly, all swap chains are destroyed here
rift.end_session()
# close the GLFW application
glfw.terminate()
return 0
def alarm_handler(signal_number, stack_frame):
"""
Close the current GLFW window when called due to a SIGALRM.
"""
assert signal_number == signal.SIGALRM
window = glfw.get_current_context()
assert window is not None
glfw.set_window_should_close(window, True)
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