From 059ccf41b65eccb275c5a22961e581ce3564ca16 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 2 Sep 2025 23:01:15 -0500 Subject: [PATCH] draw text. --- src/display/display.c | 9 ++-- src/display/scene/overworld/sceneoverworld.c | 21 ++------- src/display/ui/CMakeLists.txt | 1 + src/display/ui/ui.c | 49 ++++++++++++++++++++ src/display/ui/ui.h | 17 +++++++ 5 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 src/display/ui/ui.c create mode 100644 src/display/ui/ui.h diff --git a/src/display/display.c b/src/display/display.c index be553a4..ba75624 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -10,7 +10,7 @@ #include "display/framebuffer/framebuffer.h" #include "display/scene/scenemanager.h" #include "display/spritebatch/spritebatch.h" -#include "display/ui/rendertext.h" +#include "display/ui/ui.h" #include "display/mesh/quad.h" display_t DISPLAY; @@ -62,7 +62,7 @@ errorret_t displayInit(void) { quadInit(); frameBufferInitBackbuffer(); spriteBatchInit(); - errorChain(renderTextInit()); + errorChain(uiInit()); sceneManagerInit(); errorOk(); @@ -101,7 +101,10 @@ errorret_t displayUpdate(void) { ); sceneManagerUpdate(); + uiUpdate(); + sceneManagerRender(); + uiRender(); #if DISPLAY_SDL2 SDL_GL_SwapWindow(DISPLAY.window); @@ -118,7 +121,7 @@ errorret_t displayUpdate(void) { errorret_t displayDispose(void) { sceneManagerDispose(); - renderTextDispose(); + uiDispose(); spriteBatchDispose(); #if DISPLAY_SDL2 diff --git a/src/display/scene/overworld/sceneoverworld.c b/src/display/scene/overworld/sceneoverworld.c index 7337e51..07407b9 100644 --- a/src/display/scene/overworld/sceneoverworld.c +++ b/src/display/scene/overworld/sceneoverworld.c @@ -16,28 +16,16 @@ camera_t SCENE_OVERWORLD_CAMERA; asset_t *testAsset; +ref_t testAssetRef; void sceneOverworldInit(void) { cameraInit(&SCENE_OVERWORLD_CAMERA); - // glm_vec3_copy((vec3){32.0f, 32.0f, 32.0f}, SCENE_OVERWORLD_CAMERA.lookat.position); - - SCENE_OVERWORLD_CAMERA.projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC; - SCENE_OVERWORLD_CAMERA.orthographic.left = 0.0f; - SCENE_OVERWORLD_CAMERA.orthographic.right = 128.0f; - SCENE_OVERWORLD_CAMERA.orthographic.top = 0.0f; - SCENE_OVERWORLD_CAMERA.orthographic.bottom = 72.0f; - SCENE_OVERWORLD_CAMERA.nearClip = -1.0f; - SCENE_OVERWORLD_CAMERA.farClip = 1000.0f; - - SCENE_OVERWORLD_CAMERA.viewType = CAMERA_VIEW_TYPE_MATRIX; - glm_mat4_identity(SCENE_OVERWORLD_CAMERA.view); + glm_vec3_copy((vec3){32.0f, 32.0f, 32.0f}, SCENE_OVERWORLD_CAMERA.lookat.position); scene_t *scene = &SCENE_MANAGER_SCENES[SCENE_TYPE_OVERWORLD]; scene->flags |= SCENE_FLAG_ACTIVE | SCENE_FLAG_VISIBLE; - assetManagerGetAsset("entities.dpi", &testAsset); - ref_t lock = assetLock(testAsset); - assetLoad(testAsset); + assetManagerLoadAsset("entities.dpi", &testAsset, &testAssetRef); } void sceneOverworldUpdate(void) { @@ -51,7 +39,7 @@ void sceneOverworldRender(void) { // Draw entities // Draw overlay layer. - renderTextDraw(0.0f, 0.0f, "Hello World", 0xFF, 0xFF, 0xFF); + // renderTextDraw(0.0f, 0.0f, "Hello World", 0xFF, 0xFF, 0xFF); // spriteBatchPush( // &testAsset->paletteImage.texture, @@ -66,4 +54,5 @@ void sceneOverworldRender(void) { void sceneOverworldDispose(void) { // Dispose of the overworld scene. + if(testAsset) assetUnlock(testAsset, testAssetRef); } diff --git a/src/display/ui/CMakeLists.txt b/src/display/ui/CMakeLists.txt index 7dd25c4..1b0ffad 100644 --- a/src/display/ui/CMakeLists.txt +++ b/src/display/ui/CMakeLists.txt @@ -7,4 +7,5 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE rendertext.c + ui.c ) \ No newline at end of file diff --git a/src/display/ui/ui.c b/src/display/ui/ui.c new file mode 100644 index 0000000..ae9ccf5 --- /dev/null +++ b/src/display/ui/ui.c @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "ui.h" +#include "rendertext.h" +#include "display/framebuffer/framebuffer.h" + +camera_t UI_CAMERA; + +errorret_t uiInit(void) { + errorChain(renderTextInit()); + + cameraInit(&UI_CAMERA); + UI_CAMERA.projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC; + + UI_CAMERA.orthographic.left = 0.0f; + UI_CAMERA.orthographic.top = 0.0f; + UI_CAMERA.orthographic.right = frameBufferGetWidth(&FRAMEBUFFER_BACKBUFFER); + UI_CAMERA.orthographic.bottom = frameBufferGetHeight(&FRAMEBUFFER_BACKBUFFER); + UI_CAMERA.nearClip = -1.0f; + UI_CAMERA.farClip = 1.0f; + + UI_CAMERA.viewType = CAMERA_VIEW_TYPE_MATRIX; + glm_mat4_identity(UI_CAMERA.view); + + errorOk(); +} + +void uiUpdate(void) { +} + +void uiRender(void) { + UI_CAMERA.orthographic.right = frameBufferGetWidth(FRAMEBUFFER_BOUND); + UI_CAMERA.orthographic.bottom = frameBufferGetHeight(FRAMEBUFFER_BOUND); + + cameraPushMatrix(&UI_CAMERA); + + renderTextDraw(10.0f, 10.0f, "Dusk Engine UI", 0xFF, 0xFF, 0xFF); + + cameraPopMatrix(); +} + +void uiDispose(void) { + renderTextDispose(); +} \ No newline at end of file diff --git a/src/display/ui/ui.h b/src/display/ui/ui.h new file mode 100644 index 0000000..6b01e89 --- /dev/null +++ b/src/display/ui/ui.h @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "error/error.h" +#include "display/camera.h" + +extern camera_t UI_CAMERA; + +errorret_t uiInit(void); +void uiUpdate(void); +void uiRender(void); +void uiDispose(void); \ No newline at end of file