Remove imgui for now.

Temporary implementation of SDL_TTF
This commit is contained in:
2026-09-27 18:31:29 -05:00
parent b8d2270996
commit 42c59530d3
281 changed files with 32 additions and 130359 deletions
+32 -4
View File
@@ -1,11 +1,11 @@
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_keyboard.h>
#include <SDL3/SDL_keycode.h>
#include <SDL3/SDL_log.h>
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
#include <SDL3/SDL.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_keyboard.h>
#include <SDL3/SDL_keycode.h>
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_video.h>
@@ -16,6 +16,11 @@
Game game;
Window window;
TTF_Font *font = nullptr;
SDL_Texture *font_texture = nullptr;
fs::path fontPath("Resources/Pixelzone-E4MV4.ttf");
void EditRooms() {
@@ -57,6 +62,9 @@ void EditRooms() {
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
SDL_Surface *text;
SDL_Color color = {255, 255, 255, SDL_ALPHA_OPAQUE};
if (SDL_Init(SDL_INIT_VIDEO) == false) {
SDL_Log("SDL could not initialize! SDL error: %s\n", SDL_GetError());
}
@@ -72,6 +80,16 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
return SDL_APP_FAILURE;
}
font = TTF_OpenFont(fs::absolute(fontPath).c_str(), 12.0f);
text = TTF_RenderText_Blended(font, "Hello World!", 0, color);
if (text) {
font_texture = SDL_CreateTextureFromSurface(window.GetRenderer(), text);
SDL_DestroySurface(text);
}
if (!font_texture) {
SDL_Log("Couldn't create text: %s\n", SDL_GetError());
return SDL_APP_FAILURE;
}
if (!game) {
game.Init();
@@ -114,6 +132,15 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
SDL_SetRenderDrawColor(window.GetRenderer(), 0, 0, 0, 255); // Set render draw color to black
SDL_RenderClear(window.GetRenderer()); // Clear the renderer
int w = 0, h = 0;
SDL_FRect dst;
const float scale = 4.0f;
/* Center the text and scale it up */
SDL_GetRenderOutputSize(window.GetRenderer(), &w, &h);
SDL_SetRenderScale(window.GetRenderer(), scale, scale);
SDL_GetTextureSize(font_texture, &dst.w, &dst.h);
SDL_RenderTexture(window.GetRenderer(), font_texture, NULL, &dst);
SDL_RenderPresent(window.GetRenderer()); // Render the screen
// game.Run();
@@ -125,6 +152,7 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
if (result == SDL_APP_SUCCESS) {
window.Close();
TTF_CloseFont(font);
SDL_Quit();
}
}