Display and Window Management¶
-
class
csdl2.SDL_Window¶ A window.
It cannot be initialized directly. Instead, create one with
SDL_CreateWindow().
Window creation¶
-
csdl2.SDL_CreateWindow(title: str, x: int, y: int, w: int, h: int, flags: int) → SDL_Window¶ Creates a window with the specified title, position, dimensions and flags.
Parameters: - title (str) – Title of the window
- x (int) – X position of the window,
SDL_WINDOWPOS_CENTEREDorSDL_WINDOWPOS_UNDEFINED. - y (int) – Y position of the window,
SDL_WINDOWPOS_CENTEREDorSDL_WINDOWPOS_UNDEFINED. - w (int) – Width of the window.
- h (int) – Height of the window.
- flags (int) – 0, or one or more of the following flags OR’ed together:
SDL_WINDOW_FULLSCREEN,SDL_WINDOW_FULLSCREEN_DESKTOP,SDL_WINDOW_OPENGL,SDL_WINDOW_SHOWN,SDL_WINDOW_HIDDEN,SDL_WINDOW_BORDERLESS,SDL_WINDOW_RESIZABLE,SDL_WINDOW_MINIMIZED,SDL_WINDOW_MAXIMIZED,SDL_WINDOW_INPUT_GRABBED.
Returns: A new
SDL_Window
-
csdl2.SDL_WINDOWPOS_UNDEFINED¶ Used to indicate that you don’t care what the window position is in any display.
-
csdl2.SDL_WINDOWPOS_CENTERED¶ Used to indicate that the window position should be centered in any display.
Window flags¶
-
csdl2.SDL_WINDOW_FULLSCREEN¶ The window is fullscreen.
-
csdl2.SDL_WINDOW_OPENGL¶ The window is usable with an OpenGL context.
-
csdl2.SDL_WINDOW_SHOWN¶ The window is visible.
-
csdl2.SDL_WINDOW_HIDDEN¶ The window is hidden.
-
csdl2.SDL_WINDOW_BORDERLESS¶ The window has no window decoration.
-
csdl2.SDL_WINDOW_RESIZABLE¶ The window is resizable.
-
csdl2.SDL_WINDOW_MINIMIZED¶ The window is minimized.
-
csdl2.SDL_WINDOW_MAXIMIZED¶ The window is maximized.
-
csdl2.SDL_WINDOW_INPUT_GRABBED¶ The window has grabbed input focus.
-
csdl2.SDL_WINDOW_INPUT_FOCUS¶ The window has input focus.
-
csdl2.SDL_WINDOW_MOUSE_FOCUS¶ The window has mouse focus.
-
csdl2.SDL_WINDOW_FULLSCREEN_DESKTOP¶ The window is exclusively fullscreen – the screen display mode is set to match the window dimensions.
-
csdl2.SDL_WINDOW_FOREIGN¶ The window was not created by SDL.
Window destruction¶
-
csdl2.SDL_DestroyWindow(window: SDL_Window) → None¶ Destroys a window, freeing up its resources.
There is no need to manually call this function.
SDL_Windowwill automatically call it as part of its destructor.Parameters: window (SDL_Window) – Window to be destroyed.
Window Properties¶
-
csdl2.SDL_GetWindowTitle(window: SDL_Window) → str¶ Returns the title of the window.
Parameters: window ( SDL_Window) – The window.Returns: The title of the window.
Window Events¶
-
csdl2.SDL_WINDOWEVENT_NONE¶ This constant is not used.
-
csdl2.SDL_WINDOWEVENT_SHOWN¶ The value of SDL_WindowEvent.type when the Window has been shown.
-
csdl2.SDL_WINDOWEVENT_HIDDEN¶ The value of SDL_WindowEvent.type when the window has been hidden.
-
csdl2.SDL_WINDOWEVENT_EXPOSED¶ The value of SDL_WindowEvent.type when the Window has been exposed and should been redrawn.
-
csdl2.SDL_WINDOWEVENT_MOVED¶ The value of SDL_WindowEvent.type when the window has been moved. SDL_WindowEvent.data1 is the new x position and SDL_WindowEvent.data2 is the new y position.
-
csdl2.SDL_WINDOWEVENT_RESIZED¶ The value of SDL_WindowEvent.type when the window has been resized. SDL_WindowEvent.data1 is the new width and SDL_WindowEvent.data2 is the new height.
-
csdl2.SDL_WINDOWEVENT_SIZE_CHANGED¶ The value of SDL_WindowEvent.type when the window size has changed, either as a result of an API call or through the system or user changing the window size. SDL_WindowEvent.data1 is the new width and SDL_WindowEvent.data2 is the new height.
-
csdl2.SDL_WINDOWEVENT_MINIMIZED¶ The value of SDL_WindowEvent.type when the window has been minimized.
-
csdl2.SDL_WINDOWEVENT_MAXIMIZED¶ The value of SDL_WindowEvent.type when the window has been maximized.
-
csdl2.SDL_WINDOWEVENT_RESTORED¶ The value of SDL_WindowEvent.type when the window has been restored to normal size and position.
-
csdl2.SDL_WINDOWEVENT_ENTER¶ The value of SDL_WindowEvent.type when the window has gained mouse focus.
-
csdl2.SDL_WINDOWEVENT_LEAVE¶ The value of SDL_WindowEvent.type when the window has lost mouse focus.
-
csdl2.SDL_WINDOWEVENT_FOCUS_GAINED¶ The value of SDL_WindowEvent.type when the window has gained keyboard focus.
-
csdl2.SDL_WINDOWEVENT_FOCUS_LOST¶ The value of SDL_WindowEvent.type when the window has lost keyboard focus.
-
csdl2.SDL_WINDOWEVENT_CLOSE¶ The value of SDL_WindowEvent.type when the window manager requests that the window be closed.
OpenGL configuration attributes¶
OpenGL configuration attributes control the properties of the OpenGL context that is created with SDL_GL_CreateContext. These attributes are set with SDL_GL_SetAttribute and read with SDL_GL_GetAttribute.
Note that the following attributes must be set before the window is created
with SDL_CreateWindow():
-
csdl2.SDL_GL_RED_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the red channel of the color buffer. Defaults to 3.
-
csdl2.SDL_GL_GREEN_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the green channel of the color buffer. Defaults to 3.
-
csdl2.SDL_GL_BLUE_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the blue channel of the color buffer. Defaults to 2.
-
csdl2.SDL_GL_ALPHA_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the alpha channel of the color buffer. Defaults to 0.
-
csdl2.SDL_GL_BUFFER_SIZE¶ OpenGL configuration attribute for the minimum number of bits for frame buffer size. Defaults to 0.
-
csdl2.SDL_GL_DOUBLEBUFFER¶ OpenGL configuration attribute for whether the output is single or double buffered. Defaults to double buffering on.
-
csdl2.SDL_GL_DEPTH_SIZE¶ OpenGL configuration attribute for the minimum number of bits in the depth buffer. Defaults to 16.
-
csdl2.SDL_GL_STENCIL_SIZE¶ OpenGL configuration attribute for the minimum number of bits in the stencil buffer. Defaults to 0.
-
csdl2.SDL_GL_ACCUM_RED_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the red channel of the accumulation buffer. Defaults to 0.
-
csdl2.SDL_GL_ACCUM_GREEN_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the green channel of the accumulation buffer. Defaults to 0.
-
csdl2.SDL_GL_ACCUM_BLUE_SIZE¶ OpenGL configuration attribute for the the minimum number of bits for the blue channel of the accumulation buffer. Defaults to 0.
-
csdl2.SDL_GL_ACCUM_ALPHA_SIZE¶ OpenGL configuration attribute for the minimum number of bits for the alpha channel of the accumulation buffer. Defaults to 0.
-
csdl2.SDL_GL_STEREO¶ OpenGL configuration attribute for whether the output is stereo 3D. Defaults to off.
-
csdl2.SDL_GL_MULTISAMPLEBUFFERS¶ OpenGL configuration attribute for the number of buffers used for multisample anti-aliasing. Defaults to 0.
-
csdl2.SDL_GL_MULTISAMPLESAMPLES¶ OpenGL configuration attribute for the number of samples used around the current pixel used for multisample anti-aliasing. Defaults to 0.
-
csdl2.SDL_GL_ACCELERATED_VISUAL¶ Set this OpenGL configuration attribute to 1 to require hardware acceleration, set to 0 to force software rendering. Default is to allow either.
-
csdl2.SDL_GL_CONTEXT_MAJOR_VERSION¶ OpenGL configuration attribute for the OpenGL context major version.
-
csdl2.SDL_GL_CONTEXT_MINOR_VERSION¶ OpenGL configuration attribute for the OpenGL context minor version.
-
csdl2.SDL_GL_CONTEXT_FLAGS¶ OpenGL context creation flags. The value can be one or more of
SDL_GL_CONTEXT_DEBUG_FLAG,SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG,SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG,SDL_GL_CONTEXT_RESET_ISOLATION_FLAG. Default is 0 (no flags set).
-
csdl2.SDL_GL_CONTEXT_PROFILE_MASK¶ OpenGL context creation profile. The value must be one of
SDL_GL_CONTEXT_PROFILE_CORE,SDL_GL_CONTEXT_PROFILE_COMPATIBILITY,SDL_GL_CONTEXT_PROFILE_ES. Default depends on the platform.
-
csdl2.SDL_GL_SHARE_WITH_CURRENT_CONTEXT¶ OpenGL configuration attribute to enable context sharing. Default is 0 (don’t share contexts).
OpenGL flags¶
These flags are set through the SDL_GL_CONTEXT_FLAGS OpenGL
configuration attribute.
-
csdl2.SDL_GL_CONTEXT_DEBUG_FLAG¶ This flag maps to
GLX_CONTEXT_DEBUG_BIT_ARBin the GLX_ARB_create_context extension andWGL_CONTEXT_DEBUG_BIT_ARBin the WGL_ARB_create_context extension, and is ignored if these extensions are not available. This flag puts OpenGL into a “debug” mode which might assist with debugging, possibly at a loss of performance.
-
csdl2.SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG¶ This flag maps to
GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARBin the GLX_ARB_create_context extension andWGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARBin the WGL_ARB_create_context extension, and is ignored if these extensions are not available. This flag puts OpenGL into a “forward compatible” mode, where no deprecated functionality will be supported, possibly at a gain in performance. This only applies to OpenGL 3.0 and later contexts.
-
csdl2.SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG¶ This flag maps to
GLX_CONTEXT_ROBUST_ACCESS_BIT_ARBin the GLX_ARB_create_context_robustness extenstion andWGL_CONTEXT_ROBUST_ACCESS_BIT_ARBin the WGL_ARB_create_context_robustness extension, and is ignored if these extensions are not available. This flag creates an OpenGL context that supports the GL_ARB_robustness extension – a mode that offers a few APIs that are safer than the usual defaults.
-
csdl2.SDL_GL_CONTEXT_RESET_ISOLATION_FLAG¶ This flag maps to
GLX_CONTEXT_RESET_ISOLATION_BIT_ARBin the GLX_ARB_robustness_isolation extension andWGL_CONTEXT_RESET_ISOLATION_BIT_ARBin the WGL_ARB_create_context_robustness extension, and is ignored if these extensions are not available. This flag is intended to require OpenGL to make promises about what to do in the event of driver or hardware failure.
OpenGL Profiles¶
These profile constants are used with SDL_GL_SetAttribute and
SDL_GL_CONTEXT_PROFILE_MASK. Note that these profiles are mutually
exclusive and SDL_GL_SetAttribute accepts at most one of them. Setting
SDL_GL_CONTEXT_PROFILE_MASK to 0 leaves the choice of profile up to
SDL. Should be used in conjunction with SDL_GL_CONTEXT_MAJOR_VERSION
and SDL_GL_CONTEXT_MINOR_VERSION as OpenGL profiles are defined
relative to a particular version of OpenGL. There is no way to distinguish
between the common and common lite profiles of OpenGL ES versions 1.0 and 1.1.
-
csdl2.SDL_GL_CONTEXT_PROFILE_CORE¶ Core profile. Deprecated functions are disabled.
-
csdl2.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY¶ Compatibility profile. Deprecated functions are allowed.
-
csdl2.SDL_GL_CONTEXT_PROFILE_ES¶ OpenGL ES context. Only a subset of base OpenGL functionality is allowed.