working text pipeline

This commit is contained in:
2023-04-11 19:21:11 +02:00
parent 098622c6b9
commit 06a95fae73
11 changed files with 2878 additions and 8118 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 16:56:35 by maldavid #+# #+# */ /* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
/* Updated: 2023/04/06 16:07:38 by maldavid ### ########.fr */ /* Updated: 2023/04/11 18:37:29 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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: 2023/04/06 16:08:34 by maldavid ### ########.fr */ /* Updated: 2023/04/11 18:37:05 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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: 2023/04/08 01:14:22 by maldavid ### ########.fr */ /* Updated: 2023/04/11 18:37:11 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -15,6 +15,7 @@
#include <memory> #include <memory>
#include <unordered_set> #include <unordered_set>
#include <filesystem>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */ /* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
/* Updated: 2023/04/11 13:20:26 by maldavid ### ########.fr */ /* Updated: 2023/04/11 16:21:23 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -91,8 +91,8 @@ namespace mlx
{ {
VkSamplerCreateInfo info = {}; VkSamplerCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
info.magFilter = VK_FILTER_LINEAR; info.magFilter = VK_FILTER_NEAREST;
info.minFilter = VK_FILTER_LINEAR; info.minFilter = VK_FILTER_NEAREST;
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;

View File

@@ -6,13 +6,14 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */ /* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
/* Updated: 2023/04/11 12:28:42 by maldavid ### ########.fr */ /* Updated: 2023/04/11 18:30:09 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <renderer/text_library.h> #include <renderer/text_library.h>
#include <core/errors.h> #include <core/errors.h>
#include <renderer/renderer.h> #include <renderer/renderer.h>
#include <algorithm>
namespace mlx namespace mlx
{ {
@@ -43,6 +44,12 @@ namespace mlx
TextID TextLibrary::addTextToLibrary(std::shared_ptr<TextData> text) TextID TextLibrary::addTextToLibrary(std::shared_ptr<TextData> text)
{ {
auto it = std::find_if(_cache.begin(), _cache.end(), [=](const std::pair<TextID, std::shared_ptr<TextData>>& v)
{
return v.second == text;
});
if(it != _cache.end())
return it->first;
_cache[_current_id] = text; _cache[_current_id] = text;
_current_id++; _current_id++;
return _current_id - 1; return _current_id - 1;

View File

@@ -6,14 +6,14 @@
/* 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: 2023/04/11 12:49:59 by maldavid ### ########.fr */ /* Updated: 2023/04/11 19:16:08 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <renderer/text_pipeline.h> #include <renderer/text_pipeline.h>
#include <fstream> #include <fstream>
#include <utils/opensans-regular.h> #include <utils/dogica_ttf.h>
#include <cstdio> #include <cstdio>
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION
@@ -43,10 +43,10 @@ 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, 0xFF}, glm::vec2{q.s0, q.t0}); vertexData.emplace_back(glm::vec2{q.x0, q.y0}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s0, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y0}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFF}, glm::vec2{q.s1, q.t0}); vertexData.emplace_back(glm::vec2{q.x1, q.y0}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s1, q.t0});
vertexData.emplace_back(glm::vec2{q.x1, q.y1}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFF}, glm::vec2{q.s1, q.t1}); vertexData.emplace_back(glm::vec2{q.x1, q.y1}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, glm::vec2{q.s1, q.t1});
vertexData.emplace_back(glm::vec2{q.x0, q.y1}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFF}, glm::vec2{q.s0, q.t1}); vertexData.emplace_back(glm::vec2{q.x0, q.y1}, glm::vec4{color & 0x00FF0000, color & 0x0000FF00, color & 0x000000FF, 0xFFFFFFFF}, 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);
@@ -64,7 +64,7 @@ namespace mlx
void TextPutPipeline::init(Renderer* renderer) noexcept void TextPutPipeline::init(Renderer* renderer) noexcept
{ {
_renderer = renderer; _renderer = renderer;
stbtt_BakeFontBitmap(opensans_regular_ttf, 0, 18.0f, tmp_bitmap, 512, 512, 32, 96, _cdata.data()); stbtt_BakeFontBitmap(dogica_ttf, 0, 6.0f, tmp_bitmap, 512, 512, 32, 96, _cdata.data());
_atlas.create(tmp_bitmap, 512, 512, VK_FORMAT_R8_UNORM); _atlas.create(tmp_bitmap, 512, 512, VK_FORMAT_R8_UNORM);
_atlas.setDescriptor(renderer->getFragDescriptorSet().duplicate()); _atlas.setDescriptor(renderer->getFragDescriptorSet().duplicate());
} }

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/04/11 12:24:59 by maldavid ### ########.fr */ /* Updated: 2023/04/11 18:36:53 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -6,11 +6,12 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 14:24:00 by maldavid #+# #+# */ /* Created: 2023/04/01 14:24:00 by maldavid #+# #+# */
/* Updated: 2023/04/01 15:32:35 by maldavid ### ########.fr */ /* Updated: 2023/04/11 18:30:30 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <core/errors.h> #include <core/errors.h>
#include <algorithm>
#include <renderer/texture_library.h> #include <renderer/texture_library.h>
namespace mlx namespace mlx
@@ -24,6 +25,12 @@ namespace mlx
TextureID TextureLibrary::addTextureToLibrary(std::shared_ptr<Texture> texture) TextureID TextureLibrary::addTextureToLibrary(std::shared_ptr<Texture> texture)
{ {
auto it = std::find_if(_cache.begin(), _cache.end(), [=](const std::pair<TextureID, std::shared_ptr<Texture>>& v)
{
return v.second == texture;
});
if(it != _cache.end())
return it->first;
_cache[_current_id] = texture; _cache[_current_id] = texture;
_current_id++; _current_id++;
return _current_id - 1; return _current_id - 1;

2843
src/utils/dogica_ttf.h git.filemode.normal_file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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: 2023/04/11 12:50:58 by maldavid ### ########.fr */ /* Updated: 2023/04/11 19:15:35 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -73,12 +73,13 @@ int main(void)
void *img; void *img;
mlx.mlx = mlx_init(); mlx.mlx = mlx_init();
mlx.win = mlx_new_window(mlx.mlx, 1400, 800, "My window"); mlx.win = mlx_new_window(mlx.mlx, 400, 400, "My window");
mlx.logo = mlx_png_file_to_image(mlx.mlx, "42_logo.png", &w, &h); mlx.logo = mlx_png_file_to_image(mlx.mlx, "42_logo.png", &w, &h);
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, 200, 200); mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 200, 200);
img = create_image(&mlx); img = create_image(&mlx);
mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFFFF0000, "this is a text"); mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFF0000FF, "this is a text");
mlx_string_put(mlx.mlx, mlx.win, 20, 50, 0xFFFFFFFF, "this is another text");
mlx_put_image_to_window(mlx.mlx, mlx.win, img, 200, 20); mlx_put_image_to_window(mlx.mlx, mlx.win, img, 200, 20);
mlx_loop_hook(mlx.mlx, update, &mlx); mlx_loop_hook(mlx.mlx, update, &mlx);
mlx_loop(mlx.mlx); mlx_loop(mlx.mlx);