add TextNote
This commit is contained in:
parent
7b4ddfd278
commit
db565d23a7
19
src/graphics/render/TextNote.cpp
Normal file
19
src/graphics/render/TextNote.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "TextNote.hpp"
|
||||||
|
|
||||||
|
TextNote::TextNote(std::wstring text, NotePreset preset, glm::vec3 position)
|
||||||
|
: text(std::move(text)),
|
||||||
|
preset(std::move(preset)),
|
||||||
|
position(std::move(position)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::wstring& TextNote::getText() const {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NotePreset& TextNote::getPreset() const {
|
||||||
|
return preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
const glm::vec3& TextNote::getPosition() const {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
18
src/graphics/render/TextNote.hpp
Normal file
18
src/graphics/render/TextNote.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "presets/NotePreset.hpp"
|
||||||
|
|
||||||
|
/// @brief 3D text instance
|
||||||
|
class TextNote {
|
||||||
|
std::wstring text;
|
||||||
|
NotePreset preset;
|
||||||
|
glm::vec3 position;
|
||||||
|
public:
|
||||||
|
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);
|
||||||
|
|
||||||
|
const std::wstring& getText() const;
|
||||||
|
|
||||||
|
const NotePreset& getPreset() const;
|
||||||
|
|
||||||
|
const glm::vec3& getPosition() const;
|
||||||
|
};
|
||||||
@ -32,6 +32,7 @@
|
|||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/LevelEvents.hpp"
|
#include "world/LevelEvents.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
|
#include "presets/NotePreset.hpp"
|
||||||
#include "graphics/commons/Model.hpp"
|
#include "graphics/commons/Model.hpp"
|
||||||
#include "graphics/core/Atlas.hpp"
|
#include "graphics/core/Atlas.hpp"
|
||||||
#include "graphics/core/Batch3D.hpp"
|
#include "graphics/core/Batch3D.hpp"
|
||||||
@ -47,6 +48,7 @@
|
|||||||
#include "ModelBatch.hpp"
|
#include "ModelBatch.hpp"
|
||||||
#include "Skybox.hpp"
|
#include "Skybox.hpp"
|
||||||
#include "Emitter.hpp"
|
#include "Emitter.hpp"
|
||||||
|
#include "TextNote.hpp"
|
||||||
|
|
||||||
bool WorldRenderer::showChunkBorders = false;
|
bool WorldRenderer::showChunkBorders = false;
|
||||||
bool WorldRenderer::showEntitiesDebug = false;
|
bool WorldRenderer::showEntitiesDebug = false;
|
||||||
@ -162,11 +164,16 @@ void WorldRenderer::drawChunks(
|
|||||||
if (culling) {
|
if (culling) {
|
||||||
frustumCulling->update(camera.getProjView());
|
frustumCulling->update(camera.getProjView());
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks->visible = 0;
|
chunks->visible = 0;
|
||||||
|
if (GLEW_ARB_multi_draw_indirect && false) {
|
||||||
|
// TODO: implement Multi Draw Indirect chunks draw
|
||||||
|
} else {
|
||||||
for (size_t i = 0; i < indices.size(); i++) {
|
for (size_t i = 0; i < indices.size(); i++) {
|
||||||
chunks->visible += drawChunk(indices[i].index, camera, shader, culling);
|
chunks->visible += drawChunk(indices[i].index, camera, shader, culling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WorldRenderer::setupWorldShader(
|
void WorldRenderer::setupWorldShader(
|
||||||
Shader& shader,
|
Shader& shader,
|
||||||
@ -412,36 +419,71 @@ void WorldRenderer::renderHands(
|
|||||||
skybox->unbind();
|
skybox->unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldRenderer::renderText(
|
||||||
|
const TextNote& note,
|
||||||
|
const DrawContext& context,
|
||||||
|
const Assets& assets,
|
||||||
|
const Camera& camera,
|
||||||
|
const EngineSettings& settings,
|
||||||
|
bool hudVisible
|
||||||
|
) {
|
||||||
|
auto& font = assets.require<Font>("normal");
|
||||||
|
|
||||||
|
const auto& text = note.getText();
|
||||||
|
const auto& preset = note.getPreset();
|
||||||
|
const auto& pos = note.getPosition();
|
||||||
|
|
||||||
|
glm::vec3 xvec {1, 0, 0};
|
||||||
|
glm::vec3 yvec {0, 1, 0};
|
||||||
|
|
||||||
|
if (preset.displayMode == NoteDisplayMode::Y_FREE_BILLBOARD ||
|
||||||
|
preset.displayMode == NoteDisplayMode::XY_FREE_BILLBOARD) {
|
||||||
|
xvec = camera.position - pos;
|
||||||
|
xvec.y = 0;
|
||||||
|
std::swap(xvec.x, xvec.z);
|
||||||
|
xvec.z *= -1;
|
||||||
|
xvec = glm::normalize(xvec);
|
||||||
|
if (preset.displayMode == NoteDisplayMode::XY_FREE_BILLBOARD) {
|
||||||
|
yvec = camera.up;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float ppbx = 100;
|
||||||
|
float ppby = 100;
|
||||||
|
font.draw(
|
||||||
|
*batch3d,
|
||||||
|
text,
|
||||||
|
pos - xvec * (font.calcWidth(text, text.length()) * 0.5f) / ppbx,
|
||||||
|
xvec / ppbx,
|
||||||
|
yvec / ppby
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldRenderer::renderTexts(
|
void WorldRenderer::renderTexts(
|
||||||
const DrawContext& context,
|
const DrawContext& context,
|
||||||
const Camera& camera,
|
const Camera& camera,
|
||||||
const EngineSettings& settings,
|
const EngineSettings& settings,
|
||||||
bool hudVisible
|
bool hudVisible
|
||||||
) {
|
) {
|
||||||
|
NotePreset preset;
|
||||||
|
preset.displayMode = NoteDisplayMode::Y_FREE_BILLBOARD;
|
||||||
|
|
||||||
|
TextNote note(
|
||||||
|
L"Segmentation fault (core dumped)",
|
||||||
|
std::move(preset),
|
||||||
|
glm::vec3(0, 100, 0)
|
||||||
|
);
|
||||||
|
|
||||||
const auto& assets = *engine->getAssets();
|
const auto& assets = *engine->getAssets();
|
||||||
auto& shader = assets.require<Shader>("ui3d");
|
auto& shader = assets.require<Shader>("ui3d");
|
||||||
auto& font = assets.require<Font>("normal");
|
|
||||||
shader.use();
|
shader.use();
|
||||||
shader.uniformMatrix("u_projview", camera.getProjView());
|
shader.uniformMatrix("u_projview", camera.getProjView());
|
||||||
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||||
batch3d->begin();
|
batch3d->begin();
|
||||||
std::wstring string = L"Segmentation fault (core dumped)";
|
|
||||||
glm::vec3 pos(0, 100, 0);
|
|
||||||
auto zvec = camera.position - pos;
|
|
||||||
zvec.y = 0;
|
|
||||||
std::swap(zvec.x, zvec.z);
|
|
||||||
zvec.z *= -1;
|
|
||||||
zvec = glm::normalize(zvec);
|
|
||||||
|
|
||||||
float ppbx = 100;
|
renderText(note, context, assets, camera, settings, hudVisible);
|
||||||
float ppby = 100;
|
|
||||||
font.draw(
|
|
||||||
*batch3d,
|
|
||||||
string,
|
|
||||||
pos - zvec * (font.calcWidth(string, string.length()) * 0.5f) / ppbx,
|
|
||||||
zvec / ppbx,
|
|
||||||
camera.up / ppby
|
|
||||||
);
|
|
||||||
batch3d->flush();
|
batch3d->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class DrawContext;
|
|||||||
class ModelBatch;
|
class ModelBatch;
|
||||||
class Assets;
|
class Assets;
|
||||||
class Emitter;
|
class Emitter;
|
||||||
|
class TextNote;
|
||||||
struct EngineSettings;
|
struct EngineSettings;
|
||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
@ -92,6 +93,15 @@ class WorldRenderer {
|
|||||||
float fogFactor
|
float fogFactor
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void renderText(
|
||||||
|
const TextNote& note,
|
||||||
|
const DrawContext& context,
|
||||||
|
const Assets& assets,
|
||||||
|
const Camera& camera,
|
||||||
|
const EngineSettings& settings,
|
||||||
|
bool hudVisible
|
||||||
|
);
|
||||||
|
|
||||||
void renderTexts(
|
void renderTexts(
|
||||||
const DrawContext& context,
|
const DrawContext& context,
|
||||||
const Camera& camera,
|
const Camera& camera,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user