fixing color management issue with texts

This commit is contained in:
2024-01-10 20:22:53 +01:00
parent 62c623d70a
commit 875d73e3dd
8 changed files with 30 additions and 22 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2024/01/09 00:25:08 by maldavid ### ########.fr */ /* Updated: 2024/01/10 20:21:45 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -32,6 +32,7 @@ int update(void *param)
mlx = (t_mlx *)param; mlx = (t_mlx *)param;
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100);
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
mlx_string_put(mlx->mlx, mlx->win, 90, 120, 0xFFFF2066, "this text should be hidden");
if (i == 0) if (i == 0)
mlx_set_font_scale(mlx->mlx, mlx->win, "font.ttf", 16.f); mlx_set_font_scale(mlx->mlx, mlx->win, "font.ttf", 16.f);
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text"); mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
@@ -110,7 +111,7 @@ int main(int argc, char **argv)
mlx_pixel_put(mlx.mlx, mlx.win, 200, 10, 0xFFFF00FF); mlx_pixel_put(mlx.mlx, mlx.win, 200, 10, 0xFFFF00FF);
mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 10, 190); mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 10, 190);
mlx.img = create_image(&mlx); mlx.img = create_image(&mlx);
mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFFFF2000, \ mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFF0020FF, \
"that text will disappear"); "that text will disappear");
mlx_loop_hook(mlx.mlx, update, &mlx); mlx_loop_hook(mlx.mlx, update, &mlx);
mlx_loop(mlx.mlx); mlx_loop(mlx.mlx);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */ /* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2024/01/10 14:17:24 by maldavid ### ########.fr */ /* Updated: 2024/01/10 19:57:12 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -46,7 +46,7 @@ namespace mlx::core
inline void destroyGraphicsSupport(void* win); inline void destroyGraphicsSupport(void* win);
inline void pixelPut(void* win, int x, int y, uint32_t color) const noexcept; inline void pixelPut(void* win, int x, int y, uint32_t color) const noexcept;
inline void stringPut(void* win, int x, int y, int color, char* str); inline void stringPut(void* win, int x, int y, uint32_t color, char* str);
void* newTexture(int w, int h); void* newTexture(int w, int h);
void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...) void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...)

View File

@@ -97,7 +97,7 @@ namespace mlx::core
_graphics[*static_cast<int*>(win)]->pixelPut(x, y, color); _graphics[*static_cast<int*>(win)]->pixelPut(x, y, color);
} }
void Application::stringPut(void* win, int x, int y, int color, char* str) void Application::stringPut(void* win, int x, int y, uint32_t color, char* str)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win); CHECK_WINDOW_PTR(win);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */ /* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2023/12/31 00:22:58 by maldavid ### ########.fr */ /* Updated: 2024/01/10 19:54:51 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -193,8 +193,8 @@ extern "C"
unsigned char color_bits[4]; unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16; color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8; color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF; color_bits[2] = (color & 0x000000FF);
color_bits[3] = 0xFF; color_bits[3] = (color & 0xFF000000) >> 24;
static_cast<mlx::core::Application*>(mlx)->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str); static_cast<mlx::core::Application*>(mlx)->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
return 0; return 0;
} }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */ /* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2024/01/10 14:18:48 by maldavid ### ########.fr */ /* Updated: 2024/01/10 19:59:58 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -44,7 +44,7 @@ namespace mlx
inline void clearRenderData() noexcept; inline void clearRenderData() noexcept;
inline void pixelPut(int x, int y, uint32_t color) noexcept; inline void pixelPut(int x, int y, uint32_t color) noexcept;
inline void stringPut(int x, int y, int color, std::string str); inline void stringPut(int x, int y, uint32_t color, std::string str);
inline void texturePut(Texture* texture, int x, int y); inline void texturePut(Texture* texture, int x, int y);
inline void loadFont(const std::filesystem::path& filepath, float scale); inline void loadFont(const std::filesystem::path& filepath, float scale);

View File

@@ -32,7 +32,7 @@ namespace mlx
_pixel_put_pipeline.setPixel(x, y, color); _pixel_put_pipeline.setPixel(x, y, color);
} }
void GraphicsSupport::stringPut(int x, int y, int color, std::string str) void GraphicsSupport::stringPut(int x, int y, uint32_t color, std::string str)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
_text_put_pipeline->put(x, y, color, str); _text_put_pipeline->put(x, y, color, str);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */ /* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
/* Updated: 2024/01/10 18:26:24 by maldavid ### ########.fr */ /* Updated: 2024/01/10 20:20:30 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -32,7 +32,7 @@ constexpr const int RANGE = 1024;
namespace mlx namespace mlx
{ {
TextDrawData::TextDrawData(std::string _text, int _color, int _x, int _y) : TextDrawData::TextDrawData(std::string _text, uint32_t _color, int _x, int _y) :
x(_x), y(_y), color(_color), x(_x), y(_y), color(_color),
text(std::move(_text)) text(std::move(_text))
{} {}
@@ -56,10 +56,17 @@ namespace mlx
std::size_t index = vertexData.size(); std::size_t index = vertexData.size();
vertexData.emplace_back(glm::vec2{q.x0, q.y0}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s0, q.t0}); glm::vec4 vertex_color = {
vertexData.emplace_back(glm::vec2{q.x1, q.y0}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s1, q.t0}); static_cast<float>((color & 0x000000FF)) / 255.f,
vertexData.emplace_back(glm::vec2{q.x1, q.y1}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s1, q.t1}); static_cast<float>((color & 0x0000FF00) >> 8) / 255.f,
vertexData.emplace_back(glm::vec2{q.x0, q.y1}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s0, q.t1}); static_cast<float>((color & 0x00FF0000) >> 16) / 255.f,
static_cast<float>((color & 0xFF000000) >> 24) / 255.f
};
vertexData.emplace_back(glm::vec2{q.x0, q.y0}, vertex_color, glm::vec2{q.s0, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y0}, vertex_color, glm::vec2{q.s1, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y1}, vertex_color, glm::vec2{q.s1, q.t1});
vertexData.emplace_back(glm::vec2{q.x0, q.y1}, vertex_color, glm::vec2{q.s0, q.t1});
indexData.emplace_back(index + 0); indexData.emplace_back(index + 0);
indexData.emplace_back(index + 1); indexData.emplace_back(index + 1);
@@ -93,7 +100,7 @@ namespace mlx
_font_in_use = &const_cast<Font&>(*_font_set.emplace(*_renderer, filepath, scale).first); _font_in_use = &const_cast<Font&>(*_font_set.emplace(*_renderer, filepath, scale).first);
} }
void TextPutPipeline::put(int x, int y, int color, std::string str) void TextPutPipeline::put(int x, int y, uint32_t color, std::string str)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
auto res = _drawlist.emplace(std::move(str), color, x, y); auto res = _drawlist.emplace(std::move(str), color, x, y);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */ /* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
/* Updated: 2023/12/14 17:39:51 by maldavid ### ########.fr */ /* Updated: 2024/01/10 19:58:22 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -30,10 +30,10 @@ namespace mlx
TextID id; TextID id;
int x; int x;
int y; int y;
int color; uint32_t color;
std::string text; std::string text;
TextDrawData(std::string text, int _color, int _x, int _y); TextDrawData(std::string text, uint32_t _color, int _x, int _y);
void init(TextLibrary& library, Font* const font) noexcept; void init(TextLibrary& library, Font* const font) noexcept;
bool operator==(const TextDrawData& rhs) const { return text == rhs.text && x == rhs.x && y == rhs.y && color == rhs.color; } bool operator==(const TextDrawData& rhs) const { return text == rhs.text && x == rhs.x && y == rhs.y && color == rhs.color; }
TextDrawData() = default; TextDrawData() = default;
@@ -62,7 +62,7 @@ namespace mlx
TextPutPipeline() = default; TextPutPipeline() = default;
void init(Renderer* renderer) noexcept; void init(Renderer* renderer) noexcept;
void put(int x, int y, int color, std::string str); void put(int x, int y, uint32_t color, std::string str);
inline void clear() { _drawlist.clear(); _library.clearLibrary(); } inline void clear() { _drawlist.clear(); _library.clearLibrary(); }
void loadFont(const std::filesystem::path& filepath, float scale); void loadFont(const std::filesystem::path& filepath, float scale);
void render(std::array<VkDescriptorSet, 2>& sets); void render(std::array<VkDescriptorSet, 2>& sets);