Render is color not uint8_t

This commit is contained in:
2025-09-11 22:20:21 -05:00
parent c8f8170ec2
commit 268e9ffefd
12 changed files with 64 additions and 53 deletions

View File

@@ -13,5 +13,4 @@ bind enter accept;
bind q cancel; bind q cancel;
bind esc quit; bind esc quit;
alias test "echo \"test\""; bind f1 togglefps;
bind p test;

View File

@@ -34,10 +34,7 @@ void quadBuffer(
const float_t minY, const float_t minY,
const float_t maxX, const float_t maxX,
const float_t maxY, const float_t maxY,
const uint8_t r, const color_t color,
const uint8_t g,
const uint8_t b,
const uint8_t a,
const float_t u0, const float_t u0,
const float_t v0, const float_t v0,
const float_t u1, const float_t u1,
@@ -48,34 +45,34 @@ void quadBuffer(
// First triangle // First triangle
vertices[0] = (meshvertex_t) { vertices[0] = (meshvertex_t) {
{ r, g, b, a }, // Color { color.r, color.g, color.b, color.a }, // Color
{ u0, v0 }, // UV { u0, v0 }, // UV
{ minX, minY, z } // Position { minX, minY, z } // Position
}; };
vertices[1] = (meshvertex_t) { vertices[1] = (meshvertex_t) {
{ r, g, b, a }, // Color { color.r, color.g, color.b, color.a }, // Color
{ u1, v0 }, // UV { u1, v0 }, // UV
{ maxX, minY, z } // Position { maxX, minY, z } // Position
}; };
vertices[2] = (meshvertex_t) { vertices[2] = (meshvertex_t) {
{ r, g, b, a }, // Color { color.r, color.g, color.b, color.a }, // Color
{ u1, v1 }, // UV { u1, v1 }, // UV
{ maxX, maxY, z } // Position { maxX, maxY, z } // Position
}; };
// Second triangle // Second triangle
vertices[3] = (meshvertex_t) { vertices[3] = (meshvertex_t) {
{ r, g, b, a }, // Color { color.r, color.g, color.b, color.a }, // Color
{ u0, v0 }, // UV { u0, v0 }, // UV
{ minX, minY, z } // Position { minX, minY, z } // Position
}; };
vertices[4] = (meshvertex_t) { vertices[4] = (meshvertex_t) {
{ r, g, b, a }, // Color { color.r, color.g, color.b, color.a }, // Color
{ u1, v1 }, // UV { u1, v1 }, // UV
{ maxX, maxY, z } // Position { maxX, maxY, z } // Position
}; };
vertices[5] = (meshvertex_t) { vertices[5] = (meshvertex_t) {
{ r, g, b, a }, // Color { color.r, color.g, color.b, color.a }, // Color
{ u0, v1 }, // UV { u0, v1 }, // UV
{ minX, maxY, z } // Position { minX, maxY, z } // Position
}; };

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "mesh.h" #include "mesh.h"
#include "display/color.h"
#define QUAD_VERTEX_COUNT 6 #define QUAD_VERTEX_COUNT 6
#define QUAD_PRIMITIVE_TYPE MESH_PRIMITIVE_TRIANGLES #define QUAD_PRIMITIVE_TYPE MESH_PRIMITIVE_TRIANGLES
@@ -42,10 +43,7 @@ void quadBuffer(
const float_t minY, const float_t minY,
const float_t maxX, const float_t maxX,
const float_t maxY, const float_t maxY,
const uint8_t r, const color_t color,
const uint8_t g,
const uint8_t b,
const uint8_t a,
const float_t u0, const float_t u0,
const float_t v0, const float_t v0,
const float_t u1, const float_t u1,

View File

@@ -30,10 +30,7 @@ void spriteBatchPush(
const float_t minY, const float_t minY,
const float_t maxX, const float_t maxX,
const float_t maxY, const float_t maxY,
const uint8_t r, const color_t color,
const uint8_t g,
const uint8_t b,
const uint8_t a,
const float_t u0, const float_t u0,
const float_t v0, const float_t v0,
const float_t u1, const float_t u1,
@@ -51,7 +48,7 @@ void spriteBatchPush(
quadBuffer( quadBuffer(
&SPRITEBATCH.vertices[SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT], &SPRITEBATCH.vertices[SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT],
minX, minY, maxX, maxY, minX, minY, maxX, maxY,
r, g, b, a, color,
u0, v0, u1, v1 u0, v0, u1, v1
); );

View File

@@ -42,10 +42,7 @@ void spriteBatchInit();
* @param minY The minimum y coordinate of the sprite. * @param minY The minimum y coordinate of the sprite.
* @param maxX The maximum x coordinate of the sprite. * @param maxX The maximum x coordinate of the sprite.
* @param maxY The maximum y coordinate of the sprite. * @param maxY The maximum y coordinate of the sprite.
* @param r The red color component of the sprite. * @param color The color to tint the sprite with.
* @param g The green color component of the sprite.
* @param b The blue color component of the sprite.
* @param a The alpha component of the sprite.
* @param u0 The texture coordinate for the top-left corner of the sprite. * @param u0 The texture coordinate for the top-left corner of the sprite.
* @param v0 The texture coordinate for the top-left corner of the sprite. * @param v0 The texture coordinate for the top-left corner of the sprite.
* @param u1 The texture coordinate for the bottom-right corner of the sprite. * @param u1 The texture coordinate for the bottom-right corner of the sprite.
@@ -57,10 +54,7 @@ void spriteBatchPush(
const float_t minY, const float_t minY,
const float_t maxX, const float_t maxX,
const float_t maxY, const float_t maxY,
const uint8_t r, const color_t color,
const uint8_t g,
const uint8_t b,
const uint8_t a,
const float_t u0, const float_t u0,
const float_t v0, const float_t v0,
const float_t u1, const float_t u1,

View File

@@ -8,5 +8,6 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
uitext.c uitext.c
ui.c ui.c
uifps.c
uiconsole.c uiconsole.c
) )

View File

@@ -10,6 +10,7 @@
#include "display/framebuffer/framebuffer.h" #include "display/framebuffer/framebuffer.h"
#include "display/spritebatch/spritebatch.h" #include "display/spritebatch/spritebatch.h"
#include "uiconsole.h" #include "uiconsole.h"
#include "uifps.h"
#include "util/memory.h" #include "util/memory.h"
ui_t UI; ui_t UI;
@@ -51,6 +52,7 @@ void uiRender(void) {
cameraPushMatrix(&UI.camera); cameraPushMatrix(&UI.camera);
uiConsoleRender(); uiConsoleRender();
uiFPSRender();
spriteBatchFlush(); spriteBatchFlush();
cameraPopMatrix(); cameraPopMatrix();

View File

@@ -20,10 +20,7 @@ void uiConsoleRender(void) {
i++; i++;
continue; continue;
} }
uiTextDraw( uiTextDraw(0, i * UI_TEXT_TILE_HEIGHT, line, COLOR_WHITE);
0, i * UI_TEXT_TILE_HEIGHT, line,
0xFF, 0xFF, 0xFF
);
i++; i++;
} while(i < CONSOLE_HISTORY_MAX); } while(i < CONSOLE_HISTORY_MAX);
} }

27
src/display/ui/uifps.c Normal file
View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "uifps.h"
#include "display/ui/uitext.h"
#include "time/time.h"
void uiFPSRender(void) {
float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f;
char_t buffer[64];
snprintf(
buffer,
sizeof(buffer),
"FPS: %d",
(int32_t)fps
);
color_t color = fps >= 50.0f ? COLOR_GREEN :
(fps >= 30.0f ? COLOR_YELLOW : COLOR_RED);
uiTextDraw(0, 0, buffer, color);
}

11
src/display/ui/uifps.h Normal file
View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
void uiFPSRender(void);

View File

@@ -32,9 +32,7 @@ void uiTextDrawChar(
const float_t x, const float_t x,
const float_t y, const float_t y,
const char_t c, const char_t c,
const uint8_t r, const color_t color
const uint8_t g,
const uint8_t b
) { ) {
int32_t tileIndex = (int32_t)(c) - UI_TEXT_CHAR_START; int32_t tileIndex = (int32_t)(c) - UI_TEXT_CHAR_START;
if(tileIndex < 0 || tileIndex >= UI_TEXT_TILE_COUNT) { if(tileIndex < 0 || tileIndex >= UI_TEXT_TILE_COUNT) {
@@ -55,7 +53,7 @@ void uiTextDrawChar(
&UI_TEXT.asset->alphaImage.texture, &UI_TEXT.asset->alphaImage.texture,
x, y, x, y,
x + UI_TEXT_TILE_WIDTH, y + UI_TEXT_TILE_HEIGHT, x + UI_TEXT_TILE_WIDTH, y + UI_TEXT_TILE_HEIGHT,
r, g, b, 0xFF, color,
(tileX * UI_TEXT_TILE_WIDTH) / w, (tileX * UI_TEXT_TILE_WIDTH) / w,
(tileY * UI_TEXT_TILE_HEIGHT) / h, (tileY * UI_TEXT_TILE_HEIGHT) / h,
((tileX + 1) * UI_TEXT_TILE_WIDTH) / w, ((tileX + 1) * UI_TEXT_TILE_WIDTH) / w,
@@ -67,9 +65,7 @@ void uiTextDraw(
const float_t x, const float_t x,
const float_t y, const float_t y,
const char_t *text, const char_t *text,
const uint8_t r, const color_t color
const uint8_t g,
const uint8_t b
) { ) {
assertNotNull(text, "Text cannot be NULL"); assertNotNull(text, "Text cannot be NULL");
@@ -90,7 +86,7 @@ void uiTextDraw(
continue; continue;
} }
uiTextDrawChar(posX, posY, c, r, g, b); uiTextDrawChar(posX, posY, c, color);
posX += UI_TEXT_TILE_WIDTH; posX += UI_TEXT_TILE_WIDTH;
} }
} }

View File

@@ -35,17 +35,13 @@ errorret_t uiTextInit(void);
* @param x The x-coordinate to draw the character at. * @param x The x-coordinate to draw the character at.
* @param y The y-coordinate to draw the character at. * @param y The y-coordinate to draw the character at.
* @param c The character to draw. * @param c The character to draw.
* @param r The red component of the color (0-255). * @param color The color to draw the character in.
* @param g The green component of the color (0-255).
* @param b The blue component of the color (0-255).
*/ */
void uiTextDrawChar( void uiTextDrawChar(
const float_t x, const float_t x,
const float_t y, const float_t y,
const char_t c, const char_t c,
const uint8_t r, const color_t color
const uint8_t g,
const uint8_t b
); );
/** /**
@@ -54,17 +50,13 @@ void uiTextDrawChar(
* @param x The x-coordinate to draw the text at. * @param x The x-coordinate to draw the text at.
* @param y The y-coordinate to draw the text at. * @param y The y-coordinate to draw the text at.
* @param text The null-terminated string of text to draw. * @param text The null-terminated string of text to draw.
* @param r The red component of the color (0-255). * @param color The color to draw the text in.
* @param g The green component of the color (0-255).
* @param b The blue component of the color (0-255).
*/ */
void uiTextDraw( void uiTextDraw(
const float_t x, const float_t x,
const float_t y, const float_t y,
const char_t *text, const char_t *text,
const uint8_t r, const color_t color
const uint8_t g,
const uint8_t b
); );
/** /**