I have browsed online online introductory, not the console is Windows C programming, I feel very inconvenient. So I will give you an OpenGL's MFC introductory :)
Note: The principle of OpenGL programming under Windows, I don't talk about it here. Please refer to books: D
I know, those console programs and Windows C programs, the created window is a very simple window.
Here first to describe the steps:
1. Create a new MFC Wizard, named GLFrame, single document, remove print support, the rest of the default, generate an OpenGL framework.
2. Get a simple window style.
Add precreateWindow code in cmianframe:
Bool CMAINFRAME :: PrecreateWindow (CreateStruct & Cs) {if (! Cframewnd :: PrecreateWindow (CS)) Return False;
Cs.cx = 500; cs.cy = 400; cs.lpszname = _t ("OpenGL Framework Program"); cs.style & = ~ fws_addtotitle; // Do not add title to title bar return true;}
3. Add OpenGL support:
Add header files in cglframeView.h as follows:
#include "gl / gl.h" #include "gl / glu.h" #include "gl / glaux.h"
In the Project -> Settings -> Project Settings dialog box Select the LINK tab, join the GLAUX.LIB Glu32.lib opengl32.lib in the Object Module library.
(Tip: Of course, you can also choose Engineering -> Add to Enginee -> Add File Command, pop-up Insert Files Into Project dialog box, switch to the VC98 / LIB directory, select Glaux.lib, Glu32.Lib, OpenGL32. These files, press OK, add them to the project file.)
(Write here, there is no time today, I will write it tomorrow)
Today 2004/6/25
The following operations are performed in CGLFrameView
4. Add an RC handle to the view, a common variable
Class CGLFrameView: Public CVIEW
{
PUBLIC:
... // Other variables
Hglrc hglrc;
... // Other variables
}
5. Add a message to the view:
Add WM_CREATE, WM_DESTROY, WM_SIZE, add WM_CREATE, WM_DESTROY, WM_SIZE.
6. Modify the precreateWindow () function of cgframeView as follows:
Bool CGLFrameView :: PrecreateWindow (CreateStruct & Cs) {// Todo: Modify The window Class or Styles Here by MODIFYING // The Createstruct CS
CS.Style | = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; RETURN CVIEW :: PrecreateWindow (CS);
7. Modify the oncreate () function of cgframeView as follows:
INT cglframeview :: oncreate (lpcreatestruct lpcreatestruct) {if (cView :: oncreate (lpcreateStruct) == -1) Return -1; // ==================== =============== PIXELFORMATDESCRIPTOR pfd = {sizeof (PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_GDI, PFD_TYPE_RGBA, 24, 0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0}; cclientdc clientdc (this); int Pf = choosepixelformat (ClientDc.m_hdc, & pfd); BOOL Rt = setpixelformat (clientdc.m_hdc, pf, & pfd); hglrc = wglcreateContext (clientdc.m_hdc); // ========================== =============================} 8. Modify the onDestroy () function of the cgframeView is as follows:
void CGLFrameView :: OnDestroy () {CView :: OnDestroy (); // TODO: (! wglGetCurrentContext () = NULL) Add your message handler code here if wglMakeCurrent (NULL, NULL); if (hglrc = NULL!) {wglDeleteContext (hglrc); hglrc = null;}}
9. Modify the onsize () function of the cgframeView as follows:
Void cglframeview :: Onsize (uint ntype, int cx, int Cy) {cview :: Onsize (NTYPE, CX, CY);
Glsizei W = CX; Glsizei H = cy; if (! H) return; cclientdc clientdc (this); WGLmakecurrent (clientdc.m_hdc, hglrc); GLVIEWPORT (0, 0, W, h); WGLmakecurrent (null, null); / ** /}
The above is the basic work that must be done with OpenGL programming ^ _ *
Draw a straight line and draw some of the tea pot tomorrow, complete this example.