FPS not updating and some more!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
axeves
Posts: 12
Joined: Tue Jun 21, 2011 5:13 pm
Location: Sweden

FPS not updating and some more!

Post by axeves »

Hi.

My problem is that my fps label/text doesn't update, and there are some strange numbers all over my other labels.

(i.e no compiling issues)

Pic of the problem:
http://www.postimage.org/image/2nutc7upw/

And le code: (if you have suggestions for improvments code-wise, do tell as my code isn't very good or efficient.)

Code: Select all

int main() {
 
 IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<u32>(width, height), 32, fullscreen, stencilbuffer, vsync, NULL);
 
 IVideoDriver* driver = device->getVideoDriver();
 ISceneManager* sceneManager = device->getSceneManager();
 IGUIEnvironment* guiEnvironment = device->getGUIEnvironment();
 
 ICameraSceneNode* camera = sceneManager->addCameraSceneNodeFPS();
 
 camera->setFOV(32);
 camera->setFarValue(10000);
 camera->setNearValue(20);
 
 sceneManager->addSkyBoxSceneNode(
                driver->getTexture("Data/Textures/Skybox/up.jpg"),
                driver->getTexture("Data/Textures/Skybox/down.jpg"),
                driver->getTexture("Data/Textures/Skybox/left.jpg"),
                driver->getTexture("Data/Textures/Skybox/right.jpg"),
                driver->getTexture("Data/Textures/Skybox/forward.jpg"),
                driver->getTexture("Data/Textures/Skybox/back.jpg"));
 
 ISceneNode *cube = sceneManager->addCubeSceneNode();
 
 sceneManager->addSphereSceneNode(5.0f, 16.0f, 0, -1, vector3df(100,30,10));
 
 sceneManager->addLightSceneNode(camera);
 
 camera->setTarget(cube->getAbsolutePosition());
 
 device->getCursorControl()->setVisible(false);
 
 device->setWindowCaption(L"Bajs");
 
//DEBUG-TEXT START|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
   IGUIStaticText* fpsDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 10, 200, 200), false);
   fpsDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   IGUIStaticText* vsyncDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 20, 200, 200), false);
   vsyncDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   IGUIStaticText* fullscreenDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 30, 200, 200), false);
   fullscreenDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   IGUIStaticText* stencilbufferDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 40, 200, 200), false);
   stencilbufferDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   IGUIStaticText* rendererDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 50, 200, 200), false);
   rendererDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   IGUIStaticText* driverTypeDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 60, 200, 200), false);
   driverTypeDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   IGUIStaticText* resolutionDebug = guiEnvironment->addStaticText(L"", rect<s32>(10, 70, 200, 200), false);
   resolutionDebug->setOverrideColor(SColor(255, 255, 0, 0));
 
   stringw fullscreenStr = "";
 
   if (fullscreen == false) {
          fullscreenStr = "Fullscreen is off";
   }
 
   else if (fullscreen == true) {
          fullscreenStr = "Fullscreen is on";
   }
 
   stringw vsyncStr = "";
 
   if (vsync == false) {
          vsyncStr = "V-sync is off";
   }
 
   else if (vsync == true) {
          vsyncStr = "V-sync is on";
   }
 
   stringw stencilbufferStr = "";
 
   if (stencilbuffer == false) {
          stencilbufferStr = "Stencilbuffer is off";
   }
 
   else if (stencilbuffer == true) {
           stencilbufferStr = "Stencilbuffer is on";
   }
 
   stringw fpsStr = "";
   stringw rendererStr = stringw("");
   stringw drivertypeStr = stringw("Drivertype: ");
   stringw resolutionStr = stringw("Resolution: ");
   stringw aspectratioStr = stringw("");
 
   rendererStr += stringw(driver->getName());
   drivertypeStr += stringw(driver->getDriverType());
   vsyncStr += stringw(vsync);
   fullscreenStr += stringw(fullscreen);
   stencilbufferStr += stringw(stencilbuffer);
   resolutionStr += stringw(width);
   resolutionStr += stringw("x");
   resolutionStr += stringw(height);
   fpsStr += driver->getFPS();
 
   if (debug == true) {
   vsyncDebug->setText(vsyncStr.c_str());
   fullscreenDebug->setText(fullscreenStr.c_str());
   stencilbufferDebug->setText(stencilbufferStr.c_str());
   rendererDebug->setText(rendererStr.c_str());
   driverTypeDebug->setText(drivertypeStr.c_str());
   resolutionDebug->setText(resolutionStr.c_str());
   }
 
//DEBUG-TEXT SLUT|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||<
 
 
 while(device->run() && driver) {
 
  driver->beginScene(true, true, SColor(255, 255, 255, 255));
  sceneManager->drawAll();
  guiEnvironment->drawAll();
 
  if (debug == true) {
          fpsDebug->setText(fpsStr.c_str());
  }
 
  driver->endScene();
   }
 device->drop();
 return 0;
}
Any response is welcome :)

p.s, if you have any good input (as in keyboard and mouse-input) code anywhere or a link to it, please do send :D
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: FPS not updating and some more!

Post by serengeor »

I haven't looked too much into the code, but I can tell that your fps might "not" be updated because vsync is also set on the video card (might be forced to on in driver settings).

As for keyboard mouse input, you just really have to try to write one yourself. If you aim to write some 3d application you should be ready to do this yourself. I know it might look a bit hard at the beginning, but you really just have to give it a shot and once you'll make it it will sure be easier next time, or when you need some extra features. And if you fail at something just ask here again, I think forum users will be glad to help if you also invest some time solving your problems.

And for extra 0's I don't really know what might be wrong.
Working on game: Marrbles (Currently stopped).
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: FPS not updating and some more!

Post by Radikalizm »

I think you need to look into the language some more and figure out how variables work exactly, how are you expecting the FPS string to change if you don't update it every frame? Right now you're just assigning the FPS value once to a string and you keep on drawing that single value over and over again

I suggest you read the tutorials, they provide a complete example on displaying the framerate

About the numbers appearing, I'm not quite sure what's causing that, but it's quite late over here and I've been working on my own code the entire day so I'm exhausted and I might be overlooking something obvious; I'll get back to you on that
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: FPS not updating and some more!

Post by serengeor »

Radikalizm wrote: About the numbers appearing, I'm not quite sure what's causing that, but it's quite late over here and I've been working on my own code the entire day so I'm exhausted and I might be overlooking something obvious; I'll get back to you on that
Yeah same here, I just overlooked that hes not updating his fps string :|
Working on game: Marrbles (Currently stopped).
axeves
Posts: 12
Joined: Tue Jun 21, 2011 5:13 pm
Location: Sweden

Re: FPS not updating and some more!

Post by axeves »

Thanks for the answers!

I do know that i should get a better grasp on programming, and i am learning alot everyday.

It's just that alot of the stuff in irrlicht is confusing and new, so it takes a while to learn it properly, especially because there is no wealth of tutorials (meaning that the tutorials just show one way of doing things, and that way may not work with that function, etc.)

As for v-sync being on, it's actually not, if i set the fps label in the window caption instead, it updates properly.

I solved the FPS label problem, i thought that the fpsDebug->setText(fpsStr.c_str()); string would update it per frame, and didn't realise until now that it didn't clear out the old fps value, so it was actually stacking the numbers on and on. (i put it as a float and i couldn't see the end of the string :P)

Now, if you only could help me with the strange numbers.
CuteAlien
Admin
Posts: 9986
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: FPS not updating and some more!

Post by CuteAlien »

You add the 0's yourself:

Code: Select all

 
fullscreenStr += stringw(fullscreen);
 
Not sure what you expect this to do, but what it does is convert the boolean "fullscreen" into a string of either 0 or 1. In your case it's 0.
Also another note - you should use strings starting with L like L"myString" instead of using "myString". That way you create wide-char strings which stringw does expect (otherwise it does a conversion, which is slower and bad style).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
axeves
Posts: 12
Joined: Tue Jun 21, 2011 5:13 pm
Location: Sweden

Re: FPS not updating and some more!

Post by axeves »

Thanks, i got it and solved it, thank you!
Post Reply