View Full Version : OpenGL animation in MFC programs
03-02-2001, 11:24 PM
Hey guys, right now, to do animation in my MFC-based ogl program, I override the CWinApp::OnIdel() function. I'm wondering, is this the "right" way to do things??
This is basically the same problem as in a normal Win32-based program, in that to do animation, you can't just draw a new frame when u get a WM_PAINT, you gotta draw it whenever possible, provided that no wm's are in the queue.
Please help, thanks!
03-03-2001, 08:49 AM
set up a timer and when windows calls the timer call the rendering function.
03-03-2001, 10:46 AM
No. Windows timers are not good for doing smooth real-time animation.
Look, I already know how to do this stuff under a normal Win32 application: in your message pump, you call PeekMessage(), if there's a WM on the queue, you process it. If there's no WM on the queue, you call your RenderFrame() function, this way, you're drawing and updating your scene as fast as your machine can handle.
Using Windows timers defeats the whole purpose of this.
I just wanna know the equivalent of doing this under MFC.
ps, I successfully overrode the CWinApp::OnIdel() function last night, and it is doing what I wanted in my simple app(basically, just a spinning triangle). I just wanna know if this is how the "real" MFC opengl programmers do it...
[This message has been edited by somecodeguy (edited 03-03-2001).]
03-04-2001, 12:49 AM
Are there any `real` MFC OpenGL programmers out there? http://www.opengl.org/discussion_boards/ubb/smile.gif I would be most interested in your findings because I am writing a simple level editor with OGL and MFC and having it run as fast as the computer can handle would be good. I don't really have a clue about MFC, I only started using it a few weeks ago nad using a timer is the only way I know of creating animation. Mind you the UT editor doesn't even use a timer for some of its animations, like the animated textures in the texture browser only change when you click on the browser.
03-04-2001, 07:05 AM
OnIdle is as good a place as any to put your animation code. It's basically the same thing as calling your render function in Win32 when there ore no other messages pending.
One way to do this is to set up a thread that does nothing but call your render functions. Then give the thread as high a priority as you want. Of course threading introduces all sorts of potential complicatios with synchronization. I've implemented a separate rending thread in my apps and it works quite well.
The OpenGL superbible describes this approach in some detail.
03-04-2001, 04:23 PM
If you use multithreading, make sure that the thread that does the rendering is the same one that does the OpenGL initialization.
03-04-2001, 11:59 PM
Well, thanks for the replies. I think I'll stick with overriding CWinApp::OnIdle(), the thread-making seems too much work for such a simple problem, imho.
and Tim, I certainly hope u were not offended by my response to your post. That was not my intention, and I do appreciate your help. http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.