Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. SDL_Surface *image = NULL;
  2. SDL_Texture *texture = NULL;
  3.  
  4. image = SDL_LoadBMP("img/ciel.bmp");
  5.  
  6. if(image == NULL)
  7. {
  8. SDL_DestroyRenderer(renderer);
  9. SDL_DestroyWindow(window);
  10. SDL_ExitWithError("Impossible de créer l'image");
  11. }
  12. texture = SDL_CreateTextureFromSurface(renderer, image);
  13. SDL_FreeSurface(image);
  14.  
  15. if(texture == NULL)
  16. {
  17. SDL_DestroyRenderer(renderer);
  18. SDL_DestroyWindow(window);
  19. SDL_ExitWithError("Impossible de creer la texture");
  20. }
  21. SDL_Rect rectangle;
  22. if(SDL_QUERY(texture, NULL, NULL, &rectangle.w, &rectangle.h) != 0) // &rectangle = structure simple pas un pointeur
  23. {
  24. SDL_DestroyRenderer(renderer);
  25. SDL_DestroyWindow(window);
  26. SDL_ExitWithError("Impossible de charger la texture");
  27. }
  28.  
  29. rectangle.x = (500 - rectangle.w) / 2;
  30. rectangle.y = (400 - rectangle.h) / 2;
  31.  
  32. if(SDL_RenderCopy(renderer, texture, NULL, &rectangle) != 0)
  33. {
  34. SDL_DestroyRenderer(renderer);
  35. SDL_DestroyWindow(window);
  36. SDL_ExitWithError("Impossible d'afficher la texture");
  37. }
  38.  
  39. SDL_RenderPresent(renderer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement