pyglet.Window¶
Methods¶
-
Window.
__init__
(**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
-
Window.
init_mgl_context
() → None¶ 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
-
Window.
is_key_pressed
(key) → bool¶ Returns: The press state of a key
-
Window.
use
()¶ Bind the window’s framebuffer
-
Window.
clear
(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0, viewport=None)¶ 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
-
Window.
render
(time=0.0, frame_time=0.0) → None¶ 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
-
Window.
resize
(width, height) → None¶ Should be called every time window is resized so the example can adapt to the new size if needed
-
Window.
set_default_viewport
() → None¶ 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.
-
Window.
print_context_info
()¶ Prints moderngl context info.
Window Specific Methods¶
-
Window.
on_mouse_press
(x: int, y: int, button, mods)[source]¶ Handle mouse press events and forward to standard methods
Parameters: - x – x position of the mouse when pressed
- y – y position of the mouse when pressed
- button – The pressed button
- mods – Modifiers
-
Window.
on_key_release
(symbol, modifiers)[source]¶ Pyglet specific key release callback.
Forwards and translates the events to standard methods.
Parameters: - symbol – The symbol of the pressed key
- modifiers – Modifier state (shift, ctrl etc.)
-
Window.
on_mouse_drag
(x, y, dx, dy, buttons, modifiers)[source]¶ Pyglet specific mouse drag event.
When a mouse button is pressed this is the only way to capture mouse posision events
-
Window.
on_key_press
(symbol, modifiers)[source]¶ Pyglet specific key press callback.
Forwards and translates the events to the standard methods.
Parameters: - symbol – The symbol of the pressed key
- modifiers – Modifier state (shift, ctrl etc.)
-
Window.
on_mouse_release
(x: int, y: int, button, mods)[source]¶ Handle mouse release events and forward to standard methods
Parameters: - x – x position when moutse button was released
- y – y position when moutse button was released
- button – The button pressed
- mods – Modifiers
Attributes¶
-
Window.
keys
¶ Pyglet specific key constants
-
Window.
ctx
¶ The ModernGL context for the window
Type: moderngl.Context
-
Window.
fbo
¶ The default framebuffer
Type: moderngl.Framebuffer
-
Window.
title
¶ Window title
Type: str
-
Window.
gl_version
¶ (major, minor) required OpenGL version
Type: Tuple[int, int]
-
Window.
width
¶ The current window width
Type: int
-
Window.
height
¶ The current window height
Type: int
-
Window.
size
¶ current window size
Type: Tuple[int, int]
-
Window.
buffer_size
¶ tuple with the current window buffer size
Type: Tuple[int, int]
-
Window.
pixel_ratio
¶ The frambuffer/window size ratio
Type: float
-
Window.
viewport
¶ current window viewport
Type: Tuple[int, int, int, int]
-
Window.
frames
¶ Number of frames rendered
Type: int
-
Window.
resizable
¶ Window is resizable
Type: bool
-
Window.
fullscreen
¶ Window is in fullscreen mode
Type: bool
-
Window.
config
¶ Get the current WindowConfig instance
-
Window.
vsync
¶ vertical sync enabled/disabled
Type: bool
-
Window.
aspect_ratio
¶ Aspect ratio configured for the viewport
Type: float
-
Window.
samples
¶ Number of Multisample anti-aliasing (MSAA) samples
Type: float
-
Window.
cursor
¶ Should the mouse cursor be visible inside the window?
Type: bool
-
Window.
render_func
¶ The render callable
This property can also be used to assign a callable.
Type: callable
-
Window.
resize_func
¶ The resize callable
This property can also be used to assign a callable.
Type: callable
-
Window.
key_event_func
¶ The key_event callable
This property can also be used to assign a callable.
Type: callable
-
Window.
mouse_position_event_func
¶ The mouse_position callable
This property can also be used to assign a callable.
Type: callable
-
Window.
mouse_press_event_func
¶ The mouse_press callable
This property can also be used to assign a callable.
Type: callable
-
Window.
mouse_release_event_func
¶ The mouse_release callable
This property can also be used to assign a callable.
Type: callable
-
Window.
is_closing
¶ Check pyglet’s internal exit state
-
Window.
modifiers
¶ (KeyModifiers) The current keyboard modifiers
-
Window.
gl_version_code
¶ Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
Type: int