1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #include <stdlib.h>#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>
int main( int argc, char * argv[] )
{
// DECLARER LES VARIABLES
SDL_Window *window1;
SDL_Renderer *renderer1;
SDL_Surface *surface1;
SDL_Texture *texture1;
// INITIALISATION MODE VIDEO
if(0 != SDL_Init(SDL_INIT_VIDEO))
{
fprintf(stderr,"probleme d'initialisation");
exit(EXIT_FAILURE);
}
// CREER FENETRE
window1 = SDL_CreateWindow("fenetre 1",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN);
if( window1== NULL)
{
fprintf(stderr,"probleme de creation fenetre");
exit(EXIT_FAILURE);
}
//CREER RENDERER
renderer1 = SDL_CreateRenderer(window1,-1,SDL_RENDERER_SOFTWARE);
if( renderer1 == NULL)
{
fprintf(stderr,"probleme de creation rendu");
exit(EXIT_FAILURE);
}
SDL_SetRenderDrawColor(renderer1, 255, 128, 0, 128);
SDL_SetRenderDrawBlendMode(renderer1,SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(renderer1,NULL);
SDL_RenderPresent(renderer1);
SDL_Delay(2000);
// CREER SURFACE EN CHARGEANT UNE IMAGE DESSUS
// load support for the JPG and PNG image formats
int flags=IMG_INIT_JPG|IMG_INIT_PNG;
int initted=IMG_Init(flags);
if((initted&flags) != flags) {
printf("IMG_Init: Failed to init required jpg and png support!\n");
printf("IMG_Init: %s\n", IMG_GetError());
// handle error
}
//surface1 = SDL_LoadBMP("lac_en_montagne.BMP");
surface1 = IMG_Load("photo.PNG");
if (surface1 == NULL)
{
fprintf(stderr,"probleme de creation de surface");
exit(EXIT_FAILURE);
}
fprintf(stderr,"creation de surface OK");
//CREER TEXTURE DEPUIS SURFACE
texture1 = SDL_CreateTextureFromSurface(renderer1,surface1);
SDL_FreeSurface(surface1);
SDL_SetTextureBlendMode(texture1,SDL_BLENDMODE_BLEND);
if (texture1 == NULL)
{
fprintf(stderr,"probleme de creation de texture");
exit(EXIT_FAILURE);
}
// COPIER LA TEXTURE SUR LE RENDU AFFICHER LE TOUT
SDL_RenderCopy(renderer1,texture1,NULL,NULL);
SDL_RenderPresent(renderer1);
SDL_Delay(2000);
//LIBERER LE TOUT
SDL_DestroyTexture(texture1);
SDL_DestroyRenderer(renderer1);
SDL_DestroyWindow(window1);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager