# update() vs display() with glut

This topic is 5010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Quote:
 Original post by CosmoKramerI 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).

##### Share on other sites
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?

##### Share on other sites
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);

##### Share on other sites
What about if you have a dedicated server mode?

##### Share on other sites
Quote:
 Original post by Puzzler183What 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.

1. 1
2. 2
3. 3
JoeJ
20
4. 4
5. 5
frob
19

• 11
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632213
• Total Posts
3004850

×