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
| #include <SDL2/SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include <SDL2_image/SDL_image.h>
#include <SDL_ttf/SDL_ttf.h>
#include <SDL2_ttf/SDL_ttf.h>
int main(int argc, char** argv)
{
SDL_Surface * is = NULL,*texte = NULL,*image = NULL;
SDL_DisplayMode dpm;
SDL_GetDesktopDisplayMode(0, &dpm);
SDL_Renderer *renderer = NULL;
TTF_Font *fonts = NULL;
SDL_Color ct ={ 255, 255, 255 };
SDL_Rect pt;
int texW=0, texH=0,tx=0,ty=0;
int quit = 0;
TTF_Init();
if (TTF_Init() != 0){
SDL_Quit();
return 1;
}
fonts = TTF_OpenFont("Arial.ttf",65);
SDL_Event event;IMG_Init(IMG_INIT_PNG);
/* Initialisation simple */
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
return -1;
}
/* Création de la fenêtre */
SDL_Window* pWindow = NULL;
pWindow = SDL_CreateWindow("Ma première application SDL2",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800,
600,
SDL_WINDOW_RESIZABLE);
renderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
image =malloc(sizeof(SDL_Surface));
image = SDL_LoadBMP("image.bmp");
if(!image)
{
printf("Erreur de chargement de l'image : %s",SDL_GetError());
return -1;
}
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, image);SDL_FreeSurface(image);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
pt.x = 10;pt.y = 21;
texte=TTF_RenderText_Blended(fonts, "Avé frater", ct);
SDL_Texture* texturet = SDL_CreateTextureFromSurface(renderer, texte);
SDL_QueryTexture(texturet, NULL, NULL, &tx, &ty);
SDL_Rect dstrect = { 10, 53, texW, texH };
dstrect.x = 10;
dstrect.y = 53;
dstrect.w = tx;
dstrect.h = ty;
SDL_RenderCopy(renderer, texturet, NULL, &dstrect);
SDL_RenderPresent(renderer);
SDL_UpdateWindowSurface(pWindow);
while (!quit)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT:
quit = 1;
break;
}
}
IMG_Quit();SDL_DestroyWindow(pWindow);SDL_DestroyRenderer(renderer);
SDL_FreeSurface(is);
SDL_Quit();
TTF_CloseFont(fonts);
TTF_Quit();
return 0;
} |
Partager