4 #include "window_private.h"
9 typedef HGLRC ContextHandle;
11 struct GLContext::Private
13 ContextHandle context;
17 void GLContext::platform_init(const GLOptions &opts)
21 HDC dc = GetDC(window.get_private().window);
23 PIXELFORMATDESCRIPTOR pfd;
24 memset(&pfd, 0, sizeof(pfd));
26 pfd.nSize = sizeof(pfd);
28 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
30 pfd.dwFlags |= PFD_DOUBLEBUFFER;
31 pfd.iPixelType = PFD_TYPE_RGBA;
38 int pf_index = ChoosePixelFormat(dc, &pfd);
40 throw unsupported_gl_mode(opts);
41 SetPixelFormat(dc, pf_index, &pfd);
43 priv->context = wglCreateContext(dc);
44 wglMakeCurrent(dc, priv->context);
46 ReleaseDC(window.get_private().window, dc);
49 GLContext::~GLContext()
52 wglDeleteContext(priv->context);
57 void GLContext::swap_buffers()
59 HDC dc = GetDC(window.get_private().window);
61 ReleaseDC(window.get_private().window, dc);
64 void GLContext::window_resized(unsigned w, unsigned h)
66 glViewport(0, 0, w, h);
69 } // namespace Graphics