v2025.6.2
All Bundles

Surface

Core class

Operations

Blit

Perform a fast surface copy to a destination surface

method : public : Blit(srcrect:Rect, dst:Surface, dstrect:Rect) ~ Int

Parameters

NameTypeDescription
srcrectRectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface
dstSurfacethe SDL_Surface structure that is the blit target
dstrectRectthe SDL_Rect structure representing the rectangle that is copied into

Return

TypeDescription
Int0 if the blit is successful or a negative error code on failure

BlitScaled

Scaled surface copy to a destination surface

method : public : BlitScaled(srcrect:Rect, dst:Surface, dstrect:Rect) ~ Int

Parameters

NameTypeDescription
srcrectRectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface
dstSurfacethe SDL_Surface structure that is the blit target
dstrectRectthe SDL_Rect structure representing the rectangle that is copied into

Return

TypeDescription
Int0 if the blit is successful or a negative error code on failure

Convert

Copy an existing surface into a new one that is optimized for blitting to a surface of a specified pixel format

method : public : Convert(fmt:PixelFormat, flags:Int) ~ Surface

Parameters

NameTypeDescription
fmtPixelFormatPixelFormat structure that the new surface is optimized for
flagsIntflags are unused and should be set to 0

Return

TypeDescription
Surfacenew SDL_Surface structure that is created

ConvertFormat

Copy an existing surface to a new surface of the specified format

method : public : ConvertFormat(format:Int, flags:Int) ~ Surface

Parameters

NameTypeDescription
formatIntone of the enumerated values in SDL_PixelFormatEnum; see Remarks for details
flagsIntthe flags are unused and should be set to 0

Return

TypeDescription
Surfacethe new surface

CreateTexture

Create a texture from an existing surface

method : public : CreateTexture(renderer:Renderer) ~ Texture

Parameters

NameTypeDescription
rendererRendererthe rendering context

Return

TypeDescription
Texturenewly created texture

Duplicate

Creates a new surface identical to the existing surface

method : public : Duplicate() ~ Surface

Return

TypeDescription
Surfacea copy of the surface, or NULL on failure

FillRect

perform a fast fill of a rectangle with a specific color

method : public : FillRect(rect:Rect, color:Int) ~ Int

Parameters

NameTypeDescription
rectRectRect structure representing the rectangle to fill, or Nil to fill the entire surface
colorIntcolor to fill with

Return

TypeDescription
Int0 on success or a negative error code on failure

Free

Frees the event

method : public : Free() ~ Nil

GetAlphaMod

Get the additional alpha value used in blit operations

method : public : GetAlphaMod(alpha:IntRef) ~ Int

Parameters

NameTypeDescription
alphaIntRefholder filled in with the current alpha value

Return

TypeDescription
Int0 on success or a negative error code on failure

GetBlendMode

get the blend mode used for blit operations

method : public : GetBlendMode(blendMode:IntRef) ~ Int

Parameters

NameTypeDescription
blendModeIntRefpointer filled in with the current BlendMode

Return

TypeDescription
Int0 on success or a negative error code on failure

GetClipRect

Get the clipping rectangle for a surface

method : public : GetClipRect(rect:Rect) ~ Nil

Parameters

NameTypeDescription
rectRectRect filled in with the clipping rectangle for the surface

GetColorKey

Get the color key (transparent pixel) for a surface

method : public : GetColorKey(key:IntRef) ~ Int

Parameters

NameTypeDescription
keyIntRefa holder filled in with the transparent pixel

Return

TypeDescription
Int0 on success or a negative error code on failure

GetColorMod

Get the additional color value multiplied into blit operations

method : public : GetColorMod(r:IntRef, g:IntRef, b:IntRef) ~ Int

Parameters

NameTypeDescription
rIntRefpointer filled in with the current red color value
gIntRefpointer filled in with the current green color value
bIntRefpointer filled in with the current blue color value

Return

TypeDescription
Int0 on success or a negative error code on failure

GetH

Get height

method : public : GetH() ~ Int

Return

TypeDescription
Intheight

GetPitch

Get length of a row of pixels in bytes

method : public : GetPitch() ~ Int

Return

TypeDescription
Intpitch

GetPixelFormat

Get pixel format

method : public : GetPixelFormat() ~ PixelFormat

Return

TypeDescription
PixelFormatpixel format

GetPixels

Get raw pixels

method : public : GetPixels() ~ PixelData

Return

TypeDescription
PixelDataraw pixels

GetW

Get width

method : public : GetW() ~ Int

Return

TypeDescription
Intwidth

IsNull

Determines if the underlying SDL C-struct is NULL

method : public : IsNull() ~ Bool

Return

TypeDescription
Booltrue if NULL, false otherwise

LoadBMP

Load a surface from a BMP file.

function : LoadBMP(file:String) ~ Surface

Parameters

NameTypeDescription
fileStringthe file containing a BMP image

Return

TypeDescription
Surfacenewly created texture

Lock

Set up a surface for directly accessing the pixels

method : public : Lock() ~ Int

LowerBlit

Perform low-level surface blitting only

method : public : LowerBlit(srcrect:Rect, dst:Surface, dstrect:Rect) ~ Int

Parameters

NameTypeDescription
srcrectRectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface
dstSurfacethe SDL_Surface structure that is the blit target
dstrectRectthe SDL_Rect structure representing the rectangle that is copied into

Return

TypeDescription
Int0 if the blit is successful or a negative error code on failure

LowerBlitScaled

Perform low-level surface scaled blitting only

method : public : LowerBlitScaled(srcrect:Rect, dst:Surface, dstrect:Rect) ~ Int

Parameters

NameTypeDescription
srcrectRectthe SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface
dstSurfacethe SDL_Surface structure that is the blit target
dstrectRectthe SDL_Rect structure representing the rectangle that is copied into

Return

TypeDescription
Int0 if the blit is successful or a negative error code on failure

New

Creates new RGB surface

New(flags:Int, width:Int, height:Int, depth:Int, Rmask:Int, Gmask:Int, Bmask:Int, Amask:Int)

Parameters

NameTypeDescription
flagsIntthe flags are unused and should be set to 0
widthIntthe width of the surface
heightIntthe height of the surface
depthIntthe depth of the surface in bits; see Remarks for details
RmaskIntthe red mask for the pixels
GmaskIntthe green mask for the pixels
BmaskIntthe blue mask for the pixels
AmaskIntthe alpha mask for the pixels

New

Creates new RGB surface

New(flags:Int, width:Int, height:Int, depth:Int, format:Int)

Parameters

NameTypeDescription
flagsIntthe flags are unused and should be set to 0
widthIntthe width of the surface
heightIntthe height of the surface
depthIntthe depth of the surface in bits; see Remarks for details
formatIntthe PixelFormatValue for the new surface's pixel format

Rotate90Degrees

Rotates a 8/16/24/32 bit surface in increments of 90 degrees.

method : public : Rotate90Degrees(numClockwiseTurns:Int) ~ Surface

Parameters

NameTypeDescription
numClockwiseTurnsIntNumber of clockwise 90 degree turns to apply to the source.

Return

TypeDescription
Surfacenewly modified surface

RotoZoom

Rotates and zooms a surface and optional anti-aliasing.

method : public : RotoZoom(angle:Float, zoom:Float, smooth:Bool) ~ Surface

Parameters

NameTypeDescription
angleFloatThe angle to rotate in degrees.
zoomFloatThe scaling factor.
smoothBoolAntialiasing flag; set to true to enable.

Return

TypeDescription
Surfacenewly modified surface

RotoZoomSize

Returns the size of the resulting target surface for a RotoZoom() call.

function : RotoZoomSize(width:Int, height:Int, angle:Float, zoom:Float, dstwidth:IntRef, dstheight:IntRef) ~ Nil

Parameters

NameTypeDescription
widthIntThe source surface width.
heightIntThe source surface height.
angleFloatThe angle to rotate in degrees.
zoomFloatThe scaling factor.
dstwidthIntRefThe calculated width of the rotozoomed destination surface.
dstheightIntRefThe calculated height of the rotozoomed destination surface.

RotoZoomSizeXY

Returns the size of the resulting target surface for a RotoZoomXY() call.

function : RotoZoomSizeXY(width:Int, height:Int, angle:Float, zoomx:Float, zoomy:Float, dstwidth:IntRef, dstheight:IntRef) ~ Nil

Parameters

NameTypeDescription
widthIntThe source surface width.
heightIntThe source surface height.
angleFloatThe angle to rotate in degrees.
zoomxFloatThe horizontal scaling factor.
zoomyFloatThe vertical scaling factor.
dstwidthIntRefThe calculated width of the rotozoomed destination surface.
dstheightIntRefThe calculated height of the rotozoomed destination surface.

RotoZoomXY

Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.

method : public : RotoZoomXY(angle:Float, zoomx:Float, zoomy:Float, smooth:Bool) ~ Surface

Parameters

NameTypeDescription
angleFloatThe angle to rotate in degrees.
zoomxFloatThe horizontal scaling factor.
zoomyFloatThe vertical scaling factor.
smoothBoolAntialiasing flag; set to true to enable.

Return

TypeDescription
Surfacenewly modified surface

SaveBMP

save a surface to a BMP file

function : SaveBMP(surface:Surface, file:String) ~ Int

Parameters

NameTypeDescription
surfaceSurfaceSurface instance containing the image to be saved
fileStringfile to be saved to

Return

TypeDescription
Int0 on success or a negative error code on failure

SetAlphaMod

Set an additional alpha value used in blit operations

method : public : SetAlphaMod(alpha:Int) ~ Int

Parameters

NameTypeDescription
alphaIntalpha value multiplied into blit operations

Return

TypeDescription
Int0 on success or a negative error code on failure

SetBlendMode

set the blend mode used for blit operations

method : public : SetBlendMode(blendMode:BlendMode) ~ Int

Parameters

NameTypeDescription
blendModeBlendModeBlendMode to use for blit blending

Return

TypeDescription
Int0 on success or a negative error code on failure

SetClipRect

Set the clipping rectangle for a surface

method : public : SetClipRect(rect:Rect) ~ Bool

Parameters

NameTypeDescription
rectRectRect structure representing the clipping rectangle, or Nil to disable clipping

Return

TypeDescription
BoolReturns true if the rectangle intersects the surface, otherwise false and blits will be completely clipped

SetColorKey

Set the color key (transparent pixel) in a surface

method : public : SetColorKey(flag:Bool, key:Int) ~ Int

Parameters

NameTypeDescription
flagBooltrue to enable color key, false to disable color key
keyIntthe transparent pixel

Return

TypeDescription
Int0 on success or a negative error code on failure

SetColorMod

Set an additional color value multiplied into blit operation

method : public : SetColorMod(r:Int, g:Int, b:Int) ~ Int

Parameters

NameTypeDescription
rIntthe red color value multiplied into blit operations
gIntthe green color value multiplied into blit operations
bIntthe blue color value multiplied into blit operations

Return

TypeDescription
Int0 on success or a negative error code on failure

SetRLE

Set the RLE acceleration hint for a surface

method : public : SetRLE(flag:Int) ~ Int

Parameters

NameTypeDescription
flagInt0 to disable, non-zero to enable RLE acceleration

Return

TypeDescription
Int0 on success or a negative error code on failure

Shrink

Shrink a surface by an integer ratio using averaging.

method : public : Shrink(factorx:Int, factory:Int) ~ Surface

Parameters

NameTypeDescription
factorxIntThe horizontal shrinking ratio.
factoryIntThe vertical shrinking ratio.

Return

TypeDescription
Surfacenewly modified surface

Unlock

Release a surface after directly accessing the pixels

method : public : Unlock() ~ Nil

Zoom

Zoom a surface by independent horizontal and vertical factors with optional smoothing.

method : public : Zoom(zoomx:Float, zoomy:Float, smooth:Bool) ~ Surface

Parameters

NameTypeDescription
zoomxFloatThe horizontal scaling factor.
zoomyFloatThe vertical scaling factor.
smoothBoolAntialiasing flag; set to true to enable.

Return

TypeDescription
Surfacenewly modified surface

ZoomSize

Returns the size of the resulting target surface for a Zoom() call.

function : ZoomSize(width:Int, height:Int, zoomx:Float, zoomy:Float, dstwidth:IntRef, dstheight:IntRef) ~ Nil

Parameters

NameTypeDescription
widthIntThe source surface width.
heightIntThe source surface height.
zoomxFloatThe horizontal scaling factor.
zoomyFloatThe vertical scaling factor.
dstwidthIntRefThe calculated width of the rotozoomed destination surface.
dstheightIntRefThe calculated height of the rotozoomed destination surface.