This commit is contained in:
2026-05-24 15:59:53 +02:00
commit c550f80b3a
3 changed files with 114 additions and 0 deletions

71
src/main.c Normal file
View File

@@ -0,0 +1,71 @@
#include "utils.h"
#include <SDL2/SDL.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#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;
}

12
src/utils.h Normal file
View File

@@ -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