Do some work on the CPU, assembler still needs update

This commit is contained in:
2025-02-02 21:48:35 +01:00
parent b7e5e2aa35
commit 0a0f953f09
15 changed files with 1473 additions and 71 deletions

49
util/font.c Normal file
View File

@@ -0,0 +1,49 @@
//
// Created by bruno on 1.2.2025.
//
#include "font.h"
BitmapFont
prepText(SDL_Renderer *renderer, unsigned char pxSize, const char *file, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
const unsigned char ptSize = floor(pxSize * 0.75);
TTF_Font *gFont = TTF_OpenFont(file, ptSize);
BitmapFont out;
out.size = pxSize;
out.color = (SDL_Color) {r, g, b, a};
unsigned char i = 0;
SDL_Surface *fontTempSurf = NULL;
do {
char tmpOut[2] = {i, 0};
fontTempSurf = TTF_RenderText_Solid(gFont, tmpOut, out.color);
SDL_Rect dstRect;
dstRect.x = 0;
dstRect.y = 0;
dstRect.w = pxSize;
dstRect.h = pxSize;
out.texture[i] = SDL_CreateTextureFromSurface(renderer, fontTempSurf);
i++;
} while (i < 255);
SDL_FreeSurface(fontTempSurf);
TTF_CloseFont(gFont);
return out;
}
void renderText(SDL_Renderer *renderer, BitmapFont font, char *string, uint16_t x, uint16_t y) {
SDL_Rect charRect;
charRect.x = 0;
charRect.y = 0;
charRect.w = font.size;
charRect.h = font.size;
SDL_Rect outRect = charRect;
outRect.x = x;
outRect.y = y;
while (*string) {
SDL_RenderCopy(renderer, font.texture[*string], &charRect, &outRect);
outRect.x += charRect.w + 1;
string++;
}
}