I don’t really know what format to use i just need to load a .png.
On the wiki it shows a bunch of pixel formats and i don’t know what they mean.
I am also confused about which macro to use.
I am just really confused about this whole situation.
I don’t really know what format to use i just need to load a .png.
On the wiki it shows a bunch of pixel formats and i don’t know what they mean.
I am also confused about which macro to use.
I am just really confused about this whole situation.
I recommend downloading the SDL2_image lib to load .pngs.
SDL2 does not load .pngs by default.
// Initialise SDL_image to load .pngs (Supports JPEG and more)
IMG_Init(IMG_INIT_PNG);
// Loading .png
SDL_Surface* surface = IMG_Load("image.png");
// Before you call SDL_Quit(), shut down SDL_Image using IMG_Quit():
IMG_Quit();
Thank you for this!
This will be very useful!
Edit: when i do this it tells me i have an undefined reference to IMG_init
Edit: nvrmind i fixed it
There’s also SDL_stbimage.h which is easier to integrate and has no external dependencies (just that header and stb_image.h and SDL itself, of course).
It doesn’t support as many file formats as SDL_Image, but common ones including PNG, JPEG, BMP, TGA are supported.
Usage is pretty similar to SDL_Image, except there is no Init() or Quit() function, so it’s just
SDL_Surface* surface = STBIMG_Load("image.png");
See the comment at the beginning of the SDL_stbimage.h header for how to use and integrate it.
Thanks for this but I think the sdl image works pretty well for what i want.
still pretty cool tho.