Your help is highly appreciated, thank you.
change frame rate
change frame rate
Could anyone help me on how to change frame rate (FPS) please? I want to draw my scene for every 30 frames but do not know how to do. 
Your help is highly appreciated, thank you.
Your help is highly appreciated, thank you.
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
If you try to do this, then you have two choices:
1) Sit in a tight loop checking the time constantly. This will eat 100% of your CPU (or 100% of one core), so it's almost certainly pointless; you might as well be rendering rather than doing nothing except checking the time.
2) sleep() / Sleep() for a bit, or halt on a timer. Unfortunately, that will only guarantee that your main thread isn't woken for at least the specified time. In practice, you will have to sleep for much less time than you really need, then sit in a tight loop again. Even then, you might get a very long sleep, and miss a frame.
Trying to maintain any particular framerate is generally a bad idea, and should be avoided unless there's a very specific reason why you need to do it.
If you tell us why you want to do this, then perhaps we can suggest a better method.
1) Sit in a tight loop checking the time constantly. This will eat 100% of your CPU (or 100% of one core), so it's almost certainly pointless; you might as well be rendering rather than doing nothing except checking the time.
2) sleep() / Sleep() for a bit, or halt on a timer. Unfortunately, that will only guarantee that your main thread isn't woken for at least the specified time. In practice, you will have to sleep for much less time than you really need, then sit in a tight loop again. Even then, you might get a very long sleep, and miss a frame.
Trying to maintain any particular framerate is generally a bad idea, and should be avoided unless there's a very specific reason why you need to do it.
If you tell us why you want to do this, then perhaps we can suggest a better method.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
Dark_Kilauea
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
Option 3: Turn on vsync, which will probably get you 30 or 60 FPS, depending on how fast the game can draw. (Although this does depend on how fast your monitor can refresh and is kinda moot on LCD monitors, the implementations I've seen usually cap at 30 or 60).
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Look at the way some physics engines calculate the next frame based on specific intervals (FPS). Basically, you need to determine how many 'cpu' ticks it takes to render at say 30FPS. Then watch that number in the render loop, decrementing it every pass, keep waiting until that number goes down to zero.

Hi guys,
first of all thanks for all your suggestion. The reason why I want to control the frame rate is because right now I am doing some collision dectection between my model and the wall. Although my model doesn't pass through the wall, there are flickers when my model collide with it. My friend said the flickers are caused by the scene manager try to draw everything at a very high frame rate, thus suggesting me to control the frame rate in order to eliminate those flickers.
I have been looking for answer for quite some time, but still can't get it.
first of all thanks for all your suggestion. The reason why I want to control the frame rate is because right now I am doing some collision dectection between my model and the wall. Although my model doesn't pass through the wall, there are flickers when my model collide with it. My friend said the flickers are caused by the scene manager try to draw everything at a very high frame rate, thus suggesting me to control the frame rate in order to eliminate those flickers.
I have been looking for answer for quite some time, but still can't get it.
-
twilight17
- Posts: 362
- Joined: Sun Dec 16, 2007 9:25 pm
Use vsync
Post this userbar I made on other websites to show your support for Irrlicht!

http://img147.imageshack.us/img147/1261 ... wernq4.png

http://img147.imageshack.us/img147/1261 ... wernq4.png
this also could be caused by node culling or too long near clipping plane of the camera...charles88 wrote:Although my model doesn't pass through the wall, there are flickers when my model collide with it.
so try to disable culling and use setNearValue() on the camera to set a smaller clipping plane...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Seconded. It's a parameter to createDevice().twilight17 wrote:Use vsync
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Already tried but the flickers are still there.so try to disable culling and use setNearValue() on the camera to set a smaller clipping plane...
Edit:
Anyway is this the correct code to disable culling and setNearValue()?
Code: Select all
node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
cam->setNearValue(10f);
Last edited by charles88 on Wed Nov 05, 2008 4:01 am, edited 1 time in total.
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Uh... it's a parameter to createDevice()?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
what if u create a loop and check if time elapsed is XXX millisecond b4 render?
e.g.
use 33 millisecond for 30fps and 50millisecond for 20fps?
e.g.
Code: Select all
time = getsystemtimeinmillis
do {
now = getsystemtimeinmillis
if (now-time>33) {
render()
time = now
}
} while (XXX)