From 92a753560bea9c90b1b5992c0829b1accc1be9c1 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 15 Feb 2026 01:09:28 -0600 Subject: [PATCH] prog --- assets/scene/minesweeper.lua | 1 - assets/ui/minogram.dpt | Bin 0 -> 8204 bytes src/asset/type/assettexture.c | 48 ++++++++---- src/asset/type/assettexture.h | 3 + src/display/framebuffer.c | 4 +- src/display/text.c | 2 +- src/display/texture.c | 141 +++++++++++++++------------------- src/display/texture.h | 19 +---- tools/palette-indexer.html | 16 ++-- 9 files changed, 110 insertions(+), 124 deletions(-) create mode 100644 assets/ui/minogram.dpt diff --git a/assets/scene/minesweeper.lua b/assets/scene/minesweeper.lua index beeb93f..2df6492 100644 --- a/assets/scene/minesweeper.lua +++ b/assets/scene/minesweeper.lua @@ -198,7 +198,6 @@ function sceneRender() 0, 0, 1, 1 ) - -- centerX = math.floor(screenGetWidth() / 2) -- centerY = math.floor(screenGetHeight() / 2) diff --git a/assets/ui/minogram.dpt b/assets/ui/minogram.dpt new file mode 100644 index 0000000000000000000000000000000000000000..223156eb483456521145ed2483c28143739ed0a9 GIT binary patch literal 8204 zcmeHGTXNel476|7j~<{OJy4Hc>;nX7Nv7l^lTOFVgj@oPUGU+bzkc8U+-|oY@&E1L zogLh7m^Bh+UkZCQEt0W2lX=Iu`o!t}_xRk7I!c+OLbBr>i%5eZ)=s`cDTE3;yHXS4 zW^2x{<`U}2xibeKQ5AdJDr3SYk!j41$E1FpWADP^K&*>r?qP0})MFj=QQz|{MIg0X za*`z{hNJvMu7wPv4OJfdr!w`siSP*bRM||ZQ)rmlWKHMK?R36`dPLZx?s0Paf9nGc1rgt8x&P>qVKL{Brv`G+Obf z0jWwCV<{!>k@Qb~t{VrPQU&AsD{ik7mTJ?sa*IT{eD-xt`}=5dqB^%am(XC=4kJCf zV5IvOf9?NfeDewDZaMniHuu@@c6tR-FuHGW#7=;%cD^gj+pHoGE+iYQuYZpYP)Oz3 ze`-f0GSl-z{_Xq^{p}{7KB|Kc`Fq#ho0vy{A=Gso>cVE-v*SFI^^7VB=Q#Bs;~2MD zXm`(!*S>?H_b)Bof_JC~t^TSvA$yvrsXX zHiv}NOu|?PNSt$WMrNBR${O({kLL_6En)ZUmCd5 zcySATw7CmPo!aq*7Who#^`cyucgyAU%bOx(>gShUulZXwCjFk!1r!}85*EQY383c3 zx?G%{%O@(h^F4p{mfktLRa?De-}Wh)P@#}LXpDhzCq1EIdt>Ujg;!8_PL?lK$Ix%s j_Vf^cP>1}B_Nc#FdX+zVJOG#UV&?}k@9_HsE}y_((+>sq literal 0 HcmV?d00001 diff --git a/src/asset/type/assettexture.c b/src/asset/type/assettexture.c index c371774..3f6f138 100644 --- a/src/asset/type/assettexture.c +++ b/src/asset/type/assettexture.c @@ -16,27 +16,41 @@ errorret_t assetTextureLoad(void *data, void *output) { assettexture_t *assetData = (assettexture_t *)data; texture_t *texture = (texture_t *)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"); + } + + // Version (can only be 1 atm) + if(assetData->version != 0x01) { + errorThrow("Unsupported texture version"); + } + // Fix endian assetData->width = le32toh(assetData->width); assetData->height = le32toh(assetData->height); - - errorThrow("Hello World\n"); - // const palette_t *pal = PALETTE_LIST[assetData->paletteIndex]; - // assertNotNull(pal, "Palette index is out of bounds"); + // 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){ - // .palette = { - // .palette = pal, - // .data = assetData->palette - // } - // } - // ); + textureInit( + texture, + assetData->width, + assetData->height, + TEXTURE_FORMAT_PALETTE, + (texturedata_t){ + .paletteData = assetData->palette + } + ); - // errorOk(); + errorOk(); } \ No newline at end of file diff --git a/src/asset/type/assettexture.h b/src/asset/type/assettexture.h index 68bfa43..1acbf4e 100644 --- a/src/asset/type/assettexture.h +++ b/src/asset/type/assettexture.h @@ -16,6 +16,9 @@ #pragma pack(push, 1) typedef struct { + char_t header[3]; + uint8_t version; + uint32_t width; uint32_t height; uint8_t paletteIndex; diff --git a/src/display/framebuffer.c b/src/display/framebuffer.c index 9eec93c..6ec197a 100644 --- a/src/display/framebuffer.c +++ b/src/display/framebuffer.c @@ -31,8 +31,8 @@ void frameBufferInitBackbuffer() { assertTrue(width > 0 && height > 0, "W/H must be greater than 0"); memoryZero(framebuffer, sizeof(framebuffer_t)); - textureInit(&framebuffer->texture, width, height, GL_RGBA,(texturedata_t){ - .rgba = { .colors = NULL } + textureInit(&framebuffer->texture, width, height, TEXTURE_FORMAT_RGBA,(texturedata_t){ + .rgbaColors = NULL }); glGenFramebuffersEXT(1, &framebuffer->id); diff --git a/src/display/text.c b/src/display/text.c index 9e6d5fa..c8969b8 100644 --- a/src/display/text.c +++ b/src/display/text.c @@ -15,7 +15,7 @@ texture_t DEFAULT_FONT_TEXTURE; tileset_t DEFAULT_FONT_TILESET; errorret_t textInit(void) { - // errorChain(assetLoad(DEFAULT_FONT_TILESET.image, &DEFAULT_FONT_TEXTURE)); + errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE)); errorOk(); } diff --git a/src/display/texture.c b/src/display/texture.c index f368a2a..e198f14 100644 --- a/src/display/texture.c +++ b/src/display/texture.c @@ -29,16 +29,8 @@ void textureInit( texture->height = height; texture->format = format; - #if PSP - assertTrue( - width == mathNextPowTwo(width), - "Width must be powers of 2 for PSP" - ); - assertTrue( - height == mathNextPowTwo(height), - "Height must be powers of 2 for PSP" - ); - #endif + assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2."); + assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2."); #if DISPLAY_SDL2 glGenTextures(1, &texture->id); @@ -48,56 +40,55 @@ void textureInit( case TEXTURE_FORMAT_RGBA: glTexImage2D( GL_TEXTURE_2D, 0, format, width, height, 0, - format, GL_UNSIGNED_BYTE, (void*)data.rgba.colors + format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors ); break; - case TEXTURE_FORMAT_ALPHA: { - assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL"); - #if PSP - // PSP kinda broken with alpha textures, so we convert it to paletted - // texture here. We also crunch the amount of alpha values. - #define PSP_ALPHA_PALETTE_CRUNCH 4 - #define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH) + // case TEXTURE_FORMAT_ALPHA: { + // assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL"); + // #if PSP + // // PSP kinda broken with alpha textures, so we convert it to paletted + // // texture here. We also crunch the amount of alpha values. + // #define PSP_ALPHA_PALETTE_CRUNCH 4 + // #define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH) - color_t paletteColors[PSP_ALPHA_PALETTE_COUNT]; - for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) { - paletteColors[i].r = 0xFF; - paletteColors[i].g = 0xFF; - paletteColors[i].b = 0xFF; - paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH; - } + // color_t paletteColors[PSP_ALPHA_PALETTE_COUNT]; + // for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) { + // paletteColors[i].r = 0xFF; + // paletteColors[i].g = 0xFF; + // paletteColors[i].b = 0xFF; + // paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH; + // } - // Generate indexes, crunching the alpha values to fit. - uint8_t indexes[width * height]; - for(int32_t i = 0; i < width * height; i++) { - uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;; - indexes[i] = alpha; - } + // // Generate indexes, crunching the alpha values to fit. + // uint8_t indexes[width * height]; + // for(int32_t i = 0; i < width * height; i++) { + // uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;; + // indexes[i] = alpha; + // } - palette_t palette = { - .colorCount = PSP_ALPHA_PALETTE_COUNT, - .colors = paletteColors - }; + // palette_t palette = { + // .colorCount = PSP_ALPHA_PALETTE_COUNT, + // .colors = paletteColors + // }; - return textureInit( - texture, width, height, TEXTURE_FORMAT_PALETTE, - (texturedata_t){ - .palette = { .palette = &palette, .data = indexes } - } - ); - #else - glTexImage2D( - GL_TEXTURE_2D, 0, format, width, height, 0, - format, GL_UNSIGNED_BYTE, (void*)data.alpha.data - ); - #endif - break; - } + // return textureInit( + // texture, width, height, TEXTURE_FORMAT_PALETTE, + // (texturedata_t){ + // .palette = { .palette = &palette, .data = indexes } + // } + // ); + // #else + // glTexImage2D( + // GL_TEXTURE_2D, 0, format, width, height, 0, + // format, GL_UNSIGNED_BYTE, (void*)data.alpha.data + // ); + // #endif + // break; + // } case TEXTURE_FORMAT_PALETTE: - assertNotNull(data.palette.data, "Palette texture data cannot be NULL"); - assertNotNull(data.palette.palette, "Palette cannot be NULL"); + assertNotNull(data.paletteData, "Palette texture data cannot be NULL"); // Get and validate the palette. GLenum err = glGetError(); @@ -130,45 +121,35 @@ void textureInit( #endif if(!havePalTex) { + assertUnreachable("Paletted textures not supported on this platform"); // Not supported, convert to RGBA using lookup - color_t formatted[width * height]; - for(int32_t i = 0; i < width * height; i++) { - uint8_t index = data.palette.data[i]; - assertTrue( - index < data.palette.palette->colorCount, - "Palette index out of range" - ); - formatted[i] = data.palette.palette->colors[index]; - } - glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted - ); + // color_t formatted[width * height]; + // for(int32_t i = 0; i < width * height; i++) { + // uint8_t index = data..data[i]; + // assertTrue( + // index < data.palette.palette->colorCount, + // "Palette index out of range" + // ); + // formatted[i] = data.palette.palette->colors[index]; + // } + // glTexImage2D( + // GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, + // GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted + // ); } else { - // Supported. - #if PSP - // PSP requires the color table itself to be a power of two - assertTrue( - data.palette.palette->colorCount == - mathNextPowTwo(data.palette.palette->colorCount), - "Palette color count must be a power of 2 for PSP" - ); - #endif - glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, width, height, 0, GL_COLOR_INDEX8_EXT, - GL_UNSIGNED_BYTE, (void*)data.palette.data + GL_UNSIGNED_BYTE, (void*)data.paletteData ); - glColorTableEXT( - GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA, - GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors - ); + // glColorTableEXT( + // GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA, + // GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors + // ); } - break; default: diff --git a/src/display/texture.h b/src/display/texture.h index 1df6eb1..c3e0ead 100644 --- a/src/display/texture.h +++ b/src/display/texture.h @@ -13,11 +13,10 @@ typedef enum { #if DISPLAY_SDL2 TEXTURE_FORMAT_RGBA = GL_RGBA, - TEXTURE_FORMAT_ALPHA = GL_ALPHA, TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT, #elif DOLPHIN - TEXTURE_FORMAT_RGBA = GX_TF_RGBA8, - TEXTURE_FORMAT_ALPHA = GX_TF_A8, + // TEXTURE_FORMAT_RGBA = GX_TF_RGBA8, + // TEXTURE_FORMAT_ALPHA = GX_TF_A8, TEXTURE_FORMAT_PALETTE = GX_TF_CI8, #endif } textureformat_t; @@ -40,18 +39,8 @@ typedef struct { } texture_t; typedef union { - struct { - color_t *colors; - } rgba; - - struct { - const palette_t *palette; - uint8_t *data; - } palette; - - struct { - uint8_t *data; - } alpha; + uint8_t *paletteData; + color_t *rgbaColors; } texturedata_t; extern const texture_t *TEXTURE_BOUND; diff --git a/tools/palette-indexer.html b/tools/palette-indexer.html index 06e97ec..f54ba48 100644 --- a/tools/palette-indexer.html +++ b/tools/palette-indexer.html @@ -663,17 +663,17 @@ // Width const widthBytes = new Uint8Array(4); - widthBytes[0] = (imageWidth >> 24) & 0xFF; - widthBytes[1] = (imageWidth >> 16) & 0xFF; - widthBytes[2] = (imageWidth >> 8) & 0xFF; - widthBytes[3] = imageWidth & 0xFF; + widthBytes[3] = (imageWidth >> 24) & 0xFF; + widthBytes[2] = (imageWidth >> 16) & 0xFF; + widthBytes[1] = (imageWidth >> 8) & 0xFF; + widthBytes[0] = imageWidth & 0xFF; // Height const heightBytes = new Uint8Array(4); - heightBytes[0] = (imageHeight >> 24) & 0xFF; - heightBytes[1] = (imageHeight >> 16) & 0xFF; - heightBytes[2] = (imageHeight >> 8) & 0xFF; - heightBytes[3] = imageHeight & 0xFF; + heightBytes[3] = (imageHeight >> 24) & 0xFF; + heightBytes[2] = (imageHeight >> 16) & 0xFF; + heightBytes[1] = (imageHeight >> 8) & 0xFF; + heightBytes[0] = imageHeight & 0xFF; // add indexed image data (imageWidth * imageHeight bytes) const imageData = new Uint8Array(indexedImage.length);