diff --git a/util/test/demos/test_common.cpp b/util/test/demos/test_common.cpp index 3575da017..79a541c7e 100644 --- a/util/test/demos/test_common.cpp +++ b/util/test/demos/test_common.cpp @@ -24,6 +24,7 @@ #include "test_common.h" #include +#include #include const DefaultA2V DefaultTri[3] = { @@ -32,6 +33,62 @@ const DefaultA2V DefaultTri[3] = { {Vec3f(0.5f, -0.5f, 0.0f), Vec4f(0.0f, 0.0f, 1.0f, 1.0f), Vec2f(1.0f, 0.0f)}, }; +/* XPM */ +const char *SmileyTexture[63] = { + /* columns rows colors chars-per-pixel */ + "48 48 14 1 ", " c #000017", ". c #FF0017", "X c #FF735C", "o c #00FF17", "O c #FF8B5C", + "+ c #D0B95C", "@ c #E7A25C", "# c #B9D05C", "$ c #8BFF45", "% c #A2E745", "& c #A2FF45", + "* c #A2E75C", "= c #1700FF", "- c #B9FFFF", + /* pixels */ + "------------------------------------------------", + "------------------------------------------------", + "------------------------------------------------", + "------------------------------------------------", + "------------------------------------------------", + "--------------------- ---------------------", + "----------------- -----------------", + "--------------- XOOOOOOO@@ ---------------", + "------------- XXXOOOOOO@@@@@@@ -------------", + "------------ XXXOOOOOO@@@@@@@@@ ------------", + "----------- XXXXOOOOOO@@@@@@@@@@++ -----------", + "---------- XXXXOOOOOO@@@@@@@@@@++++ ----------", + "--------- XXXXOOOOOO@@@@@@@@@@++++++ ---------", + "-------- XXXXOOOOOO@@@@@@@@@++++++++# --------", + "-------- XXXOOOOOO@@@@@@@@@++++++++## --------", + "------- XXXOOOOOO@@@@@@@@@++++++++#### -------", + "------- XXOOOOO...@@@@@@@@+++++ooo###### -------", + "------ XOOOOO.....@@@@@@+++++ooooo##### ------", + "------ OOOOOO.....@@@@@++++++ooooo##### ------", + "------ OOOOOOO.....@@@@+++++++ooooo####%% ------", + "------ OOOOOO@.....@@@++++++++ooooo###%%* ------", + "----- OOOOO@@.....@@++++++++#ooooo##%%*% -----", + "----- OOOO@@@@...@@++++++++###ooo##%%*%% -----", + "----- OOO@@@@@@@@@++++++++########%%*%%% -----", + "----- O@@@@@@@@@@++++++++########%%*%%%% -----", + "----- @@@@@@@@@@++++++++########%%*%%%%% -----", + "----- @@@@@@@@@++++++++########%%*%%%%%& -----", + "------ @@@@@@@@++++++++########%%*%%%%%&& ------", + "------ @@@@==+++++++++########%%*%%==%&&& ------", + "------ @@@===+++++++########%%*%%===&&& ------", + "------ @@@+===+++++########%%*%%%==&&&$ ------", + "------- @@+++===+++#######%%%*%%%==&&&$$ -------", + "------- +++++===+#######%%%*%%%==&&&$$ -------", + "-------- +++++===######%%%%%%%===&&$$ --------", + "-------- +++++#====###%%*%%%====&&$$$ --------", + "--------- +++####===#%%*%%%====&&$$$ ---------", + "---------- +######===========&&&$$$ ----------", + "----------- #######%=======&&&&$$$ -----------", + "------------ ####%%*%%%%%&&&&$$ ------------", + "------------- ##%%*%%%%%&&&&$$ -------------", + "--------------- *%%%%%&&&& ---------------", + "----------------- -----------------", + "--------------------- ---------------------", + "------------------------------------------------", + "------------------------------------------------", + "------------------------------------------------", + "------------------------------------------------", + "------------------------------------------------"}; + // since tolower is int -> int, this warns below. make a char -> char alternative char toclower(char c) { @@ -90,6 +147,36 @@ void DebugPrint(const char *fmt, ...) #endif } +void LoadXPM(const char **XPM, Texture &tex) +{ + uint32_t numColors = 0; + sscanf(XPM[0], "%u %u %u %*u", &tex.width, &tex.height, &numColors); + + uint32_t colors[256] = {}; + + for(uint32_t c = 0; c < numColors; c++) + { + char ch = XPM[c + 1][0]; + + uint32_t col = 0; + + sscanf(XPM[c + 1] + 1, " c #%x", &col); + + // need to bgr swap, set full alpha + colors[ch] = 0xff000000 | ((col & 0xff) << 16) | (col & 0xff00) | ((col & 0xff0000) >> 16); + } + + tex.data.resize(tex.width * tex.height); + + for(uint32_t y = 0; y < tex.height; y++) + { + const char *row = XPM[1 + numColors + y]; + + for(uint32_t x = 0; x < tex.width; x++) + tex.data[y * tex.width + x] = colors[row[x]]; + } +} + #include "3rdparty/shaderc/shaderc.h" #ifndef HAVE_SHADERC diff --git a/util/test/demos/test_common.h b/util/test/demos/test_common.h index c510c7b2e..c95d48441 100644 --- a/util/test/demos/test_common.h +++ b/util/test/demos/test_common.h @@ -105,6 +105,18 @@ struct Vec4f float x, y, z, w; }; +struct Vec4i +{ + Vec4i(int32_t X = 0, int32_t Y = 0, int32_t Z = 0, int32_t W = 0) + { + x = X; + y = Y; + z = Z; + w = W; + } + int32_t x, y, z, w; +}; + struct DefaultA2V { Vec3f pos; @@ -113,6 +125,16 @@ struct DefaultA2V }; extern const DefaultA2V DefaultTri[3]; +extern const char *SmileyTexture[63]; + +struct Texture +{ + uint32_t width; + uint32_t height; + std::vector data; +}; + +void LoadXPM(const char **XPM, Texture &tex); struct GraphicsWindow {