0

As an experiment, I have set up a simulated set of gears attached to a motor and rendered them with OpenGL/GLUT. At the moment the only input to the Wire network is Time. I want to use the keyboard to control the change the speed of the motor. I would also like to detach the physics timestep from the frame rate as described in Fix your Timestep!.

This means that I need to run the Wire network from three different GLUT callbacks (keyboardMouseCallback,idleCallback, and displayCallback) with three different types of inputs. I'm unclear how to integrate Netwire with the GLUT callbacks.

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
John F. Miller
  • 25,556
  • 8
  • 66
  • 120

2 Answers2

3

GLUT is a bit hostile to frameworks where you need control over the main loop such as Netwire. It is possible, but you will likely have to use an IORef or something similar. The most Netwire-friendly OpenGL manager I know is SDL, but of course you can also give Nicol's GLFW suggestion a try. Otherwise you will indeed have to step the wire from multiple event handlers.

For processing the actual keyboard input I suggest that you add the event information to whatever underlying monad you are using (a reader monad is probably the best solution). Then implement, say, a keyDown wire that produces whenever the given key is held down:

keyDown :: (Monoid e) => Key -> Wire e (Reader GuiState) a a

Now you can do something as simple as this:

position = integral_ 0 . speed
    where
    direction key dir = dir . keyDown key <|> 0
    speed = direction Right 1 + direction Left (-1)
ertes
  • 46
  • 1
1

Have you considered... not doing that?

There's no law that says you have to use (Free)GLUT. GLFW is (almost) as capable, and it allows you to control the render loop however you want. It's a poll-based API, so any callbacks will happen only when you want them to.

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
  • Yes, I have. But I already have a lot of experiences with GLUT and I'm just learning Netwire. If possible I'd like to stick with what I know. – John F. Miller Nov 17 '12 at 02:29