WIN32+OPENGL Application Framework (77 lines of code)

Source: Internet
Author: User

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;&AMP;PFD); Setpixelformat (DC,&NBSP;PIXELFORMATID,&NBSP;&AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.