Skip to main content
gamedev.net
🔒 Locked

MFC continuous update

Started by Schinizer Aug 31, 2011 at 6:06 PM 3 replies 1.6k views
Original Post
Schinizer
Schinizer
Hello all,

I just started MFC recently so I'm not very familar with it. Basically my app is a level editor, its a mfc Single Document Interface with openGL. My openGL window is using CView class.
I need my openGL window to render every frame. I know this has been asked many times but I couldn't find an answer for it.

Anyone knows how to do it? Or any resource that I can have? Thanks!
ApochPiQ
ApochPiQ
Is there a particular reason why you're using MFC? It is old, deprecated, full of weird quirks, and generally hated by pretty much everyone.


That said - it's been years since I've touched it, so I can't remember for sure if there's a way to do this cleanly in MFC itself, but what you need to do is hook the main message pump and add your own code which renders your OpenGL display when no messages are being pumped. Doing this in a standard C/C++ Windows app is downright easy, but the fact that I can't even recall if it's easily possible in MFC should indicate just how overcomplicated and nasty the framework really is.
latent
latent

Hello all,

I just started MFC recently so I'm not very familar with it. Basically my app is a level editor, its a mfc Single Document Interface with openGL. My openGL window is using CView class.
I need my openGL window to render every frame. I know this has been asked many times but I couldn't find an answer for it.

Anyone knows how to do it? Or any resource that I can have? Thanks!


I've used two methods in the past - CWinApp::OnIdle() lets you do something whenever the program is not otherwise engaged, and CWnd::OnTimer() will also let you schedule regular updates. Some (many) years ago I wrote a game in MFC which used OpenGL - basically it was something trivial like:


CMyWnd::CMyWnd() : NeedsToRender(false)
{
}

CMyWnd::OnPaint()
{
DoOpenGLStuff();
NeedsToRender = false;
//...
}

CMyWnd::OnTimer() //or OnIdle
{
if (!NeedsToRender)
{
NeedsToRender = true;
Invalidate(true);
}
//...
}


At least this way, your OpenGL window will also render in response to other windows messages etc, and if it gets 'really busy', it won't fill up your message queue with WM_PAINT messages that you can't service fast enough. But as ApochPiQ says, there are almost certainly better ways these days, unless you've a very good reason to use MFC.
Schinizer
Schinizer

Is there a particular reason why you're using MFC? It is old, deprecated, full of weird quirks, and generally hated by pretty much everyone.


That said - it's been years since I've touched it, so I can't remember for sure if there's a way to do this cleanly in MFC itself, but what you need to do is hook the main message pump and add your own code which renders your OpenGL display when no messages are being pumped. Doing this in a standard C/C++ Windows app is downright easy, but the fact that I can't even recall if it's easily possible in MFC should indicate just how overcomplicated and nasty the framework really is.


Lol I saw your hate for MFC on other topics. Actually I'm using MFC only because I didn't know the existance of WTL and Winform after a proper search on google.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.