Intro #
How Chapter 6 works? #
- init()
SDL_Init()
SDL_CreateWindow()
IMG_Init()
SDL_GetWindowSurface()
- loadMedia()
- loadSurface()
- load PNG file on intermediate surface with
IMG_Load()
. - optimize loaded intermediate surface into optimized surface with
SDL_ConvertSurface()
.- free memory of intermediate surface with
SDL_FreeSurface()
.
- free memory of intermediate surface with
- load PNG file on intermediate surface with
- loadSurface()
- start loop untill variable
quit
is true.- start loop that calls
SDL_PollEvent()
untill it returns 0.- if
SDL_Event
.type isSDL_QUIT
, quit is true( which means first loop will end). - copy screen(Blit) with
SDL_BlitSurface()
from chosen PNG surface to screen surface. - update window with
SDL_UpdateWindowSurface()
to refresh and show what we’ve done.
- if
- start loop that calls
- close()
SDL_FreeSurface()
SDL_DestroyWindow()
IMG_Quit()
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
- if you have dll error, use
- writer is using IMG_2.0.4 version on SDL_2.0.9 version
Function #
IMG_Init() #
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() #
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() #
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() #
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_*