Game Development Reference
Figure 3.2 MFC Example program.
aim to teach MFC, you will need to get hold of an MFC book for further
information if you are not familiar with this Windows programming style.
Appendix B gives a very brief introduction to MFC. You will find the example
'MFCExample' on the CD, the basis for the code snippet in this section.
Many of the ideas from the GLUT example are repeated. There is a resize
event, a mouse move event and a paint event which is the equivalent of
'display'. These echo similar callbacks in the GLUT example.
Working through the code example, we created a Dialog-based
OpenGL application. 'OpenGL32.lib' and 'Glu32.lib' were added to the
linker in the dialog box for 'Program Settings' and 'gl.h' and 'glu.h' are
added as include files. You could add these to 'stdafx.h' if you choose or
to all files that include OpenGL code. Where the code for this example
departs radically from the first is in window creation. Unlike the GLUT
example, you have to do considerably more work when creating a window
suitable for OpenGL. You will need to use class wizard to create a
'PreCreateWindow' method and an 'OnCreate' function.
OpenGL needs the window to have the styles WS_CLIPCHILDREN
and WS_CLIPSIBLINGS set. So we set these in the PreCreateWindow
function by bitwise Or-ing the CREATESTRUCT member 'style' with
BOOL CWGLExampleDlg::PreCreateWindow(CREATESTRUCT& cs)
cs.style |= (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);