Skip to content

Commit

Permalink
Label3DWrapper to wrap Label3D from Scenegraph for use elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffyfreak authored and impaktor committed Dec 17, 2024
1 parent f49d447 commit 2db89c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/graphics/Drawables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "graphics/VertexBuffer.h"
#include "profiler/Profiler.h"

#include <sstream>

namespace Graphics {

namespace Drawables {
Expand Down Expand Up @@ -1028,6 +1030,23 @@ namespace Graphics {
}
}

//------------------------------------------------------------
Label3DWrapper::Label3DWrapper(Graphics::Renderer *r, const std::string &str)
{
Graphics::Texture *sdfTex = Graphics::TextureBuilder("fonts/label3d.dds", Graphics::LINEAR_CLAMP, true, true, true).GetOrCreateTexture(r, "model");
RefCountedPtr<Text::DistanceFieldFont> m_labelFont;
m_labelFont.Reset(new Text::DistanceFieldFont("fonts/sdf_definition.txt", sdfTex));
m_label3D.reset(new SceneGraph::Label3D(r, m_labelFont));
m_label3D->SetText(str);
}

void Label3DWrapper::Draw(const matrix4x4f &trans)
{
if (m_label3D) {
m_label3D->Render(trans, nullptr);
}
}

} // namespace Drawables

} // namespace Graphics
15 changes: 13 additions & 2 deletions src/graphics/Drawables.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graphics/VertexBuffer.h"

#include <memory>
#include <string>

struct Aabb;

Expand Down Expand Up @@ -122,8 +123,6 @@ namespace Graphics {
void Draw(Renderer *, Material *);

private:
void CreateVertexBuffer(Graphics::Renderer *r, const Uint32 size);

bool m_refreshVertexBuffer;
RefCountedPtr<MeshObject> m_pointMesh;
std::unique_ptr<VertexArray> m_va;
Expand Down Expand Up @@ -290,6 +289,18 @@ namespace Graphics {
static void DrawVertices(Graphics::VertexArray &va, const matrix4x4f &transform, const Aabb &aabb, Color color);
};

//------------------------------------------------------------

// Label3DWrapper
class Label3DWrapper {
public:
Label3DWrapper(Graphics::Renderer *r, const std::string &str);
void Draw(const matrix4x4f &trans);

private:
std::unique_ptr<SceneGraph::Label3D> m_label3D;
};

} // namespace Drawables

} // namespace Graphics
Expand Down

0 comments on commit 2db89c9

Please sign in to comment.