Skip to content
Snippets Groups Projects
Commit 780fbe42 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

fenetre centree et monte

parent b980ff8d
No related branches found
No related tags found
No related merge requests found
File added
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
SDL_Window
*window = NULL;
int window_width = 400;
int window_height = 300;
int window_x;
int window_y;
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_DisplayMode mode;
int display_width;
int display_height;
if (SDL_GetDesktopDisplayMode(0, &mode) != 0)
{
SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
return 1;
}
display_width = mode.w;
display_height = mode.h;
/* Initialisation de la SDL + gestion de l'échec possible */
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
SDL_Log("Error : SDL initialisation - %s\n",
SDL_GetError()); // l'initialisation de la SDL a échoué
exit(EXIT_FAILURE);
}
/* Création de la fenêtre */
window_x = (display_width-window_width)/2;
window_y = display_height;
window = SDL_CreateWindow(
"Rocket",
0, 0, // coin haut gauche en haut gauche de l'écran
400, 300, // largeur = 400, hauteur = 300
window_x, window_y, // centrage de la fenêtre
window_width, window_height, // largeur = 400, hauteur = 300
SDL_WINDOW_RESIZABLE); // redimensionnable
if (window == NULL) {
if (window == NULL)
{
SDL_Log("Error : SDL window 1 creation - %s\n",
SDL_GetError()); // échec de la création de la fenêtre
SDL_Quit(); // On referme la SDL
exit(EXIT_FAILURE);
}
/* Normalement, on devrait ici remplir les fenêtres... */
SDL_Delay(2000); // Pause exprimée en ms
while(window_y > 0){
window_y = window_y - 100;
SDL_SetWindowPosition(window, window_x, window_y);
SDL_Delay(1000); // Pause exprimée en ms
}
/* et on referme tout ce qu'on a ouvert en ordre inverse de la création */
SDL_DestroyWindow(window); // la fenêtre
......
......@@ -8,4 +8,4 @@ main.o:main.c
$(CC) -c main.c -g -Wall -Wextra
clean:
rm -rf main
rm -rf main main.o
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment