def update_fps_counter():
    global previous_second, frame_count
    current_second = glfw.GetTime()
    elapsed_seconds = current_second - previous_second
    if elapsed_seconds > 0.25:
        previous_second = current_second
        fps = float(frame_count) / float(elapsed_seconds)
        glfw.SetWindowTitle(window, '%s @ FPS: %.2f' % (window_title, fps))
        frame_count = 0.0
    frame_count += 1.0
示例#2
0
 def update_fps_counter(self):
     current_second = glfw.GetTime()
     elapsed_seconds = current_second - self.previous_second
     if elapsed_seconds > 1.0:
         self.previous_second = current_second
         fps = float(self.frame_count) / float(elapsed_seconds)
         glfw.SetWindowTitle(self.windowID,
                             '%s @ FPS: %.2f' % (self.window_title, fps))
         self.frame_count = 0.0
     self.frame_count += 1.0
示例#3
0
 def update_fps_counter(self):
     current_second = glfw.GetTime()
     elapsed_seconds = current_second - self._previous_second
     if elapsed_seconds > 0.25:
         self._previous_second = current_second
         fps = float(self._frame_count) / float(elapsed_seconds)
         new_title = '{} @ FPS: {:.2f}'.format(self._title, fps)
         glfw.SetWindowTitle(self._window, new_title)
         self._frame_count = 0.0
     self._frame_count += 1.0
示例#4
0
def main():
    appName = 'First App'

    glfw.Init()
    glfw.WindowHint(glfw.CONTEXT_VERSION_MAJOR, 3)
    glfw.WindowHint(glfw.CONTEXT_VERSION_MINOR, 3)
    # glfw.WindowHint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
    # glfw.WindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    window = glfw.CreateWindow(800, 800, appName)
    glfw.SetWindowSizeCallback(window, window_size_callback)
    glfw.SetKeyCallback(window, key_callback)
    glfw.MakeContextCurrent(window)
    glfw.SwapInterval(1)

    try:
        initOpenGL()
    except Exception as e:
        print(e)
        exit(1)

    prevTime = time()
    frameCount = 0
    frameTimeSum = 0
    lastUpdateTime = prevTime
    while not glfw.WindowShouldClose(window):
        glfw.PollEvents()
        display(window)
        glfw.SwapBuffers(window)
        curTime = time()
        frameTime = (curTime - prevTime)
        # if frameTime != 0: print(1 / frameTime)
        sleep(0.016)

        if curTime - lastUpdateTime > 1:
            glfw.SetWindowTitle(
                window, '%s, FPS: %s' %
                (appName, str(round(frameCount / frameTimeSum))))
            frameCount = 0
            frameTimeSum = 0
            lastUpdateTime = curTime

        frameTimeSum += frameTime
        frameCount += 1
        prevTime = curTime

    glfw.DestroyWindow(window)
    glfw.Terminate()
示例#5
0
    def run_window(self):
        last_time = glfw.GetTime()
        frames = 0
        while glfw.GetKey(
                self.window,
                glfw.KEY_ESCAPE) != glfw.PRESS and not glfw.WindowShouldClose(
                    self.window):

            current_time = glfw.GetTime()
            if current_time - last_time >= 1.0:
                glfw.SetWindowTitle(self.window,
                                    "Loaded! Running at FPS: %d" % (frames))
                frames = 0
                last_time = current_time
            self.render()
            frames += 1

        for object in self._render_objects:
            object.delete()
        glDeleteProgram(self._mapping['program_id'])
        glDeleteVertexArrays(1, [self._mapping['vertex_array_id']])
        glfw.Terminate()
def create_cursor_from_pixels(pixels, W, H):
    image = glfw.Image()
    im = 255 * np.ones((H, W, 4), dtype=np.uint8)
    im[:, :, :pixels.shape[2]] = pixels
    image.pixels = im
    return glfw.CreateCursor(image, W / 2, H / 2)


def create_cursor(icon_path, W, H):
    pixels = Image.open(icon_path)
    pixels = np.array(pixels.resize((W, H), Image.ANTIALIAS))
    return create_cursor_from_pixels(pixels, W, H)


#glfw.IconifyWindow(window)
#glfw.RestoreWindow(window)

cursor = create_cursor(
    '/home/dimitri/Pictures/Screenshot from 2017-08-06 15-04-26.png', 128, 128)
glfw.SetCursor(window, cursor)

i = 0
while not glfw.WindowShouldClose(window):

    glfw.SwapBuffers(window)
    glfw.PollEvents()

glfw.SetWindowTitle(window, "My Window")

glfw.SetWindowShouldClose(window, True)