From 32eeaf97694700b91ea798a222468b4e9ab6e216 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Wed, 6 May 2026 11:13:06 -0400 Subject: [PATCH] Show the FPS readout in the top right --- Makefile | 4 ++-- src/sdl3-gametest.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c1c5a11..6516fc1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -SDLFLAGS_CC:=$(shell pkg-config sdl3 --cflags) $(shell pkg-config sdl3-image --cflags) $(shell pkg-config sdl3game --cflags) $(shell pkg-config akerror --cflags) -SDLFLAGS_LD:=$(shell pkg-config sdl3 --libs) $(shell pkg-config sdl3-mixer --libs) $(shell pkg-config sdl3-image --libs) $(shell pkg-config sdl3game --libs) $(shell pkg-config akerror --libs) -lasound +SDLFLAGS_CC:=$(shell pkg-config sdl3 --cflags) $(shell pkg-config sdl3-ttf --cflags) $(shell pkg-config sdl3-image --cflags) $(shell pkg-config sdl3game --cflags) $(shell pkg-config akerror --cflags) +SDLFLAGS_LD:=$(shell pkg-config sdl3 --libs) $(shell pkg-config sdl3-ttf --libs) $(shell pkg-config sdl3-mixer --libs) $(shell pkg-config sdl3-image --libs) $(shell pkg-config sdl3game --libs) $(shell pkg-config akerror --libs) -lasound CC:=$(shell which gcc) LD:=$(shell which ld) diff --git a/src/sdl3-gametest.c b/src/sdl3-gametest.c index dc99203..7219535 100644 --- a/src/sdl3-gametest.c +++ b/src/sdl3-gametest.c @@ -16,6 +16,7 @@ #include #include #include +#include int numsprites = 8; char *spritepaths[] = { @@ -145,6 +146,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) controlmap->controls[5].key = SDLK_M; controlmap->controls[5].event_on = SDL_EVENT_KEY_DOWN; controlmap->controls[5].handler_on = &music_toggle; + + CATCH(errctx, text_loadFont("C64Pro", "assets/C64_Pro-STYLE.ttf", 18)); } CLEANUP { } PROCESS(errctx) { @@ -180,8 +183,11 @@ SDL_AppResult SDL_AppIterate(void *appstate) //b2Vec2 position; int i = 0; iterator opflags; + char fpsText[32]; PREPARE_ERROR(errctx); + + GAME_updateFPS(); BITMASK_CLEAR(opflags.flags); BITMASK_ADD(opflags.flags, ITERATOR_OP_UPDATE); @@ -200,7 +206,28 @@ SDL_AppResult SDL_AppIterate(void *appstate) return SDL_APP_FAILURE; } FINISH_NORETURN(errctx); } - SDL_RenderPresent(renderer); + ATTEMPT { + memset((char *)&fpsText, 0x00, 32); + snprintf((char *)&fpsText, 31, "FPS : %d", game.fps); + CATCH(errctx, text_renderTextAt( + SDL_GetPointerProperty( + REGISTRY_FONT, + "C64Pro", + NULL), + (char *)&fpsText, + (SDL_Color){255, 255, 255, 255}, + 0, + 450, + 10) + ); + } CLEANUP { + SDL_RenderPresent(renderer); + } PROCESS(errctx) { + } HANDLE_DEFAULT(errctx) { + LOG_ERROR(errctx); + return SDL_APP_FAILURE; + } FINISH_NORETURN(errctx); + return SDL_APP_CONTINUE; }