Commit b2b6c0d4 authored by Chen Bill's avatar Chen Bill

update CGUITTFont::addTextSceneNode

parent db333ef3
...@@ -879,11 +879,7 @@ core::dimension2d<u32> CGUITTFont::getDimensionUntilEndOfLine(const wchar_t* p) ...@@ -879,11 +879,7 @@ core::dimension2d<u32> CGUITTFont::getDimensionUntilEndOfLine(const wchar_t* p)
} }
core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text, scene::ISceneManager* smgr, scene::ISceneNode* parent, const video::SColor& color, bool center) { core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text, scene::ISceneManager* smgr, scene::ISceneNode* parent, const video::SColor& color, bool center) {
using namespace core; core::array<scene::ISceneNode*> container;
using namespace video;
using namespace scene;
array<scene::ISceneNode*> container;
if (!Driver || !smgr) return container; if (!Driver || !smgr) return container;
if (!parent) if (!parent)
...@@ -894,8 +890,8 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -894,8 +890,8 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
if (!shared_plane_ptr_) //this points to a static mesh that contains the plane if (!shared_plane_ptr_) //this points to a static mesh that contains the plane
createSharedPlane(); //if it's not initialized, we create one. createSharedPlane(); //if it's not initialized, we create one.
dimension2d<s32> text_size(getDimension(text)); //convert from unsigned to signed. core::dimension2d<s32> text_size(getDimension(text)); //convert from unsigned to signed.
vector3df start_point(0, 0, 0), offset; core::vector3df start_point(0, 0, 0), offset;
/** NOTICE: /** NOTICE:
Because we are considering adding texts into 3D world, all Y axis vectors are inverted. Because we are considering adding texts into 3D world, all Y axis vectors are inverted.
...@@ -909,7 +905,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -909,7 +905,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
} }
// the default font material // the default font material
SMaterial mat; video::SMaterial mat;
mat.setFlag(video::EMF_LIGHTING, true); mat.setFlag(video::EMF_LIGHTING, true);
mat.setFlag(video::EMF_ZWRITE_ENABLE, false); mat.setFlag(video::EMF_ZWRITE_ENABLE, false);
mat.setFlag(video::EMF_NORMALIZE_NORMALS, true); mat.setFlag(video::EMF_NORMALIZE_NORMALS, true);
...@@ -921,7 +917,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -921,7 +917,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
wchar_t current_char = 0, previous_char = 0; wchar_t current_char = 0, previous_char = 0;
u32 n = 0; u32 n = 0;
array<u32> glyph_indices; core::array<u32> glyph_indices;
while (*text) { while (*text) {
current_char = *text; current_char = *text;
...@@ -954,23 +950,23 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -954,23 +950,23 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
s32 offy = (font_metrics.ascender / 64) - glyph.offset.Y; s32 offy = (font_metrics.ascender / 64) - glyph.offset.Y;
// Apply kerning. // Apply kerning.
vector2di k = getKerning(current_char, previous_char); core::vector2di k = getKerning(current_char, previous_char);
offset.X += k.X; offset.X += k.X;
offset.Y += k.Y; offset.Y += k.Y;
vector3df current_pos(offset.X + offx, offset.Y - offy, 0); core::vector3df current_pos(offset.X + offx, offset.Y - offy, 0);
dimension2d<u32> letter_size = dimension2d<u32>(texw, texh); core::dimension2d<u32> letter_size = core::dimension2d<u32>(texw, texh);
// Now we copy planes corresponding to the letter size. // Now we copy planes corresponding to the letter size.
IMeshManipulator* mani = smgr->getMeshManipulator(); scene::IMeshManipulator* mani = smgr->getMeshManipulator();
IMesh* meshcopy = mani->createMeshCopy(shared_plane_ptr_); scene::IMesh* meshcopy = mani->createMeshCopy(shared_plane_ptr_);
mani->scale(meshcopy, vector3df((f32)letter_size.Width, (f32)letter_size.Height, 1)); mani->scale(meshcopy, core::vector3df((f32)letter_size.Width, (f32)letter_size.Height, 1));
ISceneNode* current_node = smgr->addMeshSceneNode(meshcopy, parent, -1, current_pos); scene::ISceneNode* current_node = smgr->addMeshSceneNode(meshcopy, parent, -1, current_pos);
meshcopy->drop(); meshcopy->drop();
current_node->getMaterial(0) = mat; current_node->getMaterial(0) = mat;
current_node->setAutomaticCulling(EAC_OFF); current_node->setAutomaticCulling(scene::EAC_OFF);
current_node->setIsDebugObject(true); //so the picking won't have any effect on individual letter current_node->setIsDebugObject(true); //so the picking won't have any effect on individual letter
//current_node->setDebugDataVisible(EDS_BBOX); //de-comment this when debugging //current_node->setDebugDataVisible(EDS_BBOX); //de-comment this when debugging
...@@ -988,7 +984,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -988,7 +984,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
for (u32 i = 0; i < glyph_indices.size(); ++i) { for (u32 i = 0; i < glyph_indices.size(); ++i) {
u32 n = glyph_indices[i]; u32 n = glyph_indices[i];
SGUITTGlyph const& glyph = Glyphs[n - 1]; SGUITTGlyph const& glyph = Glyphs[n - 1];
ITexture* current_tex = Glyph_Pages[glyph.glyph_page]->texture; video::ITexture* current_tex = Glyph_Pages[glyph.glyph_page]->texture;
f32 page_texture_size = (f32)current_tex->getSize().Width; f32 page_texture_size = (f32)current_tex->getSize().Width;
//Now we calculate the UV position according to the texture size and the source rect. //Now we calculate the UV position according to the texture size and the source rect.
// //
...@@ -1004,15 +1000,15 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -1004,15 +1000,15 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
f32 v2 = v1 + (glyph.source_rect.getHeight() / page_texture_size); f32 v2 = v1 + (glyph.source_rect.getHeight() / page_texture_size);
//we can be quite sure that this is IMeshSceneNode, because we just added them in the above loop. //we can be quite sure that this is IMeshSceneNode, because we just added them in the above loop.
IMeshSceneNode* node = static_cast<IMeshSceneNode*>(container[i]); scene::IMeshSceneNode* node = static_cast<scene::IMeshSceneNode*>(container[i]);
S3DVertex* pv = static_cast<S3DVertex*>(node->getMesh()->getMeshBuffer(0)->getVertices()); video::S3DVertex* pv = static_cast<video::S3DVertex*>(node->getMesh()->getMeshBuffer(0)->getVertices());
//pv[0].TCoords.Y = pv[1].TCoords.Y = (letter_size.Height - 1) / static_cast<f32>(letter_size.Height); //pv[0].TCoords.Y = pv[1].TCoords.Y = (letter_size.Height - 1) / static_cast<f32>(letter_size.Height);
//pv[1].TCoords.X = pv[3].TCoords.X = (letter_size.Width - 1) / static_cast<f32>(letter_size.Width); //pv[1].TCoords.X = pv[3].TCoords.X = (letter_size.Width - 1) / static_cast<f32>(letter_size.Width);
pv[0].TCoords = vector2df(u1, v2); pv[0].TCoords = core::vector2df(u1, v2);
pv[1].TCoords = vector2df(u2, v2); pv[1].TCoords = core::vector2df(u2, v2);
pv[2].TCoords = vector2df(u1, v1); pv[2].TCoords = core::vector2df(u1, v1);
pv[3].TCoords = vector2df(u2, v1); pv[3].TCoords = core::vector2df(u2, v1);
container[i]->getMaterial(0).setTexture(0, current_tex); container[i]->getMaterial(0).setTexture(0, current_tex);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment