Beispiel #1
0
 def center_pos(self, monitor_id):
     m = glfw.GetMonitors()
     assert monitor_id >= 0 and monitor_id < len(m)
     monitor_pos = glfw.GetMonitorPos(m[monitor_id])
     video_mode = glfw.GetVideoMode(m[monitor_id])
     xpos = monitor_pos[0] + video_mode.width / 2 - self._width / 2
     ypos = monitor_pos[1] + video_mode.height / 2 - self._height / 2
     glfw.SetWindowPos(self._window, xpos, ypos)
Beispiel #2
0
    def test_window_pos_callback(self):
        called = [False]

        def callback(window, width, height):
            called[0] = True

        glfw.SetWindowPosCallback(self.window, callback)
        glfw.SetWindowPos(self.window, 10, 50)
        glfw.PollEvents()
        glfw.SetWindowPosCallback(self.window, None)
        self.assertTrue(called[0])
def center_pos(monitor_id, W, H):
    # W, H: window dimensions
    mon = glfw.GetMonitors()
    xpos = glfw.GetMonitorPos(mon[monitor_id])[0]+glfw.GetVideoMode(mon[monitor_id]).width/2-W/2
    ypos = glfw.GetMonitorPos(mon[monitor_id])[1]+glfw.GetVideoMode(mon[monitor_id]).height/2-H/2
    glfw.SetWindowPos(window, xpos, ypos)
Beispiel #4
0
    def __init__(self,
                 window_width,
                 window_height,
                 samples=1,
                 window_title="",
                 monitor=1,
                 show_at_center=True,
                 offscreen=False):
        self.window_title = window_title
        assert glfw.Init(), "Glfw Init failed!"
        glfw.WindowHint(glfw.SAMPLES, samples)
        if offscreen:
            glfw.WindowHint(glfw.VISIBLE, False)
        mon = glfw.GetMonitors()[monitor] if monitor != None else None
        self.windowID = glfw.CreateWindow(window_width, window_height,
                                          self.window_title, mon)
        assert self.windowID, "Could not create Window!"
        glfw.MakeContextCurrent(self.windowID)

        if not glInitBindlessTextureNV():
            raise RuntimeError("Bindless Textures not supported")

        self.framebuf_width, self.framebuf_height = glfw.GetFramebufferSize(
            self.windowID)
        self.framebuffer_size_callback = []

        def framebuffer_size_callback(window, w, h):
            self.framebuf_width, self.framebuf_height = w, h
            for callback in self.framebuffer_size_callback:
                callback(w, h)

        glfw.SetFramebufferSizeCallback(self.windowID,
                                        framebuffer_size_callback)

        self.key_callback = []

        def key_callback(window, key, scancode, action, mode):
            if action == glfw.PRESS:
                if key == glfw.KEY_ESCAPE:
                    glfw.SetWindowShouldClose(window, True)
            for callback in self.key_callback:
                callback(key, scancode, action, mode)

        glfw.SetKeyCallback(self.windowID, key_callback)

        self.mouse_callback = []

        def mouse_callback(window, xpos, ypos):
            for callback in self.mouse_callback:
                callback(xpos, ypos)

        glfw.SetCursorPosCallback(self.windowID, mouse_callback)

        self.mouse_button_callback = []

        def mouse_button_callback(window, button, action, mods):
            for callback in self.mouse_button_callback:
                callback(button, action, mods)

        glfw.SetMouseButtonCallback(self.windowID, mouse_button_callback)

        self.scroll_callback = []

        def scroll_callback(window, xoffset, yoffset):
            for callback in self.scroll_callback:
                callback(xoffset, yoffset)

        glfw.SetScrollCallback(self.windowID, scroll_callback)

        self.previous_second = glfw.GetTime()
        self.frame_count = 0.0

        if show_at_center:
            monitors = glfw.GetMonitors()
            assert monitor >= 0 and monitor < len(
                monitors), "Invalid monitor selected."
            vidMode = glfw.GetVideoMode(monitors[monitor])
            glfw.SetWindowPos(
                self.windowID,
                vidMode.width / 2 - self.framebuf_width / 2,
                vidMode.height / 2 - self.framebuf_height / 2,
            )
def center_pos(monitor_id):
    xpos = glfw.GetMonitorPos(mon[monitor_id])[0] + glfw.GetVideoMode(
        mon[monitor_id]).width / 2 - W / 2
    ypos = glfw.GetMonitorPos(mon[monitor_id])[1] + glfw.GetVideoMode(
        mon[monitor_id]).height / 2 - H / 2
    glfw.SetWindowPos(window, xpos, ypos)
Beispiel #6
0
glfw.WindowHint(glfw.CONTEXT_VERSION_MAJOR, version[0])
glfw.WindowHint(glfw.CONTEXT_VERSION_MINOR, version[1])
glfw.WindowHint(glfw.OPENGL_FORWARD_COMPAT, 1)
glfw.WindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

windows = [
    glfw.CreateWindow(640, 480, 'Hello World {}'.format(count))
    for count in range(2)
]

if not windows:
    glfw.Terminate()
    print('Failed to create window')
    exit()

glfw.SetWindowPos(windows[0], 0, 0)
w, h = glfw.GetWindowSize(windows[0])
glfw.SetWindowPos(windows[1], w, 0)


def update_windows():
    for window in windows:
        if glfw.WindowShouldClose(window):
            return
        glfw.MakeContextCurrent(window)
        GL.glClearColor(0.2, 0.2, 0.2, 1.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        glfw.SwapBuffers(window)