Intro

How Chapter 6 works?

  1. init()
    1. SDL_Init()
    2. SDL_CreateWindow()
    3. IMG_Init()
    4. SDL_GetWindowSurface()
  2. loadMedia()
    1. loadSurface()
      1. load PNG file on intermediate surface with IMG_Load().
      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) with SDL_BlitSurface() from chosen PNG surface to screen surface.
      3. update window with SDL_UpdateWindowSurface() to refresh and show what we’ve done.
  4. close()
    1. SDL_FreeSurface()
    2. SDL_DestroyWindow()
    3. IMG_Quit()
    4. SDL_Quit()

SDL_image.h

  • SDL_image is used in this chapter
  • if you’re running on Windows, you need to place dll file inside proper system directory (like Windows/System32)
    • if you have dll error, use where <dll_name.dll> command to find error-able dll’s location
  • writer is using IMG_2.0.4 version on SDL_2.0.9 version

Function

IMG_Init()

1
int IMG_Init( int flags );
  • param
    • flsgs : bit flag indicates which image format to use while program
  • return
    • flags that loaded successfully on both entire, partial success
    • 0 on failure

IMG_isJPG(), IMG_isPNG(), IMG_isTIF() doesn’t requires its initialization.
you can check currently loaded system with calliing this function with 0.

IMG_GetError()

1
char* IMG_GetError( void );
  • param
    • void
  • return
    • char array with recent error information on error
    • empty array on no error happen

IMG version of SDL_GetError()

IMG_Load()

1
SLD_Surface* IMG_Load( const char* file );
  • param
    • file : image file name string (char array/pointer)
  • return
    • image-loaded surface’s address on success
    • NULL on error

this function calls IMG_LoadTyped_RW() inside logic.
since this function returns surface, call SDL_FreeSurface() after use of this surface.

IMG_Quit()

1
void IMG_Quit( void );
  • param
    • void
  • return
    • void

this function called after all IMG jobs are done.
SDL recommend to call this function essentially at end of program if you used IMG subsystem.


Struct

  • nothing new

Term

IMG_Init()

  • IMG_INIT_PNG
  • IMG_INIT_JPG
  • IMG_INIT_TIF
  • IMG_INIT_*