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 committed Nov 19, 2024
1 parent 519a4c3 commit 2f9d3e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/graphics/Drawables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "graphics/Types.h"
#include "graphics/VertexBuffer.h"
#include "profiler/Profiler.h"
#include "scenegraph/Label3D.h"

#include <sstream>

namespace Graphics {

Expand Down Expand Up @@ -1028,6 +1031,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
19 changes: 17 additions & 2 deletions src/graphics/Drawables.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#include "graphics/VertexBuffer.h"

#include <memory>
#include <string>

struct Aabb;

namespace SceneGraph {
class Label3D;
} //namespace SceneGraph

namespace Graphics {
class Renderer;

Expand Down Expand Up @@ -122,8 +127,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 +293,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 2f9d3e0

Please sign in to comment.