going from Glut to MFC

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 several MFC samples on my site - http://daltxcoltsfan.tripod.com

Good luck.

Thanks for the reply,

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?


recall that glut has:


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.

I hope that helps.

-=[ regards ]=-

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.


You may want to post related questions in the “OpenGL Under Windows” forum.

In MFC a common replacement for idle is to use your view’s OnTimer handler to call your frame display code regularly.

Check out the OnTimer handler at this link: http://www.cswl.com/whiteppr/tutorials/opengl.html#j

Hope that helps.

The MFC thread class has an OnIdle() method that does the exact same thing as glut idle callbacks.


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.

oops, sorry robosport, wasn’t trying to rain on your parade there .

Great minds think alike I guess!

These look like promising ideas. Is there a standard method though? Is one considered more acceptable?


It wouldn’t be any fun if there was only one way to do it.

All depends on what functionality/complexity trade-offs you want in your code. Both solutions posted here should work well.

Good luck.


Put this codes,

//Draw your GL screen

It will works.

Try to grab some simple tutorials from here.