Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SDL_Surface *image = NULL;
- SDL_Texture *texture = NULL;
- image = SDL_LoadBMP("img/ciel.bmp");
- if(image == NULL)
- {
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_ExitWithError("Impossible de créer l'image");
- }
- texture = SDL_CreateTextureFromSurface(renderer, image);
- SDL_FreeSurface(image);
- if(texture == NULL)
- {
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_ExitWithError("Impossible de creer la texture");
- }
- SDL_Rect rectangle;
- if(SDL_QUERY(texture, NULL, NULL, &rectangle.w, &rectangle.h) != 0) // &rectangle = structure simple pas un pointeur
- {
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_ExitWithError("Impossible de charger la texture");
- }
- rectangle.x = (500 - rectangle.w) / 2;
- rectangle.y = (400 - rectangle.h) / 2;
- if(SDL_RenderCopy(renderer, texture, NULL, &rectangle) != 0)
- {
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_ExitWithError("Impossible d'afficher la texture");
- }
- SDL_RenderPresent(renderer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement