Intro

How Chapter 3 works?

  1. Init()
    1. SDL_Init()
    2. SDL_CreateWindow()
    3. SDL_GetWindowSurface()
  2. loadMedia()
    1. SDL_LoadBMP()
  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) with SDL_BlitSurface().
      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_PollEvent()

1
int SDL_PollEvent( SDL_Event* event );
  • param
    • event : the SDL_Event structure to be filled with the next event from the queue, or NULL
  • return
    • 1 if queue contains any event inside
    • 0 if there’s no event in queue

when this function called, event at head will be removed from queue and stored to event.
(return value 1 shows this works happend) (NULL inside queue won’t works like this)
this function implicitly contains SDL_PumpEvent().


Struct

SDL_Event

general cross-platform event struct
contains event data


Term

SDL_Event..type

  • SDL_QUIT