4 #include "window_private.h"
9 typedef HGLRC ContextHandle;
11 struct GLContext::Private
13 ContextHandle context;
17 void GLContext::platform_init(const GLOptions &opts)
19 HDC dc = GetDC(window.get_private().window);
21 PIXELFORMATDESCRIPTOR pfd;
22 memset(&pfd, 0, sizeof(pfd));
24 pfd.nSize = sizeof(pfd);
26 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
28 pfd.dwFlags |= PFD_DOUBLEBUFFER;
29 pfd.iPixelType = PFD_TYPE_RGBA;
36 int pf_index = ChoosePixelFormat(dc, &pfd);
38 throw unsupported_gl_mode(opts);
39 SetPixelFormat(dc, pf_index, &pfd);
42 priv->context = wglCreateContext(dc);
43 wglMakeCurrent(dc, priv->context);
45 ReleaseDC(window.get_private().window, dc);
48 GLContext::~GLContext()
51 wglDeleteContext(priv->context);
56 void GLContext::swap_buffers()
58 HDC dc = GetDC(window.get_private().window);
60 ReleaseDC(window.get_private().window, dc);
63 void GLContext::window_resized(unsigned w, unsigned h)
65 glViewport(0, 0, w, h);
68 } // namespace Graphics