base.BaseWindow

Methods

BaseWindow.__init__(title='ModernGL', gl_version=(3, 3), size=(1280, 720), resizable=True, fullscreen=False, vsync=True, aspect_ratio=1.7777777777777777, samples=4, cursor=True, **kwargs)[source]

Initialize a window instance.

Parameters
  • title (str) – The window title

  • gl_version (tuple) – Major and minor version of the opengl context to create

  • size (tuple) – Window size x, y

  • resizable (bool) – Should the window be resizable?

  • fullscreen (bool) – Open window in fullsceeen mode

  • vsync (bool) – Enable/disable vsync

  • aspect_ratio (float) – The desired aspect ratio. Can be set to None.

  • samples (int) – Number of MSAA samples for the default framebuffer

  • cursor (bool) – Enable/disable displaying the cursor inside the window

BaseWindow.init_mgl_context() → None[source]

Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s gl_version.

Keyword Arguments

ctx – An optional custom ModernGL context

BaseWindow.is_key_pressed(key) → bool[source]

Returns: The press state of a key

BaseWindow.close() → None[source]

Signal for the window to close

BaseWindow.use()[source]

Bind the window’s framebuffer

BaseWindow.clear(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0, viewport=None)[source]

Binds and clears the default framebuffer

Parameters
  • red (float) – color component

  • green (float) – color component

  • blue (float) – color component

  • alpha (float) – alpha component

  • depth (float) – depth value

  • viewport (tuple) – The viewport

BaseWindow.render(time=0.0, frame_time=0.0) → None[source]

Renders a frame by calling the configured render callback

Keyword Arguments
  • time (float) – Current time in seconds

  • frame_time (float) – Delta time from last frame in seconds

BaseWindow.swap_buffers() → None[source]

Library specific buffer swap method. Must be overridden.

BaseWindow.resize(width, height) → None[source]

Should be called every time window is resized so the example can adapt to the new size if needed

BaseWindow.destroy() → None[source]

A library specific destroy method is required

BaseWindow.set_default_viewport() → None[source]

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

If aspect ratio is None the viewport will be scaled to the entire window size regardless of size.

BaseWindow.print_context_info()[source]

Prints moderngl context info.

Attributes

BaseWindow.keys

Window specific key constants

BaseWindow.ctx

The ModernGL context for the window

Type

moderngl.Context

BaseWindow.fbo

The default framebuffer

Type

moderngl.Framebuffer

BaseWindow.title

Window title

Type

str

BaseWindow.gl_version

(major, minor) required OpenGL version

Type

Tuple[int, int]

BaseWindow.width

The current window width

Type

int

BaseWindow.height

The current window height

Type

int

BaseWindow.size

current window size

Type

Tuple[int, int]

BaseWindow.buffer_size

tuple with the current window buffer size

Type

Tuple[int, int]

BaseWindow.pixel_ratio

The frambuffer/window size ratio

Type

float

BaseWindow.viewport

current window viewport

Type

Tuple[int, int, int, int]

BaseWindow.frames

Number of frames rendered

Type

int

BaseWindow.resizable

Window is resizable

Type

bool

BaseWindow.fullscreen

Window is in fullscreen mode

Type

bool

BaseWindow.config

Get the current WindowConfig instance

BaseWindow.vsync

vertical sync enabled/disabled

Type

bool

BaseWindow.aspect_ratio

Aspect ratio configured for the viewport

Type

float

BaseWindow.samples

Number of Multisample anti-aliasing (MSAA) samples

Type

float

BaseWindow.cursor

Should the mouse cursor be visible inside the window?

Type

bool

BaseWindow.render_func

The render callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.resize_func

The resize callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.key_event_func

The key_event callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.mouse_position_event_func

The mouse_position callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.mouse_press_event_func

The mouse_press callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.mouse_release_event_func

The mouse_release callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.mouse_drag_event_func

The mouse_drag callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.mouse_scroll_event_func

The mouse_scroll_event calable

This property can also be used to assign a callable.

Type

callable

BaseWindow.unicode_char_entered_func

The unicode_char_entered callable

This property can also be used to assign a callable.

Type

callable

BaseWindow.is_closing

Is the window about to close?

Type

bool

BaseWindow.mouse = <class 'moderngl_window.context.base.window.MouseButtons'>

Mouse button enum

BaseWindow.mouse_states

Mouse button state structure.

The current mouse button states.

window.mouse_buttons.left
window.mouse_buttons.right
window.mouse_buttons.middle
Type

MouseButtonStates

BaseWindow.modifiers

(KeyModifiers) The current keyboard modifiers

BaseWindow.gl_version_code

Generates the version code integer for the selected OpenGL version.

gl_version (4, 1) returns 410

Type

int