Commit 487f0142 authored by Lilian HIAULT's avatar Lilian HIAULT 💜
Browse files

Ajout x-fenetre v2

parent 8d48acfe
#CC : le compilateur à utiliser
CC=gcc
#CFLAGS : les options de compilation
CFLAGS=$(shell sdl2-config --cflags) -Wall -Wextra -g -DVERBOSE
# les librairies à utiliser
LIBS=$(shell sdl2-config --libs)
#LDFLAGS : les options d'édition de lien
LDFLAGS=
#lieu où se trouve les sources :
SRC=./src/
#les fichiers objets
OBJ=$(SRC)main.o
out : $(OBJ)
$(CC) $(LDFLAGS) $^ -o $@ $(LIBS)
$(SRC)%.o: $(SRC)%.c $(SRC)%.h
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@
clean:
rm -rf $(SRC)*.o out
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char ** argv)
{
(void) argc;
(void) argv;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
SDL_Log("Error : SDL initialisation - %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
int width = DM.w;
int height = DM.h;
printf("%i | %i\n", width, height);
int n = 5;
int decal_w = width / n;
int decal_h = height / n;
// Créer fenêtres
int i = 0, k = 0;
SDL_Window ** win_gauche = malloc(n*sizeof(SDL_Window *));
for (i=0; i<n; i++)
{
win_gauche[i] = SDL_CreateWindow(
"Fenêtre gauche",
decal_w * i, decal_h * i,
200, 100,
SDL_WINDOW_RESIZABLE);
if(win_gauche[i] == NULL)
{
SDL_Log("Error : SDL window gauche %i creation - %s\n", i, SDL_GetError());
for (k=0; k<i; k++)
{
SDL_DestroyWindow(win_gauche[i]);
SDL_Quit();
exit(EXIT_FAILURE);
}
}
}
SDL_Delay(1000);
// Déplacer fenêtres
int w = width, h = height;
for(i=0; i<n; i++)
{
SDL_GetWindowPosition(win_gauche[i], &w, &h);
while(w > 0)
{
w--;
SDL_SetWindowPosition(win_gauche[i], w, h);
SDL_Delay(10);
}
}
SDL_Delay(3000);
for (i=0; i<n; i++)
{
SDL_DestroyWindow(win_gauche[i]);
SDL_Quit();
exit(EXIT_FAILURE);
}
SDL_Quit();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
int init(SDL_Window **window, SDL_Renderer **renderer, int w, int h) {
/* Fonction qui initialise la fenetre */
// init video
if (0 != SDL_Init(SDL_INIT_VIDEO)) {
fprintf(stderr, "Error SDL_Init : %s", SDL_GetError());
return -1;
}
// init fenetre
*window = SDL_CreateWindow("Titre fenetre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_SHOWN);
if (NULL == window) {
fprintf(stderr, "Error SDL_CreateWindow : %s", SDL_GetError());
return -1;
}
// init renderer
*renderer = SDL_CreateRenderer(*window, -1, SDL_RENDERER_ACCELERATED || SDL_RENDERER_PRESENTVSYNC);
if (NULL == renderer) {
fprintf(stderr, "Error SDL_CreateRenderer : %s", SDL_GetError());
return -1;
}
// init icon
SDL_Surface *icon = NULL;
icon = SDL_LoadBMP("textures/icone.bmp");
if (NULL == icon) {
fprintf(stderr, "Error SDL_LoadBMP : %s", SDL_GetError());
return -1;
}
SDL_SetWindowIcon(*window, icon);
return 0;
}
#ifndef WINDOWMAKER_H_
#define WINDOWMAKER_H_
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
int init(SDL_Window **window, SDL_Renderer **renderer, int w, int h);
#endif
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment