Intro

How Chapter 5 works?

  1. init()
    1. SDL_Init()
    2. SDL_CreateWindow()
    3. SDL_GetWindowSurface()
  2. loadMedia()
    1. loadSurface()
      1. load BMP file on intermediate surface with SDL_LoadBMP().
      2. optimize loaded intermediate surface into optimized surface with SDL_ConvertSurface().
        • free memory of intermediate surface with SDL_FreeSurface().
  3. start loop untill variable quit is true.
    1. start loop that calls SDL_PollEvent() untill it returns 0.
      1. if SDL_Event.type is SDL_QUIT, quit is true( which means first loop will end).
      2. copy screen(Blit) scaled one with SDL_BlitScaled().
      3. update window with SDL_UpdateWindowSurface() to refresh and show what we’ve done.
  4. close()
    1. SDL_FreeSurface()
    2. SDL_DestroyWindow()
    3. SDL_Quit()

Function

SDL_ConvertSurface()

1
SDL_Surface* SDL_ConvertSurface( SDL_Surface* src, const SDL_PixelFormat* fmt, Uint32 flags );
  • param
    • src : the existing SDL_Surface structure to convert
    • fmt : the SDL_PixelFormat structure that the new surface is optimized for
    • flags : the flags are unused and should be set to 0; this is a leftover from SDL 1.2’s API
  • return
    • new surface on success
    • NULL on failure

get surface src and convert it into specific format that fmt indicating.

SDL_BlitScaled()

1
int SDL_BlitScaled( 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 entire surface
    • dst : the SDL_Surface structure that is the blit target
    • dstrect : the SDL_Rect structure representing the rectangle that is copied into, or NULL to copy into the entire surface
  • return
    • 0 on success
    • negative integer as error code on failure

Simiral with SDL_BlitSurface() but blit scaled surface.
this function call SDL_LowerBlitScaled() internally.


Struct

SDL_PixelFormat


Term

  • nothing new