update() vs display() with glut

Started by
4 comments, last by darookie 19 years, 4 months ago
You always hear about update() and display() functions in games. Ive always just updated in my display() function, so that you update right before you display, and no more. I never saw the point in updating the game world if your not going to display it anyway, so why separate the two ? Anyway, my friend told me its better to separate them (I still have no idea why), but even if this is the case, how can I do it using GLUT? Glut has a display callback function, but no update callback function. One might consider using the idle callback function for updating, but if you read the official description of that function, you will realize that it is not really the correct thing to do.
Advertisement
Quote:Original post by CosmoKramer
I never saw the point in updating the game world if your not going to display it anyway, so why separate the two ?

Think the other way round - you might want to display() more often than you actually update() (e.g. using interpolated values).

Oh. That seems like it would be complicated to do, not to mention inaccurate. Wouldnt interpolating take just about as much time as updating, in which case you might as well just update anyway?

Assuming youre talking about interpolating the display between 2 updates, how can you do that if you dont know what the world stat will be at the next update, or even when the next update will be? I think that just confused me more.

Anyway that stuffs not too important to me right now, I dont want my thread to get too side tracked.

My question remains: How can you separate the update and display functions in GLUT, when there is no appropriate callback function for update?
Well it depends on your application with whether or not you should do this. If you have a game for example you would want to update the screen in regular intervals (of say 30 updates per second). The display callback will only be called if the windowing system causes an update-display event, which happens if you move the screen, resize etc.

Quote:Original post by CosmoKramer how can I do it using GLUT?


Use the timer function callback, just make sure you re-call it at the end of your update function.
void glutTimerFunc(unsigned int msecs,void (*func)(int value), value);

What about if you have a dedicated server mode?
Quote:Original post by Puzzler183
What about if you have a dedicated server mode?

You don't use glut then. Nor do you render anything in the same thread as the server.

This topic is closed to new replies.

Advertisement