This commit is contained in:
2025-10-01 17:59:41 -05:00
parent a734ecaa10
commit 83243ba32f
10 changed files with 149 additions and 8 deletions

View File

@@ -11,6 +11,10 @@
#include "display/framebuffer/framebuffer.h" #include "display/framebuffer/framebuffer.h"
void cameraInit(camera_t *camera) { void cameraInit(camera_t *camera) {
cameraInitPerspective(camera);
}
void cameraInitPerspective(camera_t *camera) {
assertNotNull(camera, "Not a camera component"); assertNotNull(camera, "Not a camera component");
camera->projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE; camera->projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE;
@@ -24,6 +28,22 @@ void cameraInit(camera_t *camera) {
glm_vec3_copy((vec3){ 0.0f, 0.0f, 0.0f }, camera->lookat.target); glm_vec3_copy((vec3){ 0.0f, 0.0f, 0.0f }, camera->lookat.target);
} }
void cameraInitOrthographic(camera_t *camera) {
assertNotNull(camera, "Not a camera component");
camera->projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC;
camera->orthographic.left = 0.0f;
camera->orthographic.right = (float_t)frameBufferGetWidth(FRAMEBUFFER_BOUND);
camera->orthographic.bottom = 0.0f;
camera->orthographic.top = (float_t)frameBufferGetHeight(FRAMEBUFFER_BOUND);
camera->nearClip = -1.0f;
camera->farClip = 1.0f;
camera->viewType = CAMERA_VIEW_TYPE_2D;
glm_vec3_copy((vec3){ 0.0f, 0.0f, 0.0f }, camera->_2d.position);
camera->_2d.zoom = 1.0f;
}
void cameraPushMatrix(camera_t *camera) { void cameraPushMatrix(camera_t *camera) {
assertNotNull(camera, "Not a camera component"); assertNotNull(camera, "Not a camera component");

View File

@@ -59,10 +59,20 @@ typedef struct {
} camera_t; } camera_t;
/** /**
* Initializes a camera to default values. * Initializes a camera to default values. This calls cameraInitPerspective.
*/ */
void cameraInit(camera_t *camera); void cameraInit(camera_t *camera);
/**
* Initializes a camera for perspective projection.
*/
void cameraInitPerspective(camera_t *camera);
/**
* Initializes a camera for orthographic projection.
*/
void cameraInitOrthographic(camera_t *camera);
/** /**
* Pushes the camera's view matrix onto the matrix stack. * Pushes the camera's view matrix onto the matrix stack.
* *

View File

@@ -63,6 +63,11 @@ errorret_t displayInit(void) {
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
#endif #endif
// Commands
// Variables
consoleRegVar("fps", "0", NULL);
quadInit(); quadInit();
frameBufferInitBackbuffer(); frameBufferInitBackbuffer();
spriteBatchInit(); spriteBatchInit();

View File

@@ -9,4 +9,5 @@ target_sources(${DUSK_TARGET_NAME}
game.c game.c
) )
# Subdirs # Subdirs
add_subdirectory(ui)

View File

@@ -6,19 +6,22 @@
*/ */
#include "game/game.h" #include "game/game.h"
#include "game/minesweeper/ui/ui.h"
errorret_t gameInit(void) { errorret_t gameInit(void) {
uiInit();
errorOk(); errorOk();
} }
void gameUpdate(void) { void gameUpdate(void) {
} }
void gameRender(void) { void gameRender(void) {
uiRender();
} }
void gameDispose(void) { void gameDispose(void) {
uiDispose();
} }

View File

@@ -0,0 +1,12 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
ui.c
)
# Subdirs

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "ui.h"
#include "ui/uifps.h"
#include "ui/uiconsole.h"
#include "display/framebuffer/framebuffer.h"
#include "display/tileset/tileset_minogram.h"
ui_t UI;
void uiInit(void) {
cameraInitOrthographic(&UI.camera);
UI.minogramTileset = (tileset_t*)&TILESET_MINOGRAM;
assetManagerLoadAsset(
UI.minogramTileset->image,
&UI.minogramAsset,
&UI.minogramRef
);
}
void uiRender(void) {
int32_t w = frameBufferGetWidth(FRAMEBUFFER_BOUND);
int32_t h = frameBufferGetHeight(FRAMEBUFFER_BOUND);
UI.camera.orthographic.left = 0;
UI.camera.orthographic.right = w;
UI.camera.orthographic.bottom = h;
UI.camera.orthographic.top = 0;
cameraPushMatrix(&UI.camera);
uiFPSRender(UI.minogramTileset, &UI.minogramAsset->alphaImage.texture);
uiConsoleRender(UI.minogramTileset, &UI.minogramAsset->alphaImage.texture);
cameraPopMatrix();
}
void uiDispose(void) {
}

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#include "display/camera.h"
#include "asset/assetmanager.h"
#include "display/tileset.h"
typedef struct {
camera_t camera;
tileset_t *minogramTileset;
asset_t *minogramAsset;
ref_t minogramRef;
} ui_t;
extern ui_t UI;
/**
* Initializes the Minesweeper UI.
*/
void uiInit(void);
/**
* Renders the Minesweeper UI.
*/
void uiRender(void);
/**
* Disposes of the Minesweeper UI.
*/
void uiDispose(void);

View File

@@ -11,7 +11,6 @@
void uiConsoleRender(const tileset_t *tileset, texture_t *texture) { void uiConsoleRender(const tileset_t *tileset, texture_t *texture) {
if(!CONSOLE.visible) return; if(!CONSOLE.visible) return;
consolePrint("Test\n");
int32_t i = CONSOLE_HISTORY_MAX - 1; int32_t i = CONSOLE_HISTORY_MAX - 1;
char_t *line; char_t *line;

View File

@@ -10,6 +10,7 @@
#include "console/console.h" #include "console/console.h"
#include "util/string.h" #include "util/string.h"
#include "ui/uitext.h" #include "ui/uitext.h"
#include "display/framebuffer/framebuffer.h"
void uiFPSRender(const tileset_t *tileset, texture_t *texture) { void uiFPSRender(const tileset_t *tileset, texture_t *texture) {
if(stringCompare(consoleVarGet("fps")->value, "0") == 0) { if(stringCompare(consoleVarGet("fps")->value, "0") == 0) {
@@ -31,6 +32,11 @@ void uiFPSRender(const tileset_t *tileset, texture_t *texture) {
fps >= 30.0f ? COLOR_YELLOW : fps >= 30.0f ? COLOR_YELLOW :
COLOR_RED COLOR_RED
); );
uiTextDraw(0, 0, buffer, color, tileset, texture); int32_t w, h;
uiTextMeasure(buffer, tileset, &w, &h);
uiTextDraw(
frameBufferGetWidth(FRAMEBUFFER_BOUND) - w, 0,
buffer, color, tileset, texture
);
} }