Fixed whatever problem was with texture loading.
This commit is contained in:
@@ -199,7 +199,7 @@ function sceneRender()
|
|||||||
1, 1
|
1, 1
|
||||||
)
|
)
|
||||||
|
|
||||||
textDraw(10, 10, "Minesweeper")
|
textDraw(10, 10, "A")
|
||||||
|
|
||||||
-- centerX = math.floor(screenGetWidth() / 2)
|
-- centerX = math.floor(screenGetWidth() / 2)
|
||||||
-- centerY = math.floor(screenGetHeight() / 2)
|
-- centerY = math.floor(screenGetHeight() / 2)
|
||||||
|
|||||||
Binary file not shown.
BIN
assets/ui/minogram.dtf
Normal file
BIN
assets/ui/minogram.dtf
Normal file
Binary file not shown.
@@ -20,10 +20,8 @@ typedef struct assetentire_s assetentire_t;
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char_t header[3];
|
char_t header[3];
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
|
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint8_t paletteIndex;
|
|
||||||
uint8_t palette[ASSET_TEXTURE_SIZE_MAX];
|
uint8_t palette[ASSET_TEXTURE_SIZE_MAX];
|
||||||
} assettexture_t;
|
} assettexture_t;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "display/tileset/tileset.h"
|
#include "display/tileset/tileset.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
|
||||||
errorret_t assetTilesetLoad(assetentire_t entire) {
|
errorret_t assetTilesetLoad(assetentire_t entire) {
|
||||||
assertNotNull(entire.data, "Asset data cannot be null");
|
assertNotNull(entire.data, "Asset data cannot be null");
|
||||||
@@ -28,5 +29,51 @@ errorret_t assetTilesetLoad(assetentire_t entire) {
|
|||||||
errorThrow("Unsupported tileset version");
|
errorThrow("Unsupported tileset version");
|
||||||
}
|
}
|
||||||
|
|
||||||
errorThrow("unfinished");
|
// Fix endianness
|
||||||
|
tilesetData->tileWidth = le16toh(tilesetData->tileWidth);
|
||||||
|
tilesetData->tileHeight = le16toh(tilesetData->tileHeight);
|
||||||
|
tilesetData->columnCount = le16toh(tilesetData->columnCount);
|
||||||
|
tilesetData->rowCount = le16toh(tilesetData->rowCount);
|
||||||
|
tilesetData->right = le16toh(tilesetData->right);
|
||||||
|
tilesetData->bottom = le16toh(tilesetData->bottom);
|
||||||
|
|
||||||
|
if(tilesetData->tileWidth == 0) {
|
||||||
|
errorThrow("Tile width cannot be 0");
|
||||||
|
}
|
||||||
|
if(tilesetData->tileHeight == 0) {
|
||||||
|
errorThrow("Tile height cannot be 0");
|
||||||
|
}
|
||||||
|
if(tilesetData->columnCount == 0) {
|
||||||
|
errorThrow("Column count cannot be 0");
|
||||||
|
}
|
||||||
|
if(tilesetData->rowCount == 0) {
|
||||||
|
errorThrow("Row count cannot be 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t temp;
|
||||||
|
memoryCopy(&temp, &tilesetData->u0, sizeof(float_t));
|
||||||
|
temp = le32toh(temp);
|
||||||
|
memoryCopy(&tilesetData->u0, &temp, sizeof(float_t));
|
||||||
|
|
||||||
|
if(tilesetData->u0 < 0.0f || tilesetData->u0 > 1.0f) {
|
||||||
|
errorThrow("Invalid u0 value in tileset");
|
||||||
|
}
|
||||||
|
|
||||||
|
memoryCopy(&temp, &tilesetData->v0, sizeof(float_t));
|
||||||
|
temp = le32toh(temp);
|
||||||
|
memoryCopy(&tilesetData->v0, &temp, sizeof(float_t));
|
||||||
|
|
||||||
|
if(tilesetData->v0 < 0.0f || tilesetData->v0 > 1.0f) {
|
||||||
|
errorThrow("Invalid v0 value in tileset");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup tileset
|
||||||
|
tileset->tileWidth = tilesetData->tileWidth;
|
||||||
|
tileset->tileHeight = tilesetData->tileHeight;
|
||||||
|
tileset->tileCount = tilesetData->columnCount * tilesetData->rowCount;
|
||||||
|
tileset->columns = tilesetData->columnCount;
|
||||||
|
tileset->rows = tilesetData->rowCount;
|
||||||
|
tileset->uv[0] = tilesetData->u0;
|
||||||
|
tileset->uv[1] = tilesetData->v0;
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,14 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char_t header[3];
|
char_t header[3];
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
|
uint16_t tileWidth;
|
||||||
|
uint16_t tileHeight;
|
||||||
|
uint16_t columnCount;
|
||||||
|
uint16_t rowCount;
|
||||||
|
uint16_t right;
|
||||||
|
uint16_t bottom;
|
||||||
|
float_t u0;
|
||||||
|
float_t v0;
|
||||||
} assettileset_t;
|
} assettileset_t;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ errorret_t displayInit(void) {
|
|||||||
#else
|
#else
|
||||||
GLint mask = 0;
|
GLint mask = 0;
|
||||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
||||||
|
DISPLAY.usingShaderedPalettes = true;
|
||||||
if(mask & GL_CONTEXT_CORE_PROFILE_BIT) {
|
if(mask & GL_CONTEXT_CORE_PROFILE_BIT) {
|
||||||
GLint numExtens = 0;
|
GLint numExtens = 0;
|
||||||
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtens);
|
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtens);
|
||||||
@@ -100,7 +101,7 @@ errorret_t displayInit(void) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char* ext = (const char*)glGetString(GL_EXTENSIONS);
|
const char* ext = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
DISPLAY.usingShaderedPalettes = (
|
DISPLAY.usingShaderedPalettes = !(
|
||||||
ext && strstr(ext, "GL_EXT_paletted_texture")
|
ext && strstr(ext, "GL_EXT_paletted_texture")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ void paletteInit(
|
|||||||
memoryZero(palette, sizeof(palette_t));
|
memoryZero(palette, sizeof(palette_t));
|
||||||
|
|
||||||
palette->colorCount = colorCount;
|
palette->colorCount = colorCount;
|
||||||
memoryCopy(colors, palette->colors, colorCount * sizeof(color_t));
|
memoryCopy(palette->colors, colors, colorCount * sizeof(color_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void paletteBind(palette_t *palette, const uint8_t slot) {
|
void paletteBind(palette_t *palette, const uint8_t slot) {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ void textDrawChar(
|
|||||||
if(tileIndex < 0 || tileIndex >= tileset->tileCount) {
|
if(tileIndex < 0 || tileIndex >= tileset->tileCount) {
|
||||||
tileIndex = ((int32_t)'@') - TEXT_CHAR_START;
|
tileIndex = ((int32_t)'@') - TEXT_CHAR_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
tileIndex >= 0 && tileIndex <= tileset->tileCount,
|
tileIndex >= 0 && tileIndex <= tileset->tileCount,
|
||||||
"Character is out of bounds for font tiles"
|
"Character is out of bounds for font tiles"
|
||||||
|
|||||||
@@ -52,12 +52,13 @@ void textureInit(
|
|||||||
uint8_t formatted[width * height];
|
uint8_t formatted[width * height];
|
||||||
for(int32_t i = 0; i < width * height; i++) {
|
for(int32_t i = 0; i < width * height; i++) {
|
||||||
uint8_t index = data.paletteData[i];
|
uint8_t index = data.paletteData[i];
|
||||||
formatted[i] = index;
|
formatted[i] = index * 128;
|
||||||
}
|
}
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D, 0, GL_R, width, height, 0,
|
GL_TEXTURE_2D, 0, GL_R8, width, height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
|
GL_RED, GL_UNSIGNED_BYTE, (void*)formatted
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D,
|
GL_TEXTURE_2D,
|
||||||
@@ -66,12 +67,16 @@ void textureInit(
|
|||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
GL_UNSIGNED_BYTE, (void*)data.paletteData
|
GL_UNSIGNED_BYTE, (void*)data.paletteData
|
||||||
);
|
);
|
||||||
|
|
||||||
// glColorTableEXT(
|
// glColorTableEXT(
|
||||||
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
||||||
// GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
|
// GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLenum err = glGetError();
|
||||||
|
if(err != GL_NO_ERROR) {
|
||||||
|
assertUnreachable("GL error uploading palette texture");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -9,14 +9,12 @@
|
|||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
typedef struct tileset_s {
|
typedef struct tileset_s {
|
||||||
const char_t *name;
|
uint16_t tileWidth;
|
||||||
const uint16_t tileWidth;
|
uint16_t tileHeight;
|
||||||
const uint16_t tileHeight;
|
uint16_t tileCount;
|
||||||
const uint16_t tileCount;
|
uint16_t columns;
|
||||||
const uint16_t columns;
|
uint16_t rows;
|
||||||
const uint16_t rows;
|
vec2 uv;
|
||||||
const vec2 uv;
|
|
||||||
const char_t *image;
|
|
||||||
} tileset_t;
|
} tileset_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,13 +41,7 @@ int moduleTilesetIndex(lua_State *l) {
|
|||||||
tileset_t *ts = (tileset_t *)luaL_checkudata(l, 1, "tileset_mt");
|
tileset_t *ts = (tileset_t *)luaL_checkudata(l, 1, "tileset_mt");
|
||||||
assertNotNull(ts, "Tileset pointer cannot be NULL.");
|
assertNotNull(ts, "Tileset pointer cannot be NULL.");
|
||||||
|
|
||||||
if(stringCompare(key, "name") == 0) {
|
if(stringCompare(key, "tileWidth") == 0) {
|
||||||
lua_pushstring(l, ts->name);
|
|
||||||
return 1;
|
|
||||||
} else if(stringCompare(key, "texture") == 0) {
|
|
||||||
lua_pushstring(l, ts->image);
|
|
||||||
return 1;
|
|
||||||
} else if(stringCompare(key, "tileWidth") == 0) {
|
|
||||||
lua_pushnumber(l, ts->tileWidth);
|
lua_pushnumber(l, ts->tileWidth);
|
||||||
return 1;
|
return 1;
|
||||||
} else if(stringCompare(key, "tileHeight") == 0) {
|
} else if(stringCompare(key, "tileHeight") == 0) {
|
||||||
@@ -72,7 +66,9 @@ int moduleTilesetToString(lua_State *l) {
|
|||||||
tileset_t *ts = (tileset_t *)luaL_checkudata(l, 1, "tileset_mt");
|
tileset_t *ts = (tileset_t *)luaL_checkudata(l, 1, "tileset_mt");
|
||||||
assertNotNull(ts, "Tileset pointer cannot be NULL.");
|
assertNotNull(ts, "Tileset pointer cannot be NULL.");
|
||||||
|
|
||||||
lua_pushfstring(l, "Tileset: %s", ts->name);
|
lua_pushfstring(l, "Tileset: %dx%d tile, %d columns, %d rows",
|
||||||
|
ts->tileWidth, ts->tileHeight, ts->columns, ts->rows
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@
|
|||||||
const getValues = () => {
|
const getValues = () => {
|
||||||
if(!pixels) return null;
|
if(!pixels) return null;
|
||||||
|
|
||||||
let tileWidth, tileHeight, columnCount, rowCount, right, bottom;
|
let tileWidth, tileHeight, columnCount, rowCount;
|
||||||
if(elDefineBySize.checked) {
|
if(elDefineBySize.checked) {
|
||||||
console.log('Defining by size');
|
console.log('Defining by size');
|
||||||
tileWidth = parseInt(elTileWidth.value) || 0;
|
tileWidth = parseInt(elTileWidth.value) || 0;
|
||||||
@@ -166,8 +166,8 @@
|
|||||||
tileHeight = Math.floor(imageHeight / rowCount);
|
tileHeight = Math.floor(imageHeight / rowCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
right = parseInt(elRight.value) || 0;
|
const right = parseInt(elRight.value) || 0;
|
||||||
bottom = parseInt(elBottom.value) || 0;
|
const bottom = parseInt(elBottom.value) || 0;
|
||||||
|
|
||||||
const scale = parseInt(elScale.value) || 1;
|
const scale = parseInt(elScale.value) || 1;
|
||||||
const scaledWidth = imageWidth * scale;
|
const scaledWidth = imageWidth * scale;
|
||||||
@@ -177,13 +177,13 @@
|
|||||||
const scaledRight = right * scale;
|
const scaledRight = right * scale;
|
||||||
const scaledBottom = bottom * scale;
|
const scaledBottom = bottom * scale;
|
||||||
|
|
||||||
const u0 = tileWidth / imageWidth - (right / imageWidth);
|
const u0 = (tileWidth / imageWidth);
|
||||||
const v0 = tileHeight / imageHeight - (bottom / imageHeight);
|
const v0 = (tileHeight / imageHeight);
|
||||||
|
|
||||||
const hoveredTileX = isNaN(hoveredX) || hoveredX < 0 ? 0 : hoveredX;
|
const hoveredTileX = isNaN(hoveredX) || hoveredX < 0 ? 0 : hoveredX;
|
||||||
const hoveredTileY = isNaN(hoveredY) || hoveredY < 0 ? 0 : hoveredY;
|
const hoveredTileY = isNaN(hoveredY) || hoveredY < 0 ? 0 : hoveredY;
|
||||||
const hoveredU0 = hoveredTileX * tileWidth / imageWidth;
|
const hoveredU0 = hoveredTileX * u0;
|
||||||
const hoveredV0 = hoveredTileY * tileHeight / imageHeight;
|
const hoveredV0 = hoveredTileY * v0;
|
||||||
const hoveredU1 = hoveredU0 + u0;
|
const hoveredU1 = hoveredU0 + u0;
|
||||||
const hoveredV1 = hoveredV0 + v0;
|
const hoveredV1 = hoveredV0 + v0;
|
||||||
const hoveredTileIndex = hoveredTileY * columnCount + hoveredTileX;
|
const hoveredTileIndex = hoveredTileY * columnCount + hoveredTileX;
|
||||||
|
|||||||
Reference in New Issue
Block a user