SDL Chapter 2


Intro #

How Chapter 2 works? #

  1. Init()
    1. SDL_Init()
    2. SDL_CreateWindow()
    3. SDL_GetWindowSurface()
  2. loadMedia()
    1. SDL_LoadBMP()
  3. copy image(Blit) into surface with SDL_BlitSurface().
  4. update window with SDL_UpdateWindowSurface() to refresh and show what we’ve done.
    • you can delay loop( for window lasting) with SDL_Delay().
  5. close()
    1. SDL_FreeSurface()
    2. SDL_DestroyWindow()
    3. SDL_Quit()

Function #

SDL_LoadBMP() #

SDL_Surface* SDL_LoadBMP( const char* file );
  • param
    • file : the file containing a BMP image
  • return
    • surface that contain BMP on success
    • NULL on failure

Gets SDL_Surface object from BMP file and returns its address.

SDL_FreeSurface() #

void SDL_FreeSurface( SDL_Surface* surface );
  • param
    • surface : the SDL_Surface to free
  • return is void

free surface object on memory.

SDL_BlitSurface() #

int SDL_BlitSurface( SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect );
  • param
    • src : the SDL_Surface structure to be copied from
    • srcrect : the SDL_Rect structure representing the rectangle to be copied, or NULL to copy the entire surface
    • dst : the SDL_Surface structure that is the blit target
    • dstrect : the SDL_Rect structure representing the rectangle that is copied into
  • return
    • 0 on blit success
    • negative integer as error code on failure

Blit image into surface’s rect area or entire surface.


Struct #

  • nothing new

Term #

  • nothing new