Draw FPS
This commit is contained in:
@@ -11,6 +11,10 @@
|
||||
#include "display/framebuffer/framebuffer.h"
|
||||
|
||||
void cameraInit(camera_t *camera) {
|
||||
cameraInitPerspective(camera);
|
||||
}
|
||||
|
||||
void cameraInitPerspective(camera_t *camera) {
|
||||
assertNotNull(camera, "Not a camera component");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
assertNotNull(camera, "Not a camera component");
|
||||
|
||||
|
@@ -59,10 +59,20 @@ typedef struct {
|
||||
} camera_t;
|
||||
|
||||
/**
|
||||
* Initializes a camera to default values.
|
||||
* Initializes a camera to default values. This calls cameraInitPerspective.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
@@ -63,6 +63,11 @@ errorret_t displayInit(void) {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
|
||||
// Commands
|
||||
|
||||
// Variables
|
||||
consoleRegVar("fps", "0", NULL);
|
||||
|
||||
quadInit();
|
||||
frameBufferInitBackbuffer();
|
||||
spriteBatchInit();
|
||||
|
@@ -9,4 +9,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
game.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
# Subdirs
|
||||
add_subdirectory(ui)
|
@@ -6,19 +6,22 @@
|
||||
*/
|
||||
|
||||
#include "game/game.h"
|
||||
#include "game/minesweeper/ui/ui.h"
|
||||
|
||||
errorret_t gameInit(void) {
|
||||
uiInit();
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void gameUpdate(void) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void gameRender(void) {
|
||||
|
||||
uiRender();
|
||||
}
|
||||
|
||||
void gameDispose(void) {
|
||||
|
||||
uiDispose();
|
||||
}
|
12
src/game/minesweeper/ui/CMakeLists.txt
Normal file
12
src/game/minesweeper/ui/CMakeLists.txt
Normal 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
|
48
src/game/minesweeper/ui/ui.c
Normal file
48
src/game/minesweeper/ui/ui.c
Normal 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) {
|
||||
|
||||
}
|
37
src/game/minesweeper/ui/ui.h
Normal file
37
src/game/minesweeper/ui/ui.h
Normal 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);
|
@@ -11,7 +11,6 @@
|
||||
|
||||
void uiConsoleRender(const tileset_t *tileset, texture_t *texture) {
|
||||
if(!CONSOLE.visible) return;
|
||||
consolePrint("Test\n");
|
||||
|
||||
int32_t i = CONSOLE_HISTORY_MAX - 1;
|
||||
char_t *line;
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "console/console.h"
|
||||
#include "util/string.h"
|
||||
#include "ui/uitext.h"
|
||||
#include "display/framebuffer/framebuffer.h"
|
||||
|
||||
void uiFPSRender(const tileset_t *tileset, texture_t *texture) {
|
||||
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 :
|
||||
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
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user