void EC_ChatBubble::Refresh() { if (renderer_.expired() ||!billboardSet_ || !billboard_) return; // If no messages in the log, hide the chat bubble. if (messages_.size() == 0) { billboardSet_->setVisible(false); return; } else billboardSet_->setVisible(true); // Get pixmap with chat bubble and text rendered to it. QPixmap pixmap = GetChatBubblePixmap(); if (pixmap.isNull()) return; // Create texture QImage img = pixmap.toImage(); Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream((void*)img.bits(), img.byteCount())); std::string tex_name("ChatBubbleTexture" + renderer_.lock()->GetUniqueObjectName()); Ogre::TextureManager &manager = Ogre::TextureManager::getSingleton(); Ogre::Texture *tex = dynamic_cast<Ogre::Texture *>(manager.create(tex_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).get()); assert(tex); tex->loadRawData(stream, img.width(), img.height(), Ogre::PF_A8R8G8B8); // Set new material with the new texture name in it. std::string newMatName = std::string("material") + renderer_.lock()->GetUniqueObjectName(); Ogre::MaterialPtr material = OgreRenderer::CloneMaterial("UnlitTexturedSoftAlpha", newMatName); OgreRenderer::SetTextureUnitOnMaterial(material, tex_name); billboardSet_->setMaterialName(newMatName); }
void EC_ChatBubble::Refresh() { if (renderer_.expired() || !billboardSet_ || !billboard_) return; // If no messages in the log, hide the chat bubble. if (messages_.isEmpty()) { billboardSet_->setVisible(false); return; } else billboardSet_->setVisible(true); // Get image buffer and texture QImage buffer = GetChatBubblePixmap().toImage(); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_); if (buffer.isNull() || texture.isNull()) return; // Check texture size if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height()) { texture->freeInternalResources(); texture->setWidth(buffer.width()); texture->setHeight(buffer.height()); texture->createInternalResources(); } // Update texture buffer Ogre::Box update_box(0,0, buffer.width(), buffer.height()); Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)buffer.bits()); if (!texture->getBuffer().isNull()) texture->getBuffer()->blitFromMemory(pixel_box, update_box); }