commit c550f80b3a20d5436c03c14509a35adf9f1f0b92 Author: dukantic Date: Sun May 24 15:59:53 2026 +0200 start diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dc3bcad --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +CC := gcc +CFLAGS := -Wall -Wextra -g -fsanitize=address,undefined $(shell sdl2-config --cflags) +LDFLAGS := $(shell sdl2-config --libs) +TARGET := main + +SRC_DIR := src +BLD_DIR := build + +SRCS := $(filter-out $(SRC_DIR)/main.c, $(wildcard $(SRC_DIR)/*.c)) +OBJS := $(patsubst $(SRC_DIR)/%.c, $(BLD_DIR)/%.o, $(SRCS)) + +.PHONY: all clean fclean re + +all: $(BLD_DIR) $(TARGET) + +$(BLD_DIR): + mkdir -p $(BLD_DIR) + +$(TARGET): $(OBJS) $(SRC_DIR)/main.c + $(CC) $(CFLAGS) $(SRC_DIR)/main.c $(OBJS) -o $(TARGET) $(LDFLAGS) + +$(BLD_DIR)/%.o: $(SRC_DIR)/%.c | $(BLD_DIR) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -rf $(BLD_DIR) + +fclean: clean + rm -f $(TARGET) + +re: fclean all diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..28f956d --- /dev/null +++ b/src/main.c @@ -0,0 +1,71 @@ +#include "utils.h" +#include +#include +#include +#include + +#define SEED (42) +#define WIDTH (800) +#define HEIGHT (600) + +t_flags process_args(int argc, char **argv) { + t_flags output_flags = {0}; + if (argc <= 1) + return output_flags; + if (argv[1][0] != '-') + return output_flags; + + char *flags = argv[1]; + int i = 1; + char c = flags[i]; + while (c) { + if (c == 'g') + output_flags.graphical = 1; + if (c == 'm') + output_flags.multithread = 1; + if (c == 'o') + output_flags.opti = 1; + c = flags[++i]; + } + return output_flags; +} + +int main(int argc, char *argv[]) { + t_flags flags = process_args(argc, argv); + if (flags.graphical) { + srand(SEED); + + SDL_Init(SDL_INIT_VIDEO); + + SDL_Window *win = SDL_CreateWindow("pixels", 0, 0, WIDTH, HEIGHT, 0); + SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); + + SDL_Texture *tex = + SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT); + + uint32_t pixels[HEIGHT][WIDTH]; + for (int y = 0; y < HEIGHT; y++) + for (int x = 0; x < WIDTH; x++) + pixels[y][x] = 0xFFFFFF00; + int running = 1; + SDL_Event e; + while (running) { + while (SDL_PollEvent(&e)) + if (e.type == SDL_QUIT) + running = 0; + + // Envoie la matrice à la texture + SDL_UpdateTexture(tex, NULL, pixels, WIDTH * sizeof(uint32_t)); + + SDL_RenderClear(ren); + SDL_RenderCopy(ren, tex, NULL, NULL); + SDL_RenderPresent(ren); + } + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + SDL_Quit(); + } + return EXIT_SUCCESS; +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..c8901ad --- /dev/null +++ b/src/utils.h @@ -0,0 +1,12 @@ +#ifndef UTILS_H +#define UTILS_H + +typedef struct { + int graphical; + int multithread; + int opti; +} t_flags; + +t_flags process_args(int argc, char *argv[]); + +#endif // !UTILS_H