Riyyi
2 years ago
79 changed files with 270 additions and 6 deletions
@ -1,8 +1,8 @@
|
||||
file(GLOB_RECURSE ENGINE_SOURCES "src/*.cpp") |
||||
file(GLOB_RECURSE ENGINE_SOURCES "${ENGINE}/*.cpp") |
||||
|
||||
add_library(${ENGINE} ${ENGINE_SOURCES}) |
||||
target_include_directories(${ENGINE} PRIVATE |
||||
"src" |
||||
"${CMAKE_SOURCE_DIR}/src" |
||||
"${CMAKE_SOURCE_DIR}/vendor/entt/src" |
||||
"${CMAKE_SOURCE_DIR}/vendor/glad/include" |
||||
"${CMAKE_SOURCE_DIR}/vendor/glfw/include" |
@ -0,0 +1,32 @@
|
||||
#ifndef TEXTAREA_COMPONENT_H |
||||
#define TEXTAREA_COMPONENT_H |
||||
|
||||
#include <cstdint> // uint32_t |
||||
#include <string> // std::string |
||||
#include <utility> // std::move |
||||
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4 |
||||
|
||||
namespace Inferno { |
||||
|
||||
struct TextAreaComponent { |
||||
std::string content { "" }; |
||||
std::string font { "" }; |
||||
uint32_t fontSize { 0 }; |
||||
uint32_t width { 0 }; |
||||
uint32_t lines { 0 }; |
||||
|
||||
TextAreaComponent() {} |
||||
TextAreaComponent(const std::string& content, const std::string& font, |
||||
uint32_t fontSize, uint32_t width, uint32_t lines) |
||||
: content(std::move(content)), font(std::move(font)), fontSize(fontSize), width(width), lines(lines) {} |
||||
|
||||
// booleans?
|
||||
// glm::vec4 outlineColor { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
// glow?
|
||||
// float dropShadow { 0.0f };
|
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // TEXTAREA_COMPONENT_H
|
@ -0,0 +1,15 @@
|
||||
#include "inferno/render/framebuffer.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
Framebuffer::Framebuffer() |
||||
{ |
||||
} |
||||
|
||||
Framebuffer::~Framebuffer() |
||||
{ |
||||
} |
||||
|
||||
// -----------------------------------------
|
||||
|
||||
} // namespace Inferno
|
@ -0,0 +1,14 @@
|
||||
#ifndef FRAMEBUFFER_H |
||||
#define FRAMEBUFFER_H |
||||
|
||||
namespace Inferno { |
||||
|
||||
class Framebuffer { |
||||
public: |
||||
Framebuffer(); |
||||
virtual ~Framebuffer(); |
||||
}; |
||||
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // FRAMEBUFFER_H
|
@ -0,0 +1,7 @@
|
||||
#include "inferno/render/renderer3d.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
//..
|
||||
|
||||
} // namespace Inferno
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Riyyi |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
||||
* this software and associated documentation files (the "Software"), to deal in |
||||
* the Software without restriction, including without limitation the rights to |
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||||
* the Software, and to permit persons to whom the Software is furnished to do so, |
||||
* subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in all |
||||
* copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef RENDERER_3D_H |
||||
#define RENDERER_3D_H |
||||
|
||||
namespace Inferno { |
||||
|
||||
class Renderer3D { |
||||
public: |
||||
Renderer3D(); |
||||
virtual ~Renderer3D(); |
||||
}; |
||||
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // RENDERER_3D_H
|
||||
|
||||
// - what data do you need?
|
||||
// - gltf
|
||||
// - how are we going to batch
|
||||
// - mesh (gltf) -> material -> shader rendering
|
@ -0,0 +1,117 @@
|
||||
#include "inferno/application.h" |
||||
#include "inferno/assert.h" |
||||
#include "inferno/component/textareacomponent.h" |
||||
#include "inferno/render/font.h" |
||||
#include "inferno/render/renderer.h" |
||||
#include "inferno/render/texture.h" |
||||
#include "inferno/scene/scene.h" |
||||
#include "inferno/system/textareasystem.h" |
||||
#include "inferno/window.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
TextAreaSystem::TextAreaSystem(s) |
||||
{ |
||||
info() << "TextAreaSystem initialized"; |
||||
} |
||||
|
||||
TextAreaSystem::~TextAreaSystem() |
||||
{ |
||||
} |
||||
|
||||
void TextAreaSystem::render() |
||||
{ |
||||
auto view = m_scene->registry()->view<TransformComponent, TextAreaComponent>(); |
||||
|
||||
glm::ivec2 viewport = { |
||||
Application::the().getWindow().getWidth(), |
||||
Application::the().getWindow().getHeight(), |
||||
}; |
||||
|
||||
for (auto [entity, transform, textarea] : view.each()) { |
||||
// Loop through textareas content
|
||||
// Linebreak if width reached
|
||||
// Break if lines AND width reached
|
||||
// Calculate character quad
|
||||
// Submit character quad for rendering
|
||||
|
||||
std::shared_ptr<Font> font = FontManager::the().load(textarea.font); |
||||
// glm::mat4 translate = transform.translate;
|
||||
|
||||
float advance = 0.0f; |
||||
for (auto character : textarea.content) { |
||||
std::optional<CharacterQuad> quad = calculateCharacterQuad(character, font, advance); |
||||
|
||||
if (quad) { |
||||
RendererCharacter::the().drawCharacter(quad.value(), font->texture()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
std::optional<CharacterQuad> TextAreaSystem::calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance) |
||||
{ |
||||
CharacterQuad characterQuad; |
||||
|
||||
auto c = font->get(character); |
||||
|
||||
// Texture
|
||||
// ---------------------------------
|
||||
|
||||
float textureWidth = static_cast<float>(font->texture()->width()); |
||||
float textureHeight = static_cast<float>(font->texture()->height()); |
||||
ASSERT(textureWidth == textureHeight, "TextAreaSystem read invalid font texture"); |
||||
|
||||
// Skip empty characters
|
||||
if (c->size.x == 0 || c->size.y == 0) { |
||||
// Jump to the next glyph
|
||||
advance += c->advance / textureWidth; |
||||
return {}; |
||||
} |
||||
|
||||
// Position
|
||||
// ---------------------------------
|
||||
|
||||
float quadWidth = c->size.x / textureWidth; |
||||
float quadHeight = c->size.y / textureHeight; |
||||
characterQuad.at(0).quad.position = { -quadWidth, -quadHeight, 0.0f }; // bottom left
|
||||
characterQuad.at(1).quad.position = { quadWidth, -quadHeight, 0.0f }; // bottom right
|
||||
characterQuad.at(2).quad.position = { quadWidth, quadHeight, 0.0f }; // top right
|
||||
characterQuad.at(3).quad.position = { -quadWidth, quadHeight, 0.0f }; // top left
|
||||
|
||||
for (auto& quad : characterQuad) { |
||||
quad.quad.position.x -= 0.5f; |
||||
|
||||
quad.quad.position.x += c->offset.x / (float)textureWidth; |
||||
quad.quad.position.y -= c->offset.y / (float)textureHeight; |
||||
|
||||
quad.quad.position.x += advance; |
||||
} |
||||
|
||||
// dbgln("character: {} ({}) width: {} height: {} advance: {} x: {}",
|
||||
// character, (int)character, quadWidth, quadHeight, advance, characterQuad.at(0).quad.position.x);
|
||||
|
||||
// Jump to the next glyph
|
||||
advance += c->advance / textureWidth; |
||||
|
||||
// Texture coordinates
|
||||
// ---------------------------------
|
||||
|
||||
glm::vec2 x { |
||||
1 - (textureWidth - c->position.x) / textureWidth, |
||||
1 - (textureWidth - c->position.x - c->size.x) / textureWidth |
||||
}; |
||||
glm::vec2 y { |
||||
(textureHeight - c->position.y - c->size.y) / textureHeight, |
||||
(textureHeight - c->position.y) / textureHeight |
||||
}; |
||||
|
||||
characterQuad.at(0).quad.textureCoordinates = { x.x, y.x }; |
||||
characterQuad.at(1).quad.textureCoordinates = { x.y, y.x }; |
||||
characterQuad.at(2).quad.textureCoordinates = { x.y, y.y }; |
||||
characterQuad.at(3).quad.textureCoordinates = { x.x, y.y }; |
||||
|
||||
return characterQuad; |
||||
} |
||||
|
||||
} // namespace Inferno
|
@ -0,0 +1,39 @@
|
||||
#ifndef TEXTAREA_H |
||||
#define TEXTAREA_H |
||||
|
||||
#include <cstdint> // std::uint32_t |
||||
#include <memory> // std::shared_ptr |
||||
#include <optional> // std::optional |
||||
#include <vector> // std::vector |
||||
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3 |
||||
|
||||
#include "inferno/render/renderer.h" |
||||
#include "inferno/singleton.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
using CharacterQuad = std::array<CharacterVertex, Renderer::vertexPerQuad>; |
||||
|
||||
class Font; |
||||
class Scene; |
||||
|
||||
class TextAreaSystem final : public Singleton<TextAreaSystem> { |
||||
public: |
||||
TextAreaSystem(s); |
||||
virtual ~TextAreaSystem(); |
||||
|
||||
void render(); |
||||
|
||||
void setScene(Scene* scene) { m_scene = scene; } |
||||
|
||||
private: |
||||
std::optional<CharacterQuad> calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance); |
||||
|
||||
Scene* m_scene { nullptr }; |
||||
}; |
||||
|
||||
} // namespace Inferno
|
||||
|
||||
|
||||
#endif // TEXTAREA_H
|
Loading…
Reference in new issue