TripleM
December 23rd, 2005, 04:42 AM
[warning - newbie alert]
I've been programming in java for a little while now, but decided I wanted to transfer the little game I've been making from java to C++, and decided I'd use opengl/glut for the graphics.
Basically the main thing that happens in this game is, you click on various things on the screen to set things up, and click 'go', which causes everything on the screen to move around for a few seconds, and then we go back to the first step. In java this is quite easy - just have a timer which simulates the next step and calls repaint().
Now I'm trying to get my head around how this would work in glut. Once you enter the main loop, it will never return (though I've been looking at freeglut, which has the glutMainLoopEvent or whatever its called which just does one thing then returns, or allows you to leave the main loop itself at any stage).
How do I structure my code to get the above idea working? The only way I can see to do animation is to set the idle function to render the scene, so its continuously drawing things. But do I put, say, at the end of the render method, something like (ifweshouldbesimulating) simulateNextStep(), or something like that? I'm not quite sure when this render function is being called, but it feels like its going to be called more than when I want it.
I probably haven't explained that very well, but if anyone understands what I'm talking about, what do I do?
(The other thing I can think of is to have all the drawing in another thread, which is really what java is doing, but I can't seem to find anybody else with google who does that, so theres probably something wrong with it.)
edit - I guess what I'm really asking is, how do I get my program to actually process all the rest of the code rather than just the graphics. Though in this case its about sometimes having something simulated, sometimes having other input. Hmm.
I've been programming in java for a little while now, but decided I wanted to transfer the little game I've been making from java to C++, and decided I'd use opengl/glut for the graphics.
Basically the main thing that happens in this game is, you click on various things on the screen to set things up, and click 'go', which causes everything on the screen to move around for a few seconds, and then we go back to the first step. In java this is quite easy - just have a timer which simulates the next step and calls repaint().
Now I'm trying to get my head around how this would work in glut. Once you enter the main loop, it will never return (though I've been looking at freeglut, which has the glutMainLoopEvent or whatever its called which just does one thing then returns, or allows you to leave the main loop itself at any stage).
How do I structure my code to get the above idea working? The only way I can see to do animation is to set the idle function to render the scene, so its continuously drawing things. But do I put, say, at the end of the render method, something like (ifweshouldbesimulating) simulateNextStep(), or something like that? I'm not quite sure when this render function is being called, but it feels like its going to be called more than when I want it.
I probably haven't explained that very well, but if anyone understands what I'm talking about, what do I do?
(The other thing I can think of is to have all the drawing in another thread, which is really what java is doing, but I can't seem to find anybody else with google who does that, so theres probably something wrong with it.)
edit - I guess what I'm really asking is, how do I get my program to actually process all the rest of the code rather than just the graphics. Though in this case its about sometimes having something simulated, sometimes having other input. Hmm.