I'm developing a 3D football game with Irrlicht 1.7.3 on Ubuntu, and I'm having performance problems when adding jersey numbers on my players textures. The application drops to 5 FPS instead of the usual 60 FPS.
My players share the same mesh, which is a B3D model. The textures I apply on them have the same size 2048*2048 pixels (with PNG type), and they are very similar. Only the colors change, according to the team for which each player competes.
My font for jersey numbers is stored using the XML format, associated with a 1350*250 pixels image representing the 10 digits from 0 to 9. The digits are quite big because they have to be visible from medium range on the back of the players, and also because the texture is also quite big.
To construct my player scene node, I do this :
Code: Select all
IAnimatedMesh* mesh = sceneManager->getMesh(mModelPath);
mNode = sceneManager->addAnimatedMeshSceneNode(mesh);
mTexture = driver->getTexture(mTexturePath);
mNode->setMaterialTexture(0, mTexture);
mRenderTexture = driver->addRenderTargetTexture(mTextureSize);
mNode->setMaterialTexture(0, mRenderTexture);
When it comes to actual rendering, I process each player in the same way.
I get his render texture (RT). I draw his colored texture on this RT. Then I draw his jersey number on this RT.
Here is the code for scene rendering :
Code: Select all
mDriver->beginScene(
true, // clear back-buffer
true, // clear z-buffer
mBgColor);
for(std::map<int, Player*>::iterator i = players.begin();
i != players.end(); ++i) {
Player* p = i->second;
// Virtual surface where to draw
ITexture* rt = p->getRenderTexture();
// Actual player texture with its color but without jersey number
ITexture* texture = p->getTexture();
// Now we draw on texture instead of window
mDriver->setRenderTarget(rt);
mDriver->setMaterial(mDriver->getMaterial2D()); // fix OpenGL issue in Irrlicht 1.7.3
// Draw actual player texture
mDriver->draw2DImage(texture, vector2di(0, 0));
mDriver->setMaterial(mDriver->getMaterial2D());
// Draw jersey number over it
mJerseyFont->draw(p->getJerseyText(),
p->getJerseyTextRect(),
mJerseyTextColor, true, true);
// We go back to window (necessary to be able to switch, see API)
mDriver->setRenderTarget(0, true, true, mBgColor);
}
mSceneManager->drawAll();
mDriver->setMaterial(mDriver->getMaterial2D());
mGui->drawAll();
mDriver->endScene();
Thanks for your help