This article will introduce a method that does not rely on any third-party libraries to build its own WIN32 application window, the total length of the program is 77 lines, the source code download please see the attachment. If you don't know how to do this step-by-step, take a look at the video tutorials for the OpenGL introductory course.
#include <windows.h> #include <gl/GL.h> #include <gl/GLU.h> #pragma comment (Lib, "Opengl32.lib") Lresult callback renderwindowproc (hwnd hwnd, uint msg, wparam wparam, Lparam lparam) {switch (msg) {case wm_close:postquitmessage (0); break;} Return defwindowproc (Hwnd, msg, wparam, lparam);} Int winapi winmain (_in_ hinstance hinstance, _in_opt_ hinstance Hprevinstance, _in_ lpstr lpcmdline, _in_ int nshowcmd) {WNDCLASSEX wndClass ; wndclass.cbclsextra = 0;wndclass.cbsize = sizeof (wndclassex); wndClass.cbWndExtra = 0;wndclass.hbrbackground = null;wndclass.hcursor = loadcursor (NULL, IDC_ARROW); wndclass.hicon = null;wndclass.hiconsm = null;wndclass.hinstance = hinstance; Wndclass.lpfnwndproc = renderwindowproc;wndclass.lpszclassname&nBsp;= l "Openglwindow"; wndclass.lpszmenuname = null;wndclass.style = cs_hredraw | CS_VREDRAW; Atom atom = registerclassex (&wndclass); Hwnd hwnd = createwindowex (null,l "Openglwindow", L "Opengl render window", WS_ Overlappedwindow,100,100,800,600,null,null,hinstance,null); HDC&NBSP;DC&NBSP;=&NBSP;GETDC (HWND); Pixelformatdescriptor pfd;memset (&pfd, 0, sizeof (pixelformatdescriptor));p fd.nversion = 1;pfd.dwflags = pfd_doublebuffer | pfd_draw_to_window | pfd_support_ Opengl | pfd_type_rgba;pfd.ilayertype = pfd_main_plane;pfd.ipixeltype = pfd_type _rgba;pfd.ccolorbits = 32;pfd.cdepthbits = 24;pfd.cstencilbits = 8;int Pixelformatid = choosepixelformat (DC,&NBSP;&PFD); Setpixelformat (DC,&NBSP;PIXELFORMATID,&NBSP;&PFD); Hglrc rc = wglcreatecontext (DC); Wglmakecurrent (Dc, rc); Glclearcolor (41.0 / 255.0f, 71.0f / 255.0f, 121.0f / 255.0f, 1.0f); ShowWindow (hwnd, sw_show); UpdateWindow (HWND); msg msg;while (True) {if (PeekMessage (&msg,null,null,null,pm_remove)) {if (msg.message== Wm_quit) {break;} TranslateMessage (&msg);D ispatchmessage (&msg);} Glclear (Gl_color_buffer_bit); Swapbuffers (DC);} return 0;}
This article is from the "Instant Fire" blog, please be sure to keep this source http://battlefire.blog.51cto.com/11961165/1841269
WIN32+OPENGL Application Framework (77 lines of code)