From f15aad0c2ebe67acc9cea01e04078308141a0d44 Mon Sep 17 00:00:00 2001 From: tTh Date: Sat, 7 Sep 2024 15:36:26 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9couverte=20de=20SDL2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/SDL2/.gitignore | 1 + code/SDL2/Makefile | 4 ++++ code/SDL2/README.md | 11 +++++++++++ code/SDL2/strangebug.c | 40 ++++++++++++++++++++++++++++++++++++++++ code/SDL2/strangebug.md | 11 +++++++++++ 5 files changed, 67 insertions(+) create mode 100644 code/SDL2/.gitignore create mode 100644 code/SDL2/Makefile create mode 100644 code/SDL2/README.md create mode 100644 code/SDL2/strangebug.c create mode 100644 code/SDL2/strangebug.md diff --git a/code/SDL2/.gitignore b/code/SDL2/.gitignore new file mode 100644 index 0000000..43cb6d8 --- /dev/null +++ b/code/SDL2/.gitignore @@ -0,0 +1 @@ +strangebug diff --git a/code/SDL2/Makefile b/code/SDL2/Makefile new file mode 100644 index 0000000..23f8ed3 --- /dev/null +++ b/code/SDL2/Makefile @@ -0,0 +1,4 @@ + + +strangebug: strangebug.c Makefile + gcc -Wall $< -lSDL2 -o $@ diff --git a/code/SDL2/README.md b/code/SDL2/README.md new file mode 100644 index 0000000..7946a78 --- /dev/null +++ b/code/SDL2/README.md @@ -0,0 +1,11 @@ +# Simple DirectMedia Layer + + + +The *[Simple DirectMedia Layer](https://libsdl.org/) +is a cross-platform development library designed +to provide low level access to audio, keyboard, mouse, joystick, and +graphics hardware via OpenGL/Direct3D/Metal/Vulkan.* + +Paf, premier essai, [premier souci](strangebug.md) **:)** + diff --git a/code/SDL2/strangebug.c b/code/SDL2/strangebug.c new file mode 100644 index 0000000..02ef810 --- /dev/null +++ b/code/SDL2/strangebug.c @@ -0,0 +1,40 @@ +/* + * Strange Bug ? + */ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ +SDL_Window *win; +SDL_Renderer *rend; +int idx, idy; + +if(SDL_CreateWindowAndRenderer(256, 256, SDL_WINDOW_SHOWN, &win, &rend)) + { + fprintf(stderr, "Err SDL_CreateWindowAndRenderer : %s", SDL_GetError()); + exit(1); + } +SDL_SetRenderDrawColor(rend, 255, 0, 0, 0); +SDL_RenderClear(rend); +SDL_RenderPresent(rend); + +for (idx=0; idx<256; idx++) { + for (idy=0; idy<256; idy++) { + SDL_SetRenderDrawColor(rend, 127, idx, idy, 0); + SDL_RenderDrawPoint(rend, idx, idy); + } + SDL_RenderPresent(rend); + // SDL_Delay(50); /* Is the bug here ? */ + } +SDL_RenderPresent(rend); +sleep(30); + +SDL_DestroyRenderer(rend); +SDL_DestroyWindow(win); + +return 0; +} \ No newline at end of file diff --git a/code/SDL2/strangebug.md b/code/SDL2/strangebug.md new file mode 100644 index 0000000..9641c0c --- /dev/null +++ b/code/SDL2/strangebug.md @@ -0,0 +1,11 @@ +# `strangebug`, ou le bug étrange + +Pour mes premiers pas dans la sdl, j'ai voulu faire un gradient de couleur +dans une petite fenêtre, quelque chose de vraiment simple, me diriez-vous, +mais qui cache une chose étrange... + +Voici le [Code source](strangebug.c). Si vous décommentez la ligne +marquée, seul une colonne sur deux est correctement tracée... + +*Please explain*. +