From 1c5e50cc4d40c4aadfd1fcec01273f5e27f74772 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 29 Mar 2026 10:15:22 -0500 Subject: [PATCH] Test text rendering --- assets/scene/minesweeper.lua | 17 +- assets/ui/minogram.dpt | Bin 8204 -> 0 bytes assets/ui/minogram.dtf | Bin 24 -> 24 bytes assets/ui/minogram.dtx | Bin 0 -> 32781 bytes src/dusk/asset/assettype.h | 26 +- src/dusk/asset/type/assettexture.c | 97 ++++--- src/dusk/asset/type/assettexture.h | 4 +- src/dusk/display/text/text.c | 10 +- tools/texture-creator.html | 417 +++++++++++++++++++++++++++++ tools/tileset-creator.html | 13 +- 10 files changed, 503 insertions(+), 81 deletions(-) delete mode 100644 assets/ui/minogram.dpt create mode 100644 assets/ui/minogram.dtx create mode 100644 tools/texture-creator.html diff --git a/assets/scene/minesweeper.lua b/assets/scene/minesweeper.lua index 61c14bf..7e31aa6 100644 --- a/assets/scene/minesweeper.lua +++ b/assets/scene/minesweeper.lua @@ -63,7 +63,7 @@ function cellDraw(x, y, type) slice = cellSliceDisabled end - spriteBatchPush(textureCell, + spriteBatchPush( x, y, x + tilesetCell.tileWidth, y + tilesetCell.tileHeight, colorWhite(), @@ -185,7 +185,8 @@ end function sceneRender() -- Update camera - camera.bottom = screenGetHeight() + camera.bottom = 0 + camera.top = screenGetHeight() camera.right = screenGetWidth() shaderBind(SHADER_UNLIT) @@ -194,11 +195,13 @@ function sceneRender() view = cameraGetViewMatrix(camera) shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view) - spriteBatchPush( - x, y, - x + 32, y + 32, - colorWhite() - ) + textDraw(10, 10, "Hello World\nHow are you?") + + -- spriteBatchPush( + -- x, y, + -- x + 32, y + 32, + -- colorWhite() + -- ) -- Update mouse position -- if INPUT_POINTER then diff --git a/assets/ui/minogram.dpt b/assets/ui/minogram.dpt deleted file mode 100644 index 688283de9173fb5745440967fd1396732f9a15fd..0000000000000000000000000000000000000000 GIT binary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460bd8f8d9fcdb33 100644 GIT binary patch literal 24 dcmZ<>absX(;9?K}k_rqg3=9kowhRmkb^se+0t5g6 literal 24 fcmZ<>absX(;9_88NMm4PU}0cjaIj}!P_O|29!~-{ diff --git a/assets/ui/minogram.dtx b/assets/ui/minogram.dtx new file mode 100644 index 0000000000000000000000000000000000000000..af45a07d1c8c54d0a776f4b3e919d496e4475320 GIT binary patch literal 32781 zcmeH|U2Y^d41}GV1`fI| zjU!z(esVl8eea|8EZV5=Xx?Xjw)VTd9_{bsl}^*?C8IArEq|I0p@sP7Qjt^2s@Nxk_igd#+LY{H)11W~SoG zyADtE%vCizt=z9{9`BPU4t90t`>d+=KKE0HC(?rse>CQNaUJgQ8tpE~?x6No?T2rX zMorE!YtL47&Li^(y_>-uiCwE2|?7bib=Jo4o6r=||^u z`H?P9XSU1szxD<8@8oOWd*8NSV86iYyg>E;KWQA_6itZkwKTXekN4nJ+Q=g>BqwzJ zY`r?C%Sq?>4roHxuddn4_sAXLAXzv#)6<7{$Xt*d986t2Ju)La+LQT?yRKSiw8vL_ zvwb=r9b|7fhz@o-K1dE+)s@R0dONK0((+`#{M6uh9g@2m*{|B8@}%jIe`g*T5*e|eOV86hAfz=nN{w}$ef6LtC4%a-NI$o!1 zo_ju@nhfZ9=6jZ$BR+W$9ZVe#Rylbb_tAvtS7Yu12iXq}p4GDt4j!G~^`V2z1*La2 zJ!HrUbWn?;b7*SQ!7gicKxZtufoy3 z@;K}#PVJaFTgH z9S+X&_?d@;v)s&Q4%p>8ojy=G)jHJlI>&eK73$mz4zeR0Jga9P96UOI)|bA|?`nF4 zo^k$J-S4=v9({*Aj_-&jM0ahZ{o~^S7nD^xl?t5MJyMO08-vAEs zZE!I4qr98*D4l)4ZZ7@|vwxPqi=W>G2l);-h@O~!$B*i|haQl-;UGF#>6J#l!lU_W z#w%+1U2vfv-@Vh7k(b$ucezeyM*5G|nU~nzo4LF3{4O}i_ayK1%#Ao6sF~D>mB$Y5 z%`|-G!)JIjKb!X|ets7mWKTGl`WenFP%~8PR5f?t9pRp>`qNL&PN{zf{_Da2|H1d< z_d2igU7z$LdB2BVN7XuA?%n-(C->vgpEKO|y6SiTyVSqScYc@O*Zz+E0{aE_3q0cm zR{u73cdz!Z{>_=qTlKr#>K@(qemA{)r`7LV>GzD+)g3dx>Z!ERoRL?}`YxKj+mF7> zxoZDb_d4BsMtSe2_B?YcE%We1dZjaujB~Hur{8_oT;~q_*&O_eL{{m;Tj%y~rbE9~%y@7Oc;3v@4Vw}0cS`>y7?clllPJH6AuBQeE z$-=?Z#qmJbs(hz;KbaLg+qW|Ns!V8bdsaJF4?~Hf<*1PY2^}n4vzMppHT>XCg{`~^`1@;T< P7uYYbUtqt$tG~d1MnoZj literal 0 HcmV?d00001 diff --git a/src/dusk/asset/assettype.h b/src/dusk/asset/assettype.h index 78a4542..f5dfa36 100644 --- a/src/dusk/asset/assettype.h +++ b/src/dusk/asset/assettype.h @@ -19,12 +19,9 @@ typedef enum { ASSET_TYPE_NULL, ASSET_TYPE_TEXTURE, - // ASSET_TYPE_PALETTE, ASSET_TYPE_TILESET, ASSET_TYPE_LANGUAGE, ASSET_TYPE_SCRIPT, - ASSET_TYPE_MAP, - ASSET_TYPE_MAP_CHUNK, ASSET_TYPE_COUNT, } assettype_t; @@ -60,21 +57,14 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = { }, [ASSET_TYPE_TEXTURE] = { - .extension = "dpt", + .extension = "DTX", .loadStrategy = ASSET_LOAD_STRAT_ENTIRE, .dataSize = sizeof(assettexture_t), .entire = assetTextureLoad }, - // [ASSET_TYPE_PALETTE] = { - // .extension = "dpf", - // .loadStrategy = ASSET_LOAD_STRAT_ENTIRE, - // .dataSize = sizeof(palette_t), - // .entire = assetPaletteLoad - // }, - [ASSET_TYPE_TILESET] = { - .extension = "dtf", + .extension = "DTF", .loadStrategy = ASSET_LOAD_STRAT_ENTIRE, .dataSize = sizeof(assettileset_t), .entire = assetTilesetLoad @@ -91,16 +81,4 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = { .loadStrategy = ASSET_LOAD_STRAT_CUSTOM, .custom = assetScriptHandler }, - - // [ASSET_TYPE_MAP] = { - // .extension = "DMF", - // .loadStrategy = ASSET_LOAD_STRAT_CUSTOM, - // .custom = assetMapHandler - // }, - - // [ASSET_TYPE_MAP_CHUNK] = { - // .extension = "DMC", - // .loadStrategy = ASSET_LOAD_STRAT_CUSTOM, - // .custom = assetMapChunkHandler - // }, }; \ No newline at end of file diff --git a/src/dusk/asset/type/assettexture.c b/src/dusk/asset/type/assettexture.c index 867b636..07bd9d9 100644 --- a/src/dusk/asset/type/assettexture.c +++ b/src/dusk/asset/type/assettexture.c @@ -12,50 +12,67 @@ #include "util/endian.h" errorret_t assetTextureLoad(assetentire_t entire) { - // assertNotNull(entire.data, "Data pointer cannot be NULL."); - // assertNotNull(entire.output, "Output pointer cannot be NULL."); + assertNotNull(entire.data, "Data pointer cannot be NULL."); + assertNotNull(entire.output, "Output pointer cannot be NULL."); - // assettexture_t *assetData = (assettexture_t *)entire.data; - // texture_t *texture = (texture_t *)entire.output; + assettexture_t *assetData = (assettexture_t *)entire.data; + texture_t *texture = (texture_t *)entire.output; - // // Read header and version (first 4 bytes) - // if( - // assetData->header[0] != 'D' || - // assetData->header[1] != 'P' || - // assetData->header[2] != 'T' - // ) { - // errorThrow("Invalid texture header"); - // } + // Read header and version (first 4 bytes) + if( + assetData->header[0] != 'D' || + assetData->header[1] != 'T' || + assetData->header[2] != 'X' + ) { + errorThrow("Invalid texture header"); + } - // // Version (can only be 1 atm) - // if(assetData->version != 0x01) { - // errorThrow("Unsupported texture version"); - // } + // Version (can only be 1 atm) + if(assetData->version != 0x01) { + errorThrow("Unsupported texture version"); + } - // // Fix endian - // assetData->width = endianLittleToHost32(assetData->width); - // assetData->height = endianLittleToHost32(assetData->height); + // Fix endian + assetData->width = endianLittleToHost32(assetData->width); + assetData->height = endianLittleToHost32(assetData->height); - // // Check dimensions. - // if( - // assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX || - // assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX - // ) { - // errorThrow("Invalid texture dimensions"); - // } - - // textureInit( - // texture, - // assetData->width, - // assetData->height, - // TEXTURE_FORMAT_PALETTE, - // (texturedata_t){ - // .paletted = { - // .indices = NULL, - // .palette = NULL - // } - // } - // ); + // Check dimensions. + if( + assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX || + assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX + ) { + errorThrow("Invalid texture dimensions"); + } - // errorOk(); + // Validate format + textureformat_t format; + texturedata_t data; + + switch(assetData->type) { + case 0x00: // RGBA8888 + format = TEXTURE_FORMAT_RGBA; + data.rgbaColors = (color_t *)assetData->data; + break; + + // case 0x01: + // format = TEXTURE_FORMAT_RGB; + // break; + + // case 0x02: + // format = TEXTURE_FORMAT_RGB565; + // break; + + // case 0x03: + // format = TEXTURE_FORMAT_RGB5A3; + // break; + + default: + errorThrow("Unsupported texture format"); + } + + errorChain(textureInit( + texture, assetData->width, assetData->height, format, data + )); + + errorOk(); } \ No newline at end of file diff --git a/src/dusk/asset/type/assettexture.h b/src/dusk/asset/type/assettexture.h index 6ff4cff..1dbdde4 100644 --- a/src/dusk/asset/type/assettexture.h +++ b/src/dusk/asset/type/assettexture.h @@ -7,6 +7,7 @@ #pragma once #include "error/error.h" +#include "display/color.h" #define ASSET_TEXTURE_WIDTH_MAX 2048 #define ASSET_TEXTURE_HEIGHT_MAX 2048 @@ -20,9 +21,10 @@ typedef struct assetentire_s assetentire_t; typedef struct { char_t header[3]; uint8_t version; + uint8_t type; uint32_t width; uint32_t height; - uint8_t palette[ASSET_TEXTURE_SIZE_MAX]; + uint8_t data[ASSET_TEXTURE_SIZE_MAX * sizeof(color4b_t)]; } assettexture_t; #pragma pack(pop) diff --git a/src/dusk/display/text/text.c b/src/dusk/display/text/text.c index 37e6b4b..3eecf94 100644 --- a/src/dusk/display/text/text.c +++ b/src/dusk/display/text/text.c @@ -11,17 +11,19 @@ #include "display/spritebatch/spritebatch.h" #include "asset/asset.h" +#include "display/shader/shaderunlit.h" + texture_t DEFAULT_FONT_TEXTURE; tileset_t DEFAULT_FONT_TILESET; errorret_t textInit(void) { - // errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE)); - // errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET)); + errorChain(assetLoad("ui/minogram.dtx", &DEFAULT_FONT_TEXTURE)); + errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET)); errorOk(); } errorret_t textDispose(void) { - // errorChain(textureDispose(&DEFAULT_FONT_TEXTURE)); + errorChain(textureDispose(&DEFAULT_FONT_TEXTURE)); errorOk(); } @@ -45,6 +47,8 @@ errorret_t textDrawChar( vec4 uv; tilesetTileGetUV(tileset, tileIndex, uv); + errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture)); + errorChain(spriteBatchPush( // texture, x, y, diff --git a/tools/texture-creator.html b/tools/texture-creator.html new file mode 100644 index 0000000..152f3b6 --- /dev/null +++ b/tools/texture-creator.html @@ -0,0 +1,417 @@ + + + + + + Dusk Tools / Texture Creator + + + + + +

Dusk Texture Creator

+

+ Creates texture files. This will not create palletized textures, use the + palette-indexer.html tool for that. This will instead work for all other + kinds of textures. +

+ +
+
+ +
+
+ +
+

Settings

+ +
+ Texture Format: +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ +
+

Preview

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + + \ No newline at end of file diff --git a/tools/tileset-creator.html b/tools/tileset-creator.html index 1b74b08..f671541 100644 --- a/tools/tileset-creator.html +++ b/tools/tileset-creator.html @@ -151,23 +151,24 @@ const getValues = () => { if(!pixels) return null; + const right = parseInt(elRight.value) || 0; + const bottom = parseInt(elBottom.value) || 0; + let tileWidth, tileHeight, columnCount, rowCount; if(elDefineBySize.checked) { console.log('Defining by size'); tileWidth = parseInt(elTileWidth.value) || 0; tileHeight = parseInt(elTileHeight.value) || 0; - columnCount = Math.floor(imageWidth / tileWidth); - rowCount = Math.floor(imageHeight / tileHeight); + columnCount = Math.floor((imageWidth - right) / tileWidth); + rowCount = Math.floor((imageHeight - bottom) / tileHeight); } else { console.log('Defining by count'); columnCount = parseInt(elColumnCount.value) || 0; rowCount = parseInt(elRowCount.value) || 0; - tileWidth = Math.floor(imageWidth / columnCount); - tileHeight = Math.floor(imageHeight / rowCount); + tileWidth = Math.floor((imageWidth - right) / columnCount); + tileHeight = Math.floor((imageHeight - bottom) / rowCount); } - const right = parseInt(elRight.value) || 0; - const bottom = parseInt(elBottom.value) || 0; const scale = parseInt(elScale.value) || 1; const scaledWidth = imageWidth * scale;