The base window we extend when adding new window types to the system.


Namespace for generic key constants working across all window types.



Base window intializer reading values from settings.

When creating the initializer in your own window always call this methods using super().__init__().

The main responsebility of the initializer is to:

  • initialize the window library
  • identify the window framebuffer
  • set up keyboard and mouse events
  • create the moderngl.Context instance
  • register the window in context.WINDOW
BaseWindow.draw(current_time, frame_time)

Draws a frame. Internally it calls the configured timeline’s draw method.

  • current_time (float) – The current time (preferrably always from the configured timer class)
  • frame_time (float) – The duration of the previous frame in seconds

Clear the window buffer

BaseWindow.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.

  • red (float) – red compoent
  • green (float) – green compoent
  • blue (float) – blue compoent
  • alpha (float) – alpha compoent
  • depth (float) – depth value

Set the window buffer as the current render target


Swap the buffers. Most windows have at least support for double buffering cycling a back and front buffer.

BaseWindow.resize(width, height)

Resize the window. Should normallty be overriden when implementing a window as most window libraries need additional logic here.

  • width (int) – Width of the window
  • height – (int): Height of the window

Set the window in close state. This doesn’t actually close the window, but should make should_close() return True so the main loop can exit gracefully.

BaseWindow.should_close() → bool

Check if window should close. This should always be checked in the main draw loop.


The actual teardown of the window.

BaseWindow.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.

  • 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
BaseWindow.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.

  • 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)

Prints moderngl context info.


Calculates the viewport based on the configured aspect ratio in settings. Will add black borders if the window do not match the viewport.



(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


(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.

BaseWindow.keys = None

The key class/namespace used by the window defining keyboard constants