sdl_helper.c 882 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "sdl_helper.h"
  2. /* loads a bitmap image using SDL
  3. * returns the requested texture
  4. * returns 0 on error
  5. */
  6. SDL_Texture *dd_load_bmp(const char *filepath) {
  7. // load the surface
  8. SDL_Surface *bmp = SDL_LoadBMP(filepath);
  9. if (!bmp){
  10. printf("SDL_LoadBMP Error: %s\n", SDL_GetError());
  11. return 0;
  12. }
  13. // load the texture
  14. SDL_Texture *tex = SDL_CreateTextureFromSurface(dd_ren, bmp);
  15. SDL_FreeSurface(bmp);
  16. if (!tex){
  17. SDL_FreeSurface(bmp);
  18. printf("SDL_CreateTextureFromSurface Error: %s\n", SDL_GetError());
  19. return 0;
  20. }
  21. return tex;
  22. }
  23. /* loads any type of image using the SDL_Image extension
  24. * returns the requested texture
  25. * returns 0 on error
  26. */
  27. SDL_Texture *dd_load_image(const char *file){
  28. SDL_Texture *texture = IMG_LoadTexture(dd_ren, file);
  29. if (!texture){
  30. printf("IMG_LoadTexture Error: %s\n", SDL_GetError());
  31. return 0;
  32. }
  33. return texture;
  34. }