give more meaningful names
This commit is contained in:
@@ -8,7 +8,7 @@ include(cmake/SetupVulkan.cmake)
|
|||||||
include(cmake/Filter.cmake)
|
include(cmake/Filter.cmake)
|
||||||
include(cmake/AppleHelper.cmake)
|
include(cmake/AppleHelper.cmake)
|
||||||
include(cmake/SetShaderDependency.cmake)
|
include(cmake/SetShaderDependency.cmake)
|
||||||
include(cmake/CopyResources.cmake)
|
include(cmake/CopyResourcesToExe.cmake)
|
||||||
|
|
||||||
set(DEPENDENCY_MIRROR_FILE "DependencyMirrors.txt" CACHE STRING "Dependency mirror")
|
set(DEPENDENCY_MIRROR_FILE "DependencyMirrors.txt" CACHE STRING "Dependency mirror")
|
||||||
VarsFromFile("${DEPENDENCY_MIRROR_FILE}") # Load mirror list (for CICD)
|
VarsFromFile("${DEPENDENCY_MIRROR_FILE}") # Load mirror list (for CICD)
|
||||||
@@ -108,7 +108,7 @@ if (WIN32)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
SetupVulkan(openVulkanoCpp)
|
SetupVulkan(openVulkanoCpp)
|
||||||
CopyResources(openVulkanoCpp "${CMAKE_CURRENT_SOURCE_DIR}/fonts" ".ttf")
|
CopyResourcesToExe(openVulkanoCpp "${CMAKE_CURRENT_SOURCE_DIR}/fonts" ".ttf")
|
||||||
SetShaderDependency(openVulkanoCpp
|
SetShaderDependency(openVulkanoCpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/openVulkanoCpp/Shader
|
${CMAKE_CURRENT_SOURCE_DIR}/openVulkanoCpp/Shader
|
||||||
${SHADER_OUTPUT_DEST})
|
${SHADER_OUTPUT_DEST})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
function(CopyResources TARGET FROM EXTENSIONS)
|
function(CopyResourcesToExe TARGET FROM EXTENSIONS)
|
||||||
file(GLOB RESOURCES "${FROM}/*")
|
file(GLOB RESOURCES "${FROM}/*")
|
||||||
set(RESOURCES_TO_COPY "")
|
set(RESOURCES_TO_COPY "")
|
||||||
|
|
||||||
@@ -4,13 +4,14 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Text.hpp"
|
#include "TextDrawable.hpp"
|
||||||
#include "Scene/Geometry.hpp"
|
#include "Scene/Geometry.hpp"
|
||||||
#include "Scene/Material.hpp"
|
#include "Scene/Material.hpp"
|
||||||
#include "Scene/Vertex.hpp"
|
#include "Scene/Vertex.hpp"
|
||||||
#include "Scene/UniformBuffer.hpp"
|
#include "Scene/UniformBuffer.hpp"
|
||||||
#include "Scene/FontAtlasGenerator.hpp"
|
#include "Scene/FontAtlasGenerator.hpp"
|
||||||
#include "Base/Logger.hpp"
|
#include "Base/Logger.hpp"
|
||||||
|
#include "utf8.h"
|
||||||
#include "fmt/core.h"
|
#include "fmt/core.h"
|
||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
@@ -18,13 +19,13 @@ namespace OpenVulkano::Scene
|
|||||||
using namespace msdfgen;
|
using namespace msdfgen;
|
||||||
using namespace msdf_atlas;
|
using namespace msdf_atlas;
|
||||||
|
|
||||||
Text::~Text()
|
TextDrawable::~TextDrawable()
|
||||||
{
|
{
|
||||||
delete m_mesh;
|
delete m_mesh;
|
||||||
delete m_material;
|
delete m_material;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||||
{
|
{
|
||||||
if (!m_fontAtlasGenerator)
|
if (!m_fontAtlasGenerator)
|
||||||
{
|
{
|
||||||
@@ -62,9 +63,11 @@ namespace OpenVulkano::Scene
|
|||||||
};
|
};
|
||||||
|
|
||||||
double cursorX = pos.x;
|
double cursorX = pos.x;
|
||||||
for (size_t i = 0; i < text.size(); i++)
|
auto begin = text.begin();
|
||||||
|
auto end = text.end();
|
||||||
|
for (size_t i = 0; begin != end; i++)
|
||||||
{
|
{
|
||||||
unicode_t c = text[i];
|
unicode_t c = utf8::next(begin, end);
|
||||||
if (symbols.find(c) != symbols.end())
|
if (symbols.find(c) != symbols.end())
|
||||||
{
|
{
|
||||||
Bbox glyphBaselineBbox, glyphAtlasBbox;
|
Bbox glyphBaselineBbox, glyphAtlasBbox;
|
||||||
@@ -86,41 +89,42 @@ namespace OpenVulkano::Scene
|
|||||||
double ax = cursorX + bearingX;
|
double ax = cursorX + bearingX;
|
||||||
double ay = pos.y - (h - bearingY);
|
double ay = pos.y - (h - bearingY);
|
||||||
|
|
||||||
m_material->texture = &info.texture;
|
const Texture& atlasTex = m_fontAtlasGenerator->GetAtlas();
|
||||||
|
m_material->texture = const_cast<Texture*>(&atlasTex);
|
||||||
|
|
||||||
m_mesh->vertices[vIdx].position.x = ax;
|
m_mesh->vertices[vIdx].position.x = ax;
|
||||||
m_mesh->vertices[vIdx].position.y = ay;
|
m_mesh->vertices[vIdx].position.y = ay;
|
||||||
m_mesh->vertices[vIdx].position.z = 1;
|
m_mesh->vertices[vIdx].position.z = 1;
|
||||||
m_mesh->vertices[vIdx].textureCoordinates.x = l / info.texture.resolution.x;
|
m_mesh->vertices[vIdx].textureCoordinates.x = l / atlasTex.resolution.x;
|
||||||
m_mesh->vertices[vIdx].textureCoordinates.y = b / info.texture.resolution.y;
|
m_mesh->vertices[vIdx].textureCoordinates.y = b / atlasTex.resolution.y;
|
||||||
|
|
||||||
m_mesh->vertices[vIdx + 1].position.x = ax + w;
|
m_mesh->vertices[vIdx + 1].position.x = ax + w;
|
||||||
m_mesh->vertices[vIdx + 1].position.y = ay;
|
m_mesh->vertices[vIdx + 1].position.y = ay;
|
||||||
m_mesh->vertices[vIdx + 1].position.z = 1;
|
m_mesh->vertices[vIdx + 1].position.z = 1;
|
||||||
m_mesh->vertices[vIdx + 1].textureCoordinates.x = r / info.texture.resolution.x;
|
m_mesh->vertices[vIdx + 1].textureCoordinates.x = r / atlasTex.resolution.x;
|
||||||
m_mesh->vertices[vIdx + 1].textureCoordinates.y = b / info.texture.resolution.y;
|
m_mesh->vertices[vIdx + 1].textureCoordinates.y = b / atlasTex.resolution.y;
|
||||||
|
|
||||||
m_mesh->vertices[vIdx + 2].position.x = ax + w;
|
m_mesh->vertices[vIdx + 2].position.x = ax + w;
|
||||||
m_mesh->vertices[vIdx + 2].position.y = ay + h;
|
m_mesh->vertices[vIdx + 2].position.y = ay + h;
|
||||||
m_mesh->vertices[vIdx + 2].position.z = 1;
|
m_mesh->vertices[vIdx + 2].position.z = 1;
|
||||||
m_mesh->vertices[vIdx + 2].textureCoordinates.x = r / info.texture.resolution.x;
|
m_mesh->vertices[vIdx + 2].textureCoordinates.x = r / atlasTex.resolution.x;
|
||||||
m_mesh->vertices[vIdx + 2].textureCoordinates.y = t / info.texture.resolution.y;
|
m_mesh->vertices[vIdx + 2].textureCoordinates.y = t / atlasTex.resolution.y;
|
||||||
|
|
||||||
m_mesh->vertices[vIdx + 3].position.x = ax;
|
m_mesh->vertices[vIdx + 3].position.x = ax;
|
||||||
m_mesh->vertices[vIdx + 3].position.y = ay + h;
|
m_mesh->vertices[vIdx + 3].position.y = ay + h;
|
||||||
m_mesh->vertices[vIdx + 3].position.z = 1;
|
m_mesh->vertices[vIdx + 3].position.z = 1;
|
||||||
m_mesh->vertices[vIdx + 3].textureCoordinates.x = l / info.texture.resolution.x;
|
m_mesh->vertices[vIdx + 3].textureCoordinates.x = l / atlasTex.resolution.x;
|
||||||
m_mesh->vertices[vIdx + 3].textureCoordinates.y = t / info.texture.resolution.y;
|
m_mesh->vertices[vIdx + 3].textureCoordinates.y = t / atlasTex.resolution.y;
|
||||||
|
|
||||||
m_mesh->SetIndices(indices, 6, 6 * i);
|
m_mesh->SetIndices(indices, 6, 6 * i);
|
||||||
// TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols
|
// TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols
|
||||||
// when setting for depth comparison operator will be available( <= )
|
// when setting for depth comparison operator will be available( <= )
|
||||||
cursorX += info.glyphBox.advance +0.08;
|
cursorX += info.glyphBox.advance + 0.08;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// throw ? replace with ? character (if available) ?
|
// throw ? replace with ? character (if available) ?
|
||||||
Logger::RENDER->error(fmt::format("Could not find glyph for character", c));
|
Logger::RENDER->error(fmt::format("Could not find glyph for character {}", c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,11 +34,11 @@ namespace OpenVulkano::Scene
|
|||||||
//bool sdfMultiChannel = false;
|
//bool sdfMultiChannel = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Text : public SimpleDrawable
|
class TextDrawable : public SimpleDrawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Text() = default;
|
TextDrawable() = default;
|
||||||
~Text();
|
~TextDrawable();
|
||||||
void SetUniformBuffer(UniformBuffer* buffer) { m_uniBuffer = buffer; }
|
void SetUniformBuffer(UniformBuffer* buffer) { m_uniBuffer = buffer; }
|
||||||
void GenerateText(const std::string& text, const Math::Vector3f& pos = Math::Vector3f(0.f));
|
void GenerateText(const std::string& text, const Math::Vector3f& pos = Math::Vector3f(0.f));
|
||||||
void SetConfig(const TextConfig& cfg) { m_cfg = cfg; }
|
void SetConfig(const TextConfig& cfg) { m_cfg = cfg; }
|
||||||
Reference in New Issue
Block a user