I am trying to make a transition from using Glut to using MFC. I have managed to get an OpenGL window in MFC, and now I need to know how to implement a few features. In particular, I need to know how to perform the equivalent of glutIdleFunc, glutKeyboardFunc, and glutMouseFunc. Can anyone offer any guidance?
In the ClassView, right-click on the dialog class and choose Add Windows Message Handler. You’ll see a list of the windows messages you can handle - most of them are pretty obvious, you can read up on the ones that aren’t.
I have looked at the class wizard and I think I can see what to use for mouse and keyboard input, but I still do not see where I would put the code to redraw the scene for animation (i.e. what is the equivalent of glutIdleFunc). Can anyone offer insight on this?
you can think of glutIdleFunc as a handle for when the program/window is inactive or minimized. some people choose to not have the program do anything but most people pass in their display functions into glutIdleFunc.
if it’s imperative that your program responds to an “idle” event, then you can surely implement one. other than that, you don’t necessarily need it. just call your drawing func appropriately.
Okay, here is what I need. I am used to using glutIdleFunc to provide the code to update my image on the screen constantly. Basically, each time the idle function is called, the rotation will increase or something like that. What I need is a place to do the same thing in MFC. In otherwords, I need a place I can put a series of commands that will update the image, and redraw it to the screen. This needs to be run once for every frame of animation. So, how do I implement this in MFC.
Try a timer class too, OnIdle() would probably be “cleaner” code but a CTimer works as well. If you go to www.codeproject.com (might be www.thecodeproject.com, I can never remember) and do a search for CLabel, it’s a class someone wrote that makes the MFC Static object act like Visual Basic’s label control and it uses CTimer.