Commit 572a5bc0 authored by Coralie Pierre's avatar Coralie Pierre
Browse files

Merge branch 'animation' into x-fenetre

parents 09ca96b7 86619e57
#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) -lSDL2_image
#LDFLAGS : les options d'édition de lien
LDFLAGS=
#lieu où se trouve les sources :
SRC=./src/
#les fichiers objets
OBJ=$(SRC)main.o\
$(SRC)image.o\
$(SRC)windowMaker.o
out : $(OBJ)
$(CC) $(LDFLAGS) $^ -o $@ $(LIBS)
$(SRC)%.o: $(SRC)%.c $(SRC)%.h
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@
clean:
rm -rf $(SRC)*.o out
#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\
$(SRC)windowMaker.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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
SDL_Texture *loadPicture (const char path[], SDL_Renderer *renderer) {
/* Permet d'ouvrir des images autre que BITMAP comme PNG, JPG, ... */
SDL_Texture *texture = NULL;
SDL_Surface *tmp = IMG_Load(path);
if (!tmp) {
printf("Error IMG_Load : %s", SDL_GetError());
return NULL;
}
texture = SDL_CreateTextureFromSurface(renderer, tmp);
SDL_FreeSurface(tmp);
if (NULL == texture) {
fprintf(stderr, "Error SDL_CreateTextureFromSurface : %s", SDL_GetError());
return NULL;
}
return texture;
}
int printPicture (SDL_Renderer *renderer, SDL_Texture *img, int x, int y) {
/* affiche une image sur le renderer */
if (NULL == img) {
return -1;
}
// on l'affiche à des coordonnées précises
if (x != -1 && y != -1) {
SDL_Point size;
SDL_QueryTexture(img, NULL, NULL, &size.x, &size.y);
SDL_Rect dst;
dst.x = x;
dst.y = y;
dst.h = size.x;
dst.w = size.y;
SDL_RenderCopy(renderer, img, NULL, &dst);
}
// l'image prend tout l'écran
else {
SDL_RenderCopy(renderer, img, NULL, NULL);
}
SDL_RenderPresent(renderer);
return 0;
}
cl@cl-manjaro.11381:1623671775
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
SDL_Texture *loadPicture (const char path[], SDL_Renderer *renderer) {
/* Permet d'ouvrir des images autre que BITMAP comme PNG, JPG, ... */
SDL_Texture *texture = NULL;
SDL_Surface *tmp = IMG_Load(path);
if (!tmp) {
printf("Error IMG_Load : %s", SDL_GetError());
return NULL;
}
texture = SDL_CreateTextureFromSurface(renderer, tmp);
SDL_FreeSurface(tmp);
if (NULL == texture) {
fprintf(stderr, "Error SDL_CreateTextureFromSurface : %s", SDL_GetError());
return NULL;
}
return texture;
}
int printPicture (SDL_Renderer *renderer, SDL_Texture *img, int x, int y) {
/* affiche une image sur le renderer */
if (NULL == img) {
return -1;
}
// on l'affiche à des coordonnées précises
if (x != -1 && y != -1) {
SDL_Point size;
SDL_QueryTexture(img, NULL, NULL, &size.x, &size.y);
SDL_Rect dst;
dst.x = x;
dst.y = y;
dst.h = size.x;
dst.w = size.y;
SDL_RenderCopy(renderer, img, NULL, &dst);
}
// l'image prend tout l'écran
else {
SDL_RenderCopy(renderer, img, NULL, NULL);
}
SDL_RenderPresent(renderer);
return 0;
}
#ifndef IMAGE_H_
#define IMAGE_H_
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
SDL_Texture *loadPicture (const char path[], SDL_Renderer *renderer);
int printPicture (SDL_Renderer *renderer, SDL_Texture *img, int x, int y);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <SDL2/SDL.h>
#include "windowMaker.h"
#include "image.h"
int main () {
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
if (0 == init(&window, &renderer, 1024, 780)) {
const struct timespec time[] = {{0, 500000000L}};
SDL_Texture *gauche = loadPicture("textures/gauche.png", renderer);
SDL_Texture *droit = loadPicture("textures/droit.png", renderer);
SDL_Texture *fond = loadPicture("textures/fond.jpg", renderer);
printPicture(renderer, fond, -1, -1);
printPicture(renderer, droit, 450, 650);
sleep(1);
printPicture(renderer, fond, -1, -1);
printPicture(renderer, gauche, 450, 650);
sleep(1);
printPicture(renderer, fond, -1, -1);
printPicture(renderer, droit, 450, 650);
for (int i=0; i<10; i++) {
printPicture(renderer, fond, -1, -1);
printPicture(renderer, droit, 450 + 5 * i, 650 - 5 * i);
nanosleep(time, NULL);
}
for (int i=0; i<6; i++) {
SDL_SetTextureAlphaMod(droit, 250 - 50 * i);
printPicture(renderer, fond, -1, -1);
printPicture(renderer, droit, 500, 600);
nanosleep(time, NULL);
}
sleep(1);
SDL_DestroyTexture(droit);
SDL_DestroyTexture(gauche);
SDL_DestroyTexture(fond);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include "windowMaker.h"
int main () {
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
if (0 == init(&window, &renderer, 1024, 780)) {
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.h = 1024;
rect.w = 780;
int i = 0;
Uint8 a = 255;
Uint8 r = 0;
Uint8 g = 0;
Uint8 b = 0;
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
while (i < 5) {
rect.x = 250 + 100 * i;
rect.y = 150 + 100 * i;
rect.h = 200 - 20 * i;
rect.w = 200 - 20 * i;
b += 50;
SDL_SetRenderDrawColor(renderer, r, g, b, a);
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
sleep(1);
i++;
}
}
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