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 688283d..0000000 Binary files a/assets/ui/minogram.dpt and /dev/null differ diff --git a/assets/ui/minogram.dtf b/assets/ui/minogram.dtf index 41511ea..cbf4aef 100644 Binary files a/assets/ui/minogram.dtf and b/assets/ui/minogram.dtf differ diff --git a/assets/ui/minogram.dtx b/assets/ui/minogram.dtx new file mode 100644 index 0000000..af45a07 Binary files /dev/null and b/assets/ui/minogram.dtx differ 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;