diff options
| author | Arslaan Pathan <[email protected]> | 2026-04-06 21:59:31 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-04-06 21:59:31 +1200 |
| commit | 7fba8447b9ce0c74808b943d9fe7f56b9663c4cf (patch) | |
| tree | a51c60db357177613d7d9dea908c0b58d4b6095b | |
| parent | 1f2d8ff3c2be1ad2399f9233de417c9d0fa779b8 (diff) | |
| download | saffron-7fba8447b9ce0c74808b943d9fe7f56b9663c4cf.tar.xz saffron-7fba8447b9ce0c74808b943d9fe7f56b9663c4cf.zip | |
Meson setup, SDL tests
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | meson.build | 7 | ||||
| -rw-r--r-- | src/main.c | 48 |
3 files changed, 56 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..ce5edc9 --- /dev/null +++ b/meson.build @@ -0,0 +1,7 @@ +project('saffron', 'c') + +deps = [] +deps += dependency('sdl3', static: true) +deps += dependency('sdl3-ttf', static: true) + +executable('saffron', 'src/main.c', dependencies: deps) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f286a0a --- /dev/null +++ b/src/main.c @@ -0,0 +1,48 @@ +#include <SDL3/SDL.h> +#include <SDL3/SDL_main.h> +#include <SDL3_ttf/SDL_ttf.h> + +int main(int argc, char *argv[]) { + SDL_Init(SDL_INIT_VIDEO); + TTF_Init(); + + SDL_Window *window = SDL_CreateWindow("Saffron", 800, 600, 0); + SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); + + TTF_Font *font = TTF_OpenFont("/usr/share/fonts/maple-mono/MapleMonoNL-Regular.ttf", 20); // "works on my machine" - Arslaan, 2026 + + bool running = true; + SDL_Event event; + SDL_FRect rect; + rect.x = rect.y = 100; + rect.w = rect.h = 100; + + SDL_FRect text_rect = {200, 200, 0, 0}; + SDL_Color white = {255, 255, 255, 255}; + SDL_Surface *surface = TTF_RenderText_Blended(font, "Hello Saffron!", 0, white); + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_DestroySurface(surface); + SDL_GetTextureSize(texture, &text_rect.w, &text_rect.h); + + while (running) { + while (SDL_PollEvent(&event)) { + if (event.type == SDL_EVENT_QUIT) { + running = false; + } + } + + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); + SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); + SDL_RenderFillRect(renderer, &rect); + SDL_RenderTexture(renderer, texture, NULL, &text_rect); + SDL_RenderPresent(renderer); + } + + TTF_CloseFont(font); + TTF_Quit(); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + return 0; +} |
