More work on billboard text
This commit is contained in:
parent
f803b01d10
commit
db26ef3076
@ -13,19 +13,30 @@
|
||||
|
||||
using namespace irr;
|
||||
|
||||
|
||||
STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font,
|
||||
const video::SColor& color, irr::scene::ISceneNode* parent,
|
||||
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size) : // TODO: use size or remove
|
||||
IBillboardSceneNode(parent, mgr, id, position),
|
||||
CBillboardSceneNode(parent, mgr, id, position, size, video::SColor(255, 255, 255, 255), video::SColor(255, 255, 255, 255))
|
||||
const irr::core::vector3df& position, const irr::core::vector3df& size) :
|
||||
STKMeshSceneNode(new scene::SMesh(),
|
||||
parent, irr_driver->getSceneManager(), -1,
|
||||
position, core::vector3df(0.0f, 0.0f, 0.0f), size, false)
|
||||
{
|
||||
getTextMesh(text, font, color);
|
||||
createGLMeshes();
|
||||
Mesh->drop();
|
||||
//setAutomaticCulling(0);
|
||||
setReloadEachFrame(true); // FIXME: should not need that!!
|
||||
updateAbsolutePosition();
|
||||
}
|
||||
|
||||
scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFont* font,
|
||||
const video::SColor& color)
|
||||
{
|
||||
font->doDraw(text, core::rect<s32>(0, 0, 1000, 1000), color, false, false, NULL, this);
|
||||
|
||||
const float scale = 0.05f;
|
||||
|
||||
scene::SMesh* mesh = new scene::SMesh();
|
||||
//scene::SMesh* mesh = new scene::SMesh();
|
||||
std::map<video::ITexture*, scene::SMeshBuffer*> buffers;
|
||||
|
||||
for (unsigned int i = 0; i < m_chars.size(); i++)
|
||||
@ -33,12 +44,10 @@ STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font,
|
||||
core::vector3df char_pos(m_chars[i].m_destRect.UpperLeftCorner.X,
|
||||
m_chars[i].m_destRect.UpperLeftCorner.Y, 0);
|
||||
char_pos *= scale;
|
||||
char_pos += position;
|
||||
|
||||
core::vector3df char_pos2(m_chars[i].m_destRect.LowerRightCorner.X,
|
||||
m_chars[i].m_destRect.LowerRightCorner.Y, 0);
|
||||
char_pos2 *= scale;
|
||||
char_pos2 += position;
|
||||
|
||||
core::dimension2di char_size_i = m_chars[i].m_destRect.getSize();
|
||||
core::dimension2df char_size(char_size_i.Width*scale, char_size_i.Height*scale);
|
||||
@ -96,18 +105,25 @@ STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font,
|
||||
for (std::map<video::ITexture*, scene::SMeshBuffer*>::iterator map_itr = buffers.begin();
|
||||
map_itr != buffers.end(); map_itr++)
|
||||
{
|
||||
mesh->addMeshBuffer(map_itr->second);
|
||||
((scene::SMesh*)Mesh)->addMeshBuffer(map_itr->second);
|
||||
|
||||
map_itr->second->recalculateBoundingBox();
|
||||
Mesh->setBoundingBox(map_itr->second->getBoundingBox()); // TODO: wrong if several buffers
|
||||
|
||||
map_itr->second->drop();
|
||||
}
|
||||
|
||||
STKMeshSceneNode* stk_mesh = new STKMeshSceneNode(mesh,
|
||||
parent, irr_driver->getSceneManager(), -1,
|
||||
position, core::vector3df(0.0f, 0.0f, 0.0f), core::vector3df(1.0f, 1.0f, 1.0f));
|
||||
stk_mesh->setAutomaticCulling(0);
|
||||
return Mesh;
|
||||
}
|
||||
|
||||
void STKTextBillboard::render()
|
||||
void STKTextBillboard::OnRegisterSceneNode()
|
||||
{
|
||||
if (IsVisible)
|
||||
{
|
||||
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
|
||||
}
|
||||
|
||||
ISceneNode::OnRegisterSceneNode();
|
||||
}
|
||||
|
||||
void STKTextBillboard::collectChar(video::ITexture* texture,
|
||||
|
@ -4,7 +4,10 @@
|
||||
#include "../lib/irrlicht/source/Irrlicht/CBillboardSceneNode.h"
|
||||
#include <IBillboardSceneNode.h>
|
||||
#include <irrTypes.h>
|
||||
#include <IMesh.h>
|
||||
#include "graphics/stkmeshscenenode.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
class STKTextBillboardChar
|
||||
{
|
||||
@ -36,18 +39,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class STKTextBillboard : public irr::scene::CBillboardSceneNode, irr::gui::FontCharCollector
|
||||
class STKTextBillboard : public STKMeshSceneNode, irr::gui::FontCharCollector
|
||||
{
|
||||
std::vector<STKTextBillboardChar> m_chars;
|
||||
|
||||
irr::scene::IMesh* getTextMesh(irr::core::stringw text, gui::ScalableFont* font,
|
||||
const irr::video::SColor& color);
|
||||
|
||||
public:
|
||||
STKTextBillboard(irr::core::stringw text, irr::gui::ScalableFont* font,
|
||||
const irr::video::SColor& color, irr::scene::ISceneNode* parent,
|
||||
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||
const irr::core::vector3df& position,
|
||||
const irr::core::dimension2d<irr::f32>& size);
|
||||
const irr::core::vector3df& size);
|
||||
|
||||
virtual void render();
|
||||
virtual void OnRegisterSceneNode() OVERRIDE;
|
||||
|
||||
virtual void collectChar(irr::video::ITexture* texture,
|
||||
const irr::core::rect<irr::s32>& destRect,
|
||||
|
@ -15,13 +15,15 @@
|
||||
STKMeshSceneNode::STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||
const irr::core::vector3df& position,
|
||||
const irr::core::vector3df& rotation,
|
||||
const irr::core::vector3df& scale) :
|
||||
const irr::core::vector3df& scale, bool createGLMeshes) :
|
||||
CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
|
||||
{
|
||||
isDisplacement = false;
|
||||
immediate_draw = false;
|
||||
update_each_frame = false;
|
||||
createGLMeshes();
|
||||
|
||||
if (createGLMeshes)
|
||||
this->createGLMeshes();
|
||||
}
|
||||
|
||||
void STKMeshSceneNode::setReloadEachFrame(bool val)
|
||||
|
@ -29,7 +29,8 @@ public:
|
||||
STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||
const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0),
|
||||
const irr::core::vector3df& rotation = irr::core::vector3df(0, 0, 0),
|
||||
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f));
|
||||
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f),
|
||||
bool createGLMeshes = true);
|
||||
virtual void render();
|
||||
virtual void setMesh(irr::scene::IMesh* mesh);
|
||||
virtual void OnRegisterSceneNode();
|
||||
|
Loading…
Reference in New Issue
Block a user