PDA

View Full Version : going from Glut to MFC



Eggman
03-19-2004, 01:18 PM
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?

Wade

DalTXColtsFan
03-19-2004, 03:12 PM
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.

Eggman
03-19-2004, 03:28 PM
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?

Wade

ce110ut
03-19-2004, 04:30 PM
recall that glut has:

glutDisplayFunc()
glutIdleFunc()

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 ]=-

Eggman
03-19-2004, 05:37 PM
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.

Wade

robosport
03-19-2004, 08:08 PM
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.

mikael_aronsson
03-19-2004, 11:10 PM
The MFC thread class has an OnIdle() method that does the exact same thing as glut idle callbacks.

Mikael

DalTXColtsFan
03-20-2004, 11:08 AM
Try a timer class too, OnIdle() would probably be "cleaner" code but a CTimer works as well. If you go to www.codeproject.com (http://www.codeproject.com) (might be www.thecodeproject.com, (http://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.

DalTXColtsFan
03-20-2004, 11:10 AM
oops, sorry robosport, wasn't trying to rain on your parade there http://www.opengl.org/discussion_boards/ubb/smile.gif.

Great minds think alike I guess! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Eggman
03-20-2004, 03:10 PM
These look like promising ideas. Is there a standard method though? Is one considered more acceptable?

Wade

robosport
03-21-2004, 12:04 AM
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.

03-21-2004, 08:15 PM
Hi,

Put this codes,

OnTimerFunc()
{
SendMessage(WM_PAINT);
}
OnInitDialog()
{
this->SetTimer(..);
}
OnPaint()
{
//Draw your GL screen
}

It will works.

Try to grab some simple tutorials from here.
http://www.myopendemo.com