add more NotePreset properties
This commit is contained in:
@@ -125,7 +125,7 @@ void Batch3D::sprite(
|
||||
float h,
|
||||
int atlasRes,
|
||||
int index,
|
||||
glm::vec4 tint
|
||||
const glm::vec4& tint
|
||||
) {
|
||||
float scale = 1.0f / static_cast<float>(atlasRes);
|
||||
float u = (index % atlasRes) * scale;
|
||||
@@ -288,3 +288,11 @@ void Batch3D::flushPoints() {
|
||||
mesh->draw(GL_POINTS);
|
||||
index = 0;
|
||||
}
|
||||
|
||||
void Batch3D::setColor(const glm::vec4& color) {
|
||||
tint = color;
|
||||
}
|
||||
|
||||
const glm::vec4& Batch3D::getColor() const {
|
||||
return tint;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class Batch3D : public Flushable {
|
||||
std::unique_ptr<Mesh> mesh;
|
||||
std::unique_ptr<Texture> blank;
|
||||
size_t index;
|
||||
glm::vec4 tint {1.0f};
|
||||
|
||||
const Texture* currentTexture;
|
||||
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
float h,
|
||||
int atlasRes,
|
||||
int index,
|
||||
glm::vec4 tint
|
||||
const glm::vec4& tint
|
||||
);
|
||||
void xSprite(
|
||||
float w,
|
||||
@@ -91,4 +92,7 @@ public:
|
||||
void point(const glm::vec3& pos, const glm::vec4& tint);
|
||||
void flush() override;
|
||||
void flushPoints();
|
||||
|
||||
void setColor(const glm::vec4& color);
|
||||
const glm::vec4& getColor() const;
|
||||
};
|
||||
|
||||
@@ -81,7 +81,7 @@ static inline void draw_glyph(
|
||||
0.5f,
|
||||
16,
|
||||
c,
|
||||
glm::vec4(1.0f)
|
||||
batch.getColor()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -427,15 +427,25 @@ void WorldRenderer::renderText(
|
||||
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();
|
||||
|
||||
if (util::distance2(pos, camera.position) >
|
||||
util::sqr(preset.renderDistance / camera.zoom)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Projected notes are displayed on the front layer only
|
||||
if (preset.displayMode == NoteDisplayMode::PROJECTED) {
|
||||
return;
|
||||
}
|
||||
auto& font = assets.require<Font>("normal");
|
||||
|
||||
glm::vec3 xvec {1, 0, 0};
|
||||
glm::vec3 yvec {0, 1, 0};
|
||||
|
||||
int width = font.calcWidth(text, text.length());
|
||||
if (preset.displayMode == NoteDisplayMode::Y_FREE_BILLBOARD ||
|
||||
preset.displayMode == NoteDisplayMode::XY_FREE_BILLBOARD) {
|
||||
xvec = camera.position - pos;
|
||||
@@ -447,13 +457,22 @@ void WorldRenderer::renderText(
|
||||
yvec = camera.up;
|
||||
}
|
||||
}
|
||||
|
||||
if (preset.displayMode != NoteDisplayMode::PROJECTED) {
|
||||
if (!frustumCulling->isBoxVisible(pos - xvec * (width * 0.5f),
|
||||
pos + xvec * (width * 0.5f))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
float ppbx = 100;
|
||||
float ppby = 100;
|
||||
float ppbx = 1.0f / preset.scale;
|
||||
float ppby = 1.0f / preset.scale;
|
||||
|
||||
batch3d->setColor(preset.color);
|
||||
font.draw(
|
||||
*batch3d,
|
||||
text,
|
||||
pos - xvec * (font.calcWidth(text, text.length()) * 0.5f) / ppbx,
|
||||
pos - xvec * (width * 0.5f) / ppbx,
|
||||
xvec / ppbx,
|
||||
yvec / ppby
|
||||
);
|
||||
@@ -463,15 +482,19 @@ void WorldRenderer::renderTexts(
|
||||
const DrawContext& context,
|
||||
const Camera& camera,
|
||||
const EngineSettings& settings,
|
||||
bool hudVisible
|
||||
bool hudVisible,
|
||||
bool frontLayer
|
||||
) {
|
||||
std::vector<TextNote> notes;
|
||||
NotePreset preset;
|
||||
preset.displayMode = NoteDisplayMode::Y_FREE_BILLBOARD;
|
||||
preset.displayMode = NoteDisplayMode::STATIC_BILLBOARD;
|
||||
preset.color = glm::vec4(0, 0, 0, 1);
|
||||
preset.scale = 0.005f;
|
||||
|
||||
TextNote note(
|
||||
L"Segmentation fault (core dumped)",
|
||||
notes.emplace_back(
|
||||
L"Segmentation fault",
|
||||
std::move(preset),
|
||||
glm::vec3(0, 100, 0)
|
||||
glm::vec3(0.5f, 99.5f, 0.0015f)
|
||||
);
|
||||
|
||||
const auto& assets = *engine->getAssets();
|
||||
@@ -482,8 +505,9 @@ void WorldRenderer::renderTexts(
|
||||
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||
batch3d->begin();
|
||||
|
||||
renderText(note, context, assets, camera, settings, hudVisible);
|
||||
|
||||
for (const auto& note : notes) {
|
||||
renderText(note, context, assets, camera, settings, hudVisible);
|
||||
}
|
||||
batch3d->flush();
|
||||
}
|
||||
|
||||
@@ -523,7 +547,7 @@ void WorldRenderer::draw(
|
||||
DrawContext ctx = wctx.sub();
|
||||
ctx.setDepthTest(true);
|
||||
ctx.setCullFace(true);
|
||||
renderTexts(ctx, camera, settings, hudVisible);
|
||||
renderTexts(ctx, camera, settings, hudVisible, false);
|
||||
renderLevel(ctx, camera, settings, delta, pause);
|
||||
// Debug lines
|
||||
if (hudVisible) {
|
||||
|
||||
@@ -106,7 +106,8 @@ class WorldRenderer {
|
||||
const DrawContext& context,
|
||||
const Camera& camera,
|
||||
const EngineSettings& settings,
|
||||
bool hudVisible
|
||||
bool hudVisible,
|
||||
bool frontLayer
|
||||
);
|
||||
public:
|
||||
std::unique_ptr<ParticlesRenderer> particles;
|
||||
|
||||
Reference in New Issue
Block a user