mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Do things
This commit is contained in:
parent
69dae9ab42
commit
d8911df619
@ -221,7 +221,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE dependencies/stb)
|
|||||||
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
|
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
|
||||||
set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
|
set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
|
||||||
set(ASSIMP_BUILD_ZLIB ON CACHE INTERNAL "" FORCE)
|
set(ASSIMP_BUILD_ZLIB ON CACHE INTERNAL "" FORCE)
|
||||||
set(ASSIMP_NO_EXPORT OFF CACHE INTERNAL "" FORCE)
|
set(ASSIMP_NO_EXPORT ON CACHE INTERNAL "" FORCE)
|
||||||
set(ASSIMP_INSTALL OFF CACHE INTERNAL "" FORCE)
|
set(ASSIMP_INSTALL OFF CACHE INTERNAL "" FORCE)
|
||||||
add_subdirectory(dependencies/assimp)
|
add_subdirectory(dependencies/assimp)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE dependencies/assimp/include)
|
target_include_directories(${PROJECT_NAME} PRIVATE dependencies/assimp/include)
|
||||||
|
@ -19,10 +19,20 @@ public:
|
|||||||
Font(const std::filesystem::path& resPath);
|
Font(const std::filesystem::path& resPath);
|
||||||
~Font() override;
|
~Font() override;
|
||||||
|
|
||||||
|
struct CharData {
|
||||||
|
glm::vec2 atlas_top_left{};
|
||||||
|
glm::vec2 atlas_bottom_right{};
|
||||||
|
glm::vec2 offset{};
|
||||||
|
float xAdvance{};
|
||||||
|
};
|
||||||
|
|
||||||
const gfx::Texture* getAtlasTexture();
|
const gfx::Texture* getAtlasTexture();
|
||||||
|
|
||||||
|
CharData getCharData(uint32_t charCode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const gfx::Texture* m_atlas;
|
const gfx::Texture* m_atlas;
|
||||||
|
std::map<uint32_t, CharData> m_charData;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ UI::UI(Object* parent) : Component(parent, TypeEnum::UI)
|
|||||||
{ { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f } },
|
{ { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f } },
|
||||||
{ { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 1.0f } }
|
{ { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 1.0f } }
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI::~UI()
|
UI::~UI()
|
||||||
@ -33,13 +32,25 @@ void UI::render(glm::mat4 transform, glm::mat4 view)
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
glm::mat4 m;
|
glm::mat4 m;
|
||||||
|
glm::vec2 atlas_top_left;
|
||||||
|
glm::vec2 atlas_bottom_right;
|
||||||
glm::vec2 offset;
|
glm::vec2 offset;
|
||||||
glm::vec2 size;
|
glm::vec2 size;
|
||||||
} pushConsts{};
|
} pushConsts{};
|
||||||
|
|
||||||
pushConsts.m = glm::mat4{1.0f};
|
int advance = 0;
|
||||||
|
|
||||||
gfxdev->draw(m_shader->getPipeline(), m_atlasMesh->vb, m_atlasMesh->ib, m_atlasMesh->m_indices.size(), &pushConsts, sizeof(pushConsts), m_font->getAtlasTexture());
|
for (char c : m_text) {
|
||||||
|
auto charData = m_font->getCharData(c);
|
||||||
|
pushConsts.m = glm::mat4{1.0f};
|
||||||
|
pushConsts.atlas_top_left = charData.atlas_top_left;
|
||||||
|
pushConsts.atlas_bottom_right = charData.atlas_bottom_right;
|
||||||
|
pushConsts.offset = charData.offset;
|
||||||
|
gfxdev->draw(
|
||||||
|
m_shader->getPipeline(), m_atlasMesh->vb, m_atlasMesh->ib, m_atlasMesh->m_indices.size(),
|
||||||
|
&pushConsts, sizeof(pushConsts), m_font->getAtlasTexture());
|
||||||
|
advance += charData.xAdvance;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,15 @@ Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font")
|
|||||||
// TODO: load font
|
// TODO: load font
|
||||||
auto fontBuffer = util::readBinaryFile(resPath.string());
|
auto fontBuffer = util::readBinaryFile(resPath.string());
|
||||||
|
|
||||||
|
constexpr int FIRST_CHAR = 32;
|
||||||
|
constexpr int NUM_CHARS = 96;
|
||||||
|
|
||||||
constexpr int BITMAP_WIDTH = 1024;
|
constexpr int BITMAP_WIDTH = 1024;
|
||||||
constexpr int BITMAP_HEIGHT = 1024;
|
constexpr int BITMAP_HEIGHT = 1024;
|
||||||
auto pixels = std::make_unique<unsigned char[]>(BITMAP_WIDTH * BITMAP_HEIGHT);
|
auto pixels = std::make_unique<unsigned char[]>(BITMAP_WIDTH * BITMAP_HEIGHT);
|
||||||
auto chardata = std::make_unique<stbtt_bakedchar[]>(96);
|
auto bakedChars = std::make_unique<stbtt_bakedchar[]>(NUM_CHARS);
|
||||||
|
|
||||||
stbtt_BakeFontBitmap(fontBuffer->data(), 0, 128.0f, pixels.get(), BITMAP_WIDTH, BITMAP_HEIGHT, 32, 96, chardata.get());
|
stbtt_BakeFontBitmap(fontBuffer->data(), 0, 128.0f, pixels.get(), BITMAP_WIDTH, BITMAP_HEIGHT, FIRST_CHAR, NUM_CHARS, bakedChars.get());
|
||||||
|
|
||||||
auto textureData = std::make_unique<uint8_t[]>(BITMAP_WIDTH * BITMAP_HEIGHT * 4);
|
auto textureData = std::make_unique<uint8_t[]>(BITMAP_WIDTH * BITMAP_HEIGHT * 4);
|
||||||
|
|
||||||
@ -34,6 +37,16 @@ Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font")
|
|||||||
|
|
||||||
m_atlas = gfxdev->createTexture(textureData.get(), BITMAP_WIDTH, BITMAP_HEIGHT, gfx::TextureFilter::LINEAR, gfx::TextureFilter::LINEAR);
|
m_atlas = gfxdev->createTexture(textureData.get(), BITMAP_WIDTH, BITMAP_HEIGHT, gfx::TextureFilter::LINEAR, gfx::TextureFilter::LINEAR);
|
||||||
|
|
||||||
|
for (int i = FIRST_CHAR; i < NUM_CHARS; i++) {
|
||||||
|
CharData charData{};
|
||||||
|
charData.atlas_top_left = { bakedChars[i].x0, bakedChars[i].y0 };
|
||||||
|
charData.atlas_bottom_right = { bakedChars[i].x1, bakedChars[i].y1 };
|
||||||
|
charData.offset = { bakedChars[i].xoff, bakedChars[i].yoff };
|
||||||
|
charData.xAdvance = bakedChars[i].xadvance;
|
||||||
|
m_charData[i] = charData;
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::~Font()
|
Font::~Font()
|
||||||
@ -46,4 +59,9 @@ const gfx::Texture* Font::getAtlasTexture()
|
|||||||
return m_atlas;
|
return m_atlas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Font::CharData Font::getCharData(uint32_t charCode)
|
||||||
|
{
|
||||||
|
return m_charData[charCode];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "components/mesh_renderer.hpp"
|
#include "components/mesh_renderer.hpp"
|
||||||
|
|
||||||
|
#include "resource_manager.hpp"
|
||||||
|
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/LogStream.hpp>
|
#include <assimp/LogStream.hpp>
|
||||||
#include <assimp/Logger.hpp>
|
#include <assimp/Logger.hpp>
|
||||||
@ -17,6 +19,7 @@
|
|||||||
|
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace engine::util {
|
namespace engine::util {
|
||||||
@ -162,7 +165,11 @@ namespace engine::util {
|
|||||||
std::filesystem::path absPath = path;
|
std::filesystem::path absPath = path;
|
||||||
absPath = absPath.parent_path();
|
absPath = absPath.parent_path();
|
||||||
absPath /= texPath.C_Str();
|
absPath /= texPath.C_Str();
|
||||||
textures[i] = std::make_shared<resources::Texture>(absPath);
|
try {
|
||||||
|
textures[i] = std::make_shared<resources::Texture>(absPath);
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
textures[i] = parent->res.get<resources::Texture>("textures/white.png");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,8 +165,12 @@ void playGame()
|
|||||||
plane->transform.position = { -30.0f, 2.0f, 10.0f };
|
plane->transform.position = { -30.0f, 2.0f, 10.0f };
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
auto van = engine::util::loadAssimpMeshFromFile(app.scene(), app.resources()->getFilePath("models/van/van.dae").string());
|
||||||
|
|
||||||
|
/*
|
||||||
auto lego = engine::util::loadAssimpMeshFromFile(app.scene(), app.resources()->getFilePath("models/lego/lego.dae").string());
|
auto lego = engine::util::loadAssimpMeshFromFile(app.scene(), app.resources()->getFilePath("models/lego/lego.dae").string());
|
||||||
lego->transform.position = { -30.0f, -33.0f, -30.0f };
|
lego->transform.position = { -30.0f, -33.0f, -30.0f };
|
||||||
|
*/
|
||||||
|
|
||||||
app.scene()->printTree();
|
app.scene()->printTree();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user