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
|
#include <SDL2/SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include <SDL2_image/SDL_image.h>
int main(int argc, char** argv)
{
SDL_Surface * ws = NULL;
SDL_Surface * is = NULL;
SDL_DisplayMode dpm;
SDL_GetDesktopDisplayMode(0, &dpm);
SDL_Renderer *renderer = NULL;
/* 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_OPENGL|SDL_WINDOW_RESIZABLE);
SDL_GLContext glcontext = SDL_GL_CreateContext(pWindow);
renderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_SOFTWARE);
is = SDL_LoadBMP("image.bmp");
ws = SDL_GetWindowSurface(pWindow);
SDL_BlitSurface(is, NULL, ws, NULL);
SDL_UpdateWindowSurface(pWindow);
if( pWindow )
{
SDL_Delay(19000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
SDL_DestroyWindow(pWindow);
}
else
{
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
}
SDL_FreeSurface(is);
SDL_GL_DeleteContext(glcontext);
SDL_Quit();
return 0;
} |
Partager