I learn a bit of functional programming in the Gambit-C Scheme, limiting myself to not using set !. I thought it would be interesting to write a small OpenGL game using this environment, which seems to be well suited for game development.
However, it seems difficult to maintain a functional style and avoid a global state when using OpenGL and GLUT. I don't think this is a fundamental limitation of game programming, in fact, but a callback based API like GLUT does not seem to work with functional programming.
For example, I am trying to imagine the world as a stream of mutating state vectors, which is a function of an alternating list of time events and input events. This idea seems to be in order, but with asynchronous programming, it does not seem to go easy. For example, I have to register a callback for the GLUT mapping function, which must somehow have access to the "current" element in this thread. Meanwhile, there is nothing to drive the stream forward, taking from it.
Ideally, I need something like the “outside” of GLUT, the main function that somehow depends (possibly monadically) on the various GLUT functions that were executed at some point. How can I create this style of a game engine around GLUT, or another way to ask how I can most successfully isolate GLUT from my engine? Is it possible for GLUT to generate such a striped list of events for an external procedure? How does Haskell handle this, for example?
Steve source share