DRAFT |
SDL_BlitSurface
Use this function to perform a fast blit from the source surface to the destination surface.
Contents
Syntax
int SDL_BlitSurface(SDL_Surface* src,
SDL_Rect* srcrect,
SDL_Surface* dst,
SDL_Rect* dstrect)
Function Parameters
src |
a pointer to the source surface / SDL_Surface containing srcrect |
srcrect |
a pointer to the source rectangle / SDL_Rect to be queried |
dst |
a pointer to the destination surface / SDL_Surface containing dstrect |
dstrect |
a pointer to the destination rectangle / SDL_Rect to be filled |
Return Value
If the blit is successful it returns 0, otherwise it returns -1 on failure; call SDL_GetError() for more information.
See Remarks for details if the return value is -2.
Code Examples
You can add your code example here
Remarks
This is the public blit function, and it performs rectangle validation and clipping before passing it to SDL_LowerBlit(). green
You should call SDL_BlitSurface() unless you know exactly how SDL blitting works internally and how to use the other blit functions.
green
The blit function should not be called on a locked surface. green
This assumes that the source and destination rectangles are the same size. If either srcrect or dstrect are NULL, the entire surface (src or dst) is copied. The final blit rectangles are saved in srcrect and dstrect after all clipping is performed.
green
The blit semantics for surfaces with and without alpha and colorkey are defined as follows:
- \verbatim
RGBA->RGB:
- SDL_SRCALPHA set:
- alpha-blend (using alpha-channel). SDL_SRCCOLORKEY ignored.
- copy RGB. if SDL_SRCCOLORKEY set, only copy the pixels matching the RGB values of the source colour key, ignoring alpha in the comparison.
RGB->RGBA:
- SDL_SRCALPHA set:
- alpha-blend (using the source per-surface alpha value); set destination alpha to opaque.
- copy RGB, set destination alpha to source per-surface alpha value.
- if SDL_SRCCOLORKEY set, only copy the pixels matching the source colour key.
RGBA->RGBA:
- SDL_SRCALPHA set:
- alpha-blend (using the source alpha channel) the RGB values; leave destination alpha untouched. [Note: is this correct?] SDL_SRCCOLORKEY ignored.
- copy all of RGBA to the destination. if SDL_SRCCOLORKEY set, only copy the pixels matching the RGB values of the source colour key, ignoring alpha in the comparison.
RGB->RGB:
- SDL_SRCALPHA set:
- alpha-blend (using the source per-surface alpha value).
- copy RGB.
- if SDL_SRCCOLORKEY set, only copy the pixels matching the source colour key.
- SDL_SRCALPHA set:
If either of the surfaces were in video memory, and the blit returns -2, the video memory was lost, so it should be reloaded with artwork and re-blitted:
@code while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) { while ( SDL_LockSurface(image) < 0 ) Sleep(10); -- Write image pixels to image->pixels -- SDL_UnlockSurface(image); } @endcode
green
This happens under DirectX 5.0 when the system switches away from your fullscreen application. The lock will also fail until you have access to the video memory again.
