PDA

View Full Version : Fullscreen AND MFC help plz?



Prico
02-10-2002, 09:46 AM
Hello, I'm learning OpenGL with MFC and everything works fine. But then I tried to put the fullscreen code from NeHe's 1st tutorial in my MFC code but nothing happens! I can switch the display mode to another resolution but the window doesn't go fullscreen. I placed the code in the PreCreate method since the tutorials states that you must switch to fullscreen before you create window. Can anyone help me plz?

marcus256
02-10-2002, 11:08 AM
Not really - I don't know MFC. But I do know GLFW (which I am the author of), and it can do fullscreen for you in only one line of code (!). It has some other nice things too, but only you can decide if it's what you really want:
http://hem.passagen.se/opengl/glfw/

Besides, the GLFW fullscreen code is really alot better than the NeHe code.

Good luck!

Korval
02-10-2002, 04:23 PM
Prico, you can't put all of NeHe's code in PreCreateWindow. Some of that code, like the code to maximize a window, needs to go in OnCreate or perhaps OnSize. These functions need to occur after you create a window.

Prico
02-11-2002, 03:35 AM
Hmm, I found the problem. I put the code in the PreCreate of my View class and it should be in the MainFrm class. Now it goes well, except that I have a border now. I read somewhere this is due to the CFrameWnd and should not occur when using CWnd, so I'm gonna try to inherit the CMainFrame from a CWnd. I'll also check out that GLFW if it doesn't go well.

marcus256
02-11-2002, 03:55 AM
I think that you should check out GLFW anyway. It may not be what you want (it is not able to do Windows GUI stuff, "only" OpenGL window related management - and some other stuff), but it does solve alot of issues with fullscreen mode. For instance:

- It has means for dealing with things like ALT+TAB
- It has some nice code for selecting a best match mode, if an exact match is not available (e.g. you can select a 500x500x17 screen mode, and you would probably get a 640x480x16 mode)
- It has a function for returning a nice sorted list of screen modes
- It also works for Unix/X11 (e.g. Linux)

/Marcus

Prico
02-11-2002, 10:04 AM
I already did go to your site. I'm still learning OpenGl, and I already tried some frameworks, of which I liked none, so now I'm trying to make my own. It's just finished and it works great, no problems anymore. So I don't feel like switching again. And I need MFC for the menu's and stuff, I don't know how to do it otherwise.

J P
02-11-2002, 12:31 PM
Try my websites. There is a full screen MFC demo.
http://pws.prserv.net/mfcogl/

I'd like to know what you think of the site below. It is newer and has a counter.
http://www.mfcogl.com/

Korval
02-11-2002, 02:04 PM
Wait. You can't inherit CMainWnd from CWnd if you're using Doc/View. The CView class expects to find a CFrameWnd (and will likely start casting CWnd's to CFrameWnds). And the CDocument class expects the main window to be a CFrameWnd.

You could instead change the window style of the window that CFrameWnd uses to not have borders. I don't remember the commands, but they almost certainly go in PreCreateWindow. It probably has something to do with changing values in the argument to that function.

Humus
02-12-2002, 08:52 AM
You may want to read my tutorial about OpenGL rendering with MFC: http://hem.passagen.se/emiper/OpenGL/Tutorials/OpenGL_Basic_Framework/index.html

Eric
02-13-2002, 12:25 AM
This routine is the one I use to switch to fullscreen in my MFC apps. The idea was taken from somewhere on the web but I can't remember where (perhaps MSDN ?). Sorry for not being able to credit the author...

The "OnWindowFullscreen" function is the handler for my menu command "Window/Fullscreen". Note when going fullscreen, I hide the Edit and File toolbars but not the others (this software has something like 10 toolbars). You can hide everything if you want...

Also note that this is not real fullscreen: you simply make the view as large as the screen...




void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{

if (m_bFullScreen)
{
lpMMI->ptMaxSize.x=m_rectFullScreenWindow.Width();
lpMMI->ptMaxSize.y=m_rectFullScreenWindow.Height();
lpMMI->ptMaxPosition.x=m_rectFullScreenWindow.left;
lpMMI->ptMaxPosition.y=m_rectFullScreenWindow.top;
lpMMI->ptMinTrackSize.x=lpMMI->ptMaxSize.x;
lpMMI->ptMinTrackSize.y=lpMMI->ptMaxSize.y;
lpMMI->ptMaxTrackSize.x=lpMMI->ptMaxSize.x;
lpMMI->ptMaxTrackSize.y=lpMMI->ptMaxSize.y;
}
else
CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);

}

void CMainFrame::OnWindowFullscreen()
{
CChildFrame *ActiveFrame;
CRect rectDesktop;
WINDOWPLACEMENT wpNew;

ActiveFrame=(CChildFrame*) GetActiveFrame();
if (m_bFullScreen)
{
wpNew=m_wpPrev;
m_bFullScreen=false;
SetWindowPlacement(&wpNew);
ActiveFrame->MDIRestore();
ShowControlBar(&m_wndFileToolBar,m_bMainToolBarVis ible,FALSE);
ShowControlBar(&m_wndEditToolBar,m_bEditToolBarVis ible,FALSE);
RecalcLayout();
}
else
{
m_bFullScreen=true;
m_bMainToolBarVisible=m_wndFileToolBar.IsWindowVis ible();
m_bEditToolBarVisible=m_wndEditToolBar.IsWindowVis ible();
ShowControlBar(&m_wndFileToolBar,FALSE,FALSE);
ShowControlBar(&m_wndEditToolBar,FALSE,FALSE);
RecalcLayout();
ActiveFrame->MDIMaximize();
GetWindowPlacement (&m_wpPrev);
m_wpPrev.length = sizeof m_wpPrev;
//Adjust RECT to new size of window
GetDesktopWindow()->GetWindowRect(&rectDesktop);
AdjustWindowRectEx(&rectDesktop,GetStyle(),TRUE,Ge tExStyle());
// Remember this for OnGetMinMaxInfo()
m_rectFullScreenWindow=rectDesktop;
wpNew=m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition=rectDesktop;
SetWindowPlacement(&wpNew);
RecalcLayout();
}

}


Hope this helps !

Regards.

Eric

Prico
02-15-2002, 05:56 AM
Thanks for all the help. I solved it by starting with an SDI application, without the Doc/View Architecture. Then I deleted almost every class except the main App. Then I built my own window class derived from CWnd. With some adjustements in the App class, I got a very clean OpenGl framework with all the advantages of MFC ( easy message handling etc)

Michalek366
02-18-2002, 02:36 AM
Originally posted by Eric:
Also note that this is not real fullscreen: you simply make the view as large as the screen...


No, it is real. When you maximize the window, which hasnt got a border, you will have a true full screen mode.

U dont belive? So do sth like that:
- create maximized window without border;
- Draw a few frames to be sure it is "hot".
- And if you reach eg. 5 frames, draw a quad in a upper-letf corener of the view.
- SwapBuffers();
- Draw again a quad, but in a lower-right corner.
- SwapBuffers() again;
- And now, dont do anything, just SwapBuffers ().

If you are in fullscreen, you will see a flickering quads, beacuse in a fullscreen frame buffers arent copied but flipped.