The problem is, it's basically missing the actual character preview texture, i.e. the osg::Image is empty.
Also note, I understand my implementation might be counter to the desired design. I'm just trying to hack something together first.
Code: Select all
// Not sure if I'm missing steps or creating this preview outside of InventoryDialogue is possible
void RenderingManager::avatar(osg::Image *image, const MWWorld::Ptr& player)
{
MWRender::InventoryPreview* inventoryPreview = new MWRender::InventoryPreview(mViewer->getSceneData()->asGroup(), mResourceSystem, player);
inventoryPreview->rebuild();
inventoryPreview->update();
image = inventoryPreview->getTexture()->getImage();
}
My goal is to be able to save the ChatacterPreview image (when you open your inventory up and you see your character) to a file.
EDIT:
This continues with code to write to file when the player saves his/her game. When complete I could push to master with the option to turn this feature on. I'm working on a website based character browser for people to see and read the states of everyones characters, the mods they use, and a download to the save file for OpenMW. One day it'd be cool to host here, with authentication for everyone to upload their characters.
Code is similar to the way we save screenshots for saved games. I see todo's to clean screenshot saves up so I will investigate that at some point.
Code: Select all
void MWState::StateManager::writeAvatar(std::vector<char> &imageData) const
{
osg::ref_ptr<osg::Image> avatar(new osg::Image);
MWBase::Environment::get().getWorld()->avatar(avatar.get(), MWBase::Environment::get().getWorld()->getPlayerPtr());
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("jpg");
if (!readerwriter)
{
std::cerr << "Error: Unable to write avatar, can't find a jpg ReaderWriter" << std::endl;
return;
}
std::ostringstream ostream;
osgDB::ReaderWriter::WriteResult result = readerwriter->writeImage(*avatar, ostream);
if (!result.success())
{
std::cerr << "Error: Unable to write avatar: " << result.message() << " code " << result.status() << std::endl;
return;
}
// \todo save the avatar image
}
I think this feature, the ability to save a preview of your character, is a neat for when people have mods and such. And adds uniformity when compiling a list of character previews.