demosys.context.glfw.Window¶
-
demosys.context.glfw.Window¶ Window implementation using pyGLFW
-
demosys.context.glfw.Keys¶ Namespace defining glfw specific keys constants
Methods¶
-
Window.__init__()¶ Initializes glfw, sets up key and mouse events and creates a
moderngl.Contextusing the context glfw createad.Using the glfw window requires glfw binaries and pyGLFW.
-
Window.use()¶ Bind the window framebuffer making it the current render target
-
Window.swap_buffers()¶ Swaps buffers, incement the framecounter and pull events.
-
Window.resize(width, height)¶ Sets the new size and buffer size internally
-
Window.close()¶ Set the window closing state in glfw
-
Window.should_close()¶ Ask glfw is the window should be closed
-
Window.terminate()¶ Terminates the glfw library
-
Window.key_event_callback(window, key, scancode, action, mods)¶ Key event callback for glfw. Translates and forwards keyboard event to
keyboard_event()Parameters: - window – Window event origin
- key – The key that was pressed or released.
- scancode – The system-specific scancode of the key.
- action – GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
- mods – Bit field describing which modifier keys were held down.
-
Window.mouse_event_callback(window, xpos, ypos)¶ Mouse event callback from glfw. Translates the events forwarding them to
cursor_event().Parameters: - window – The window
- xpos – viewport x pos
- ypos – viewport y pos
-
Window.window_resize_callback(window, width, height)¶ Window resize callback for glfw
Parameters: - window – The window
- width – New width
- height – New height
-
Window.poll_events()¶ Poll events from glfw
-
Window.check_glfw_version()¶ Ensure glfw library version is compatible
Other Inherited Methods¶
-
Window.draw(current_time, frame_time)¶ Draws a frame. Internally it calls the configured timeline’s draw method.
Parameters: - current_time (float) – The current time (preferrably always from the configured timer class)
- frame_time (float) – The duration of the previous frame in seconds
-
Window.clear()¶ Clear the window buffer
-
Window.clear_values(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0)¶ Sets the clear values for the window buffer.
Parameters: - red (float) – red compoent
- green (float) – green compoent
- blue (float) – blue compoent
- alpha (float) – alpha compoent
- depth (float) – depth value
-
Window.keyboard_event(key, action, modifier)¶ Handles the standard keyboard events such as camera movements, taking a screenshot, closing the window etc.
Can be overriden add new keyboard events. Ensure this method is also called if you want to keep the standard features.
Parameters: - key – The key that was pressed or released
- action – The key action. Can be ACTION_PRESS or ACTION_RELEASE
- modifier – Modifiers such as holding shift or ctrl
-
Window.cursor_event(x, y, dx, dy)¶ The standard mouse movement event method. Can be overriden to add new functionality. By default this feeds the system camera with new values.
Parameters: - x – The current mouse x position
- y – The current mouse y position
- dx – Delta x postion (x position difference from the previous event)
- dy – Delta y postion (y position difference from the previous event)
-
Window.print_context_info()¶ Prints moderngl context info.
-
Window.set_default_viewport()¶ Calculates the viewport based on the configured aspect ratio in settings. Will add black borders if the window do not match the viewport.
Attributes¶
-
Window.size¶ (width, height) tuple containing the window size.
Note that for certain displays we rely on
buffer_size()to get the actual window buffer size. This is fairly common for retina and 4k displays where the UI scale is > 1.0
-
Window.buffer_size¶ (width, heigh) buffer size of the window.
This is the actual buffer size of the window taking UI scale into account. A 1920 x 1080 window running in an environment with UI scale 2.0 would have a 3840 x 2160 window buffer.
-
Window.keys= <class 'demosys.context.glfw.keys.Keys'>¶
-
Window.min_glfw_version= (3, 2, 1)¶ The minimum glfw version required