I want display HP above object and update texture each frame. I use billboard for that. Are there any another posibilities to display HP bar instead use billboards? Or billboards are the best way?
Can I use Sprite in 3D scene instead billboards? With sprite I can use texture directly instead Billboards where are material used.
Problem with this is, when two or more HP bars are displayed it render only one bar. That means if HP is decreased, hpoints are decrease for all displayed HP bars. I think this is because billboards share same one texture. Or be more precise, material. I think this is problematic: m_material = cache->GetResource<Material>("Materials/MyEmptyBillboard2.xml");
but when I use
m_material = new Material(ctx);
m_material->SetTexture(TextureUnit::TU_DIFFUSE, m_texture);
it show billboard with gray color.
This is how I display HP bar above my cubes (each cube have own billboard)
m_texture = new Texture2D(ctx);
m_texture->SetFilterMode(Urho3D::TextureFilterMode::FILTER_BILINEAR);
m_texture->SetNumLevels(1);
m_texture->SetSize(m_i_width, m_i_height, Urho3D::Graphics::GetRGBAFormat(), Urho3D::TEXTURE_DYNAMIC);
m_texture->SetData(0, 0, 0, m_i_width, m_i_height, m_idata_converted);
// billboard
m_node_billboard = m_node->CreateChild("HealthBar");
m_node_billboard->SetPosition(Vector3(0, 0.8, 0));
m_bs = m_node_billboard->CreateComponent<BillboardSet>();
m_bs->SetNumBillboards(1);
m_material = cache->GetResource<Material>("Materials/MyEmptyBillboard2.xml");
m_material->SetTexture(TextureUnit::TU_DIFFUSE, m_texture);
m_bs->SetMaterial(m_material);
m_bs->SetSorted(true);
m_bb = m_bs->GetBillboard(0);
float fx = 0.5;
float fy = fx / (m_i_width / m_i_height);
m_bb->size_ = Vector2(fx, fy);
m_bb->enabled_ = SHOW_HEALTHBAR;
m_bs->Commit();
and how I update billboard
ArmorHealthBar->Render((double)m_i_width, (double)m_i_height, m_idata);
ConvertRGBA();
m_texture->SetData(0, 0, 0, m_i_width, m_i_height, m_idata_converted);
m_material->SetTexture(TextureUnit::TU_DIFFUSE, m_texture);