Surface Creation and Simple Drawing¶
-
class
csdl2.SDL_Surface¶ A structure that contains a collection of pixels used in software blitting.
This structure cannot be initiated directly. Use
SDL_CreateRGBSurface(),SDL_CreateRGBSurfaceFrom(),SDL_LoadBMP_RW()orSDL_LoadBMP()to create a new instance.-
flags¶ (readonly) A bitmask of the flags
SDL_PREALLOC,SDL_RLEACCELand/orSDL_DONTFREEfor internal use.
-
format¶ (readonly)
SDL_PixelFormatof the pixels stored in the surface.
-
w¶ (readonly) Width of the surface in pixels.
-
h¶ (readonly) Height of the surface in pixels.
-
pitch¶ (readonly) The length of a row of pixels in bytes.
-
pixels¶ (readonly) Buffer providing the actual pixel data.
-
userdata¶ An arbitrary object that an application can set for its own use.
-
locked¶ (readonly) True if the surface is locked.
-
clip_rect¶ (readonly) An
SDL_Rectstructure used to clip bits to the surface which can be set bySDL_SetClipRect().
-
refcount¶ (readonly) SDL’s reference count of the surface. For internal use.
-
-
csdl2.SDL_PREALLOC¶ Surface uses preallocated memory.
-
csdl2.SDL_RLEACCEL¶ Surface is RLE encoded.
-
csdl2.SDL_DONTFREE¶ Surface is referenced internally.
-
csdl2.SDL_MUSTLOCK(surface: SDL_Surface) → bool¶ Returns True if surface needs to be locked before its
SDL_Surface.pixelscan be accessed.Parameters: surface (SDL_Surface) – The surface to test Returns: True if the surface needs to be locked before its pixels can be accessed, False otherwise.
-
csdl2.SDL_CreateRGBSurface(flags: int, width: int, height: int, depth: int, Rmask: int, Gmask: int, Bmask: int, Amask: int) → SDL_Surface¶ Creates and returns a new blank
SDL_Surfacewith the specified properties.Parameters: - flags (int) – This argument is unused and should be set to 0.
- width (int) – The width of the surface in pixels.
- height (int) – The height of the surface in pixels.
- depth (int) – The depth of the surface in bits. If depth is 4 or 8
bits, an empty
SDL_Paletteis allocated for the surface. If depth is greater than 8 bits, the pixel format is set using the Rmask, Gmask, Bmask and Amask arguments. - Rmask (int) – Bitmask used to extract the red component from a pixel. If 0, a default mask based on the depth is used.
- Gmask (int) – Bitmask used to extract the green component from a pixel. If 0, a default mask based on the depth is used.
- Bmask (int) – Bitmask used to extract the blue component from a pixel. If 0, a default mask based on the depth is used.
- Amask (int) – Bitmask used to extract the alpha component from a pixel. If 0, the surface has no alpha channel.
Returns: A new blank
SDL_Surfacestructure.
-
csdl2.SDL_CreateRGBSurfaceFrom(pixels: buffer, width: int, height: int, depth: int, pitch: int, Rmask: int, Gmask: int, Bmask: int, Amask: int) → SDL_Surface¶ Creates and returns a
SDL_Surfacewith existing pixel data.Parameters: - pixels (buffer) – Existing pixel data. This can be any object that supports the buffer protocol and exports a C-contiguous buffer of the correct size.
- width (int) – The width of the surface in pixels.
- height (int) – The height of the surface in pixels.
- depth (int) – The depth of the surface in bits. If depth is 4 or 8
bits, an empty
SDL_Paletteis allocated for the surface. If depth is greater than 8 bits, the pixel format is set using the Rmask, Gmask, Bmask and Amask arguments. - Rmask (int) – Bitmask used to extract the red component from a pixel. If 0, a default mask based on the depth is used.
- Gmask (int) – Bitmask used to extract the green component from a pixel. If 0, a default mask based on the depth is used.
- Bmask (int) – Bitmask used to extract the blue component from a pixel. If 0, a default mask based on the depth is used.
- Amask (int) – Bitmask used to extract the alpha component from a pixel. If 0, the surface has no alpha channel.
Returns: A
SDL_Surfacewith its contents backed by the provided pixels buffer.
-
csdl2.SDL_LoadBMP_RW(src, freesrc) → SDL_Surface¶ Load a BMP image from a seekable SDL data stream. (memory or file).
Parameters: - src (
SDL_RWops) – The data stream for the surface. - freesrc (bool) – True to close the stream after being read.
Returns: SDL_Surfacewith the image data.- src (
-
csdl2.SDL_LoadBMP(file) → SDL_Surface¶ Load a surface from a BMP file on the filesystem.
Parameters: file (str) – The path to the file containing a BMP image. Returns: SDL_Surfacewith the image data.
-
csdl2.SDL_FreeSurface(surface: SDL_Surface)¶ Frees the surface.
There is no need to manually call this function.
SDL_Surfacewill automatically call this function as part of its destructor.Parameters: surface (SDL_Surface) – surface to free