How to use glfw - 10 common examples

To help you get started, we’ve selected a few glfw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kitao / pyxel / pyxel / app.py View on Github external
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
github openai / mujoco-py / examples / mjvive.py View on Github external
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
github mdcutone / psychxr / test_rift.py View on Github external
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()
github mdcutone / psychxr / test_rift.py View on Github external
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
github almarklein / wgpu-py / tests / test_gui_glfw.py View on Github external
def setup_module():
    import glfw

    glfw.init()
github almarklein / wgpu-py / examples / test-wgpu.py View on Github external
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)
github mdcutone / psychxr / test_rift.py View on Github external
# 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
github swistakm / pyimgui / doc / examples / glfw3.py View on Github external
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
github polmorenoc / opendr / demo_fit_cube.py View on Github external
np.random.seed(1)

width, height = (128, 128)
numPixels = width*height
shapeIm = [width, height,3]
win = -1
clip_start = 0.01
clip_end = 10
frustum = {'near': clip_start, 'far': clip_end, 'width': width, 'height': height}

if glMode == 'glfw':
    #Initialize base GLFW context for the Demo and to share context among all renderers.
    glfw.init()
    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.DEPTH_BITS,32)
    glfw.window_hint(glfw.VISIBLE, GL.GL_FALSE)
    win = glfw.create_window(width, height, "Demo",  None, None)
    glfw.make_context_current(win)

else:
    from OpenGL.raw.osmesa._types import *
    from OpenGL.raw.osmesa import mesa

winShared = None

gtCamElevation = np.pi/3
gtCamHeight = 0.4 #meters

chLightAzimuthGT = ch.Ch([0])
chLightElevationGT = ch.Ch([np.pi/3])