1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* this doesnt really test saffron's api right now
* because i need to actually implement stuff
* but its good refactor for now
*/
#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;
}
|