Page 1 of 1
Render FPS in a static text.
Posted: Mon Jun 25, 2007 8:18 pm
by alfabeta90
I wanted to show a fps in a static text.
Code: Select all
while(device->run())
{
driver->beginScene(true, true, SColor(0,192,192,192));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
int fps = driver->getFPS();
core::stringw str = L"FPS: ";
str += fps;
guienv->addStaticText(str.c_str(), rect<s32>(35,35,140,50), false, false, 0);
}
But if i run program i see: "FPS: " and then a black little somthing. I think that are fps number whos are rendered on previous fps number. Any help?
Posted: Mon Jun 25, 2007 8:54 pm
by Dorth
you have to either use a string buffer then throw in it the numbers with the << operator or use something like itoa to convert them to text. Right now the value you give it is not something a string recognizes...
Posted: Mon Jun 25, 2007 8:54 pm
by vitek
You only need to call
addStaticText() once. After that you need to use
setText(). Otherwise you're creating a new static text over the top of the old one every frame.
Code: Select all
IGUIStaticText* fpsTextElement = guienv->addStaticText(L"", rect<s32>(35, 35, 140, 50), false, false, 0);
int lastFPS = 0;
while (device->run())
{
if (driver->beginScene(true, true, SColor(0,192,192,192)))
{
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
// only update fps display if fps changed
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"FPS: ";
str += fps;
fpsTextElement->setText(str.c_str());
lastFPS = fps;
}
}
Travis
Posted: Wed Jun 27, 2007 8:52 pm
by alfabeta90
alfabeta90 wrote:I do so:
Code: Select all
IGUIFont* font = device->getGUIEnvironment()->getFont("images/courier.bmp");
font->draw(buffer,rect<s32>(10,10,300,60),SColor(255,255,255,255));
What must i do to show fps because font has no methos lik setText?
Posted: Thu Jun 28, 2007 2:04 am
by Dances
alfabeta90 wrote:alfabeta90 wrote:I do so:
Code: Select all
IGUIFont* font = device->getGUIEnvironment()->getFont("images/courier.bmp");
font->draw(buffer,rect<s32>(10,10,300,60),SColor(255,255,255,255));
What must i do to show fps because font has no methos lik setText?
When you use addStaticText the first time you'll get a pointer to an IStaticText... or something like that... you should probably check the API.
Anyway, when you've got that you use setText on that pointer.
Posted: Thu Jun 28, 2007 8:36 am
by vitek
If you insist on using
drawText() you need to change the text that you draw...
Code: Select all
IGUIFont* font = device->getGUIEnvironment()->getFont("images/courier.bmp");
int lastFPS = 0;
while (device->run())
{
if (driver->beginScene(true, true, SColor(0,192,192,192)))
{
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
// only update fps display if fps changed
int fps = driver->getFPS();
if (font && (lastFPS != fps))
{
core::stringw str = L"FPS: ";
str += fps;
font->draw(str.c_str(), rect<s32>(10,10,300,60), video::SColor(255,255,255,255));
lastFPS = fps;
}
}
I don't know why you'd want to do that though. The
IGUIStaticText does exactly the same thing, the only diference is that it creates a GUI element to hold the state.
Travis