Skip to content

Instantly share code, notes, and snippets.

@JustSid
Last active December 11, 2015 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustSid/4549722 to your computer and use it in GitHub Desktop.
Save JustSid/4549722 to your computer and use it in GitHub Desktop.
_hWnd = CreateOffscreenWindow();
_hDC = GetDC(_hWnd);
PIXELFORMATDESCRIPTOR descriptor;
memset(&descriptor, 0, sizeof(PIXELFORMATDESCRIPTOR));
descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR);
descriptor.nVersion = 1;
descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
descriptor.iPixelType = PFD_TYPE_RGBA;
descriptor.cColorBits = 24;
descriptor.cAlphaBits = 8;
descriptor.iLayerType = PFD_MAIN_PLANE;
_pixelFormat = ChoosePixelFormat(_hDC, &descriptor);
SetPixelFormat(_hDC, _pixelFormat, &descriptor);
if(!wglCreateContextAttribsARB)
{
HGLRC _temp = wglCreateContext(_hDC);
wglMakeCurrent(_hDC, _temp);
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
std::string extensions = std::string((const char *)wglGetExtensionsStringARB(_hDC));
auto createContext = extensions.find("WGL_ARB_create_context");
auto coreProfile = extensions.find("WGL_ARB_create_context_profile");
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
wglMakeCurrent(_hDC, 0);
wglDeleteContext(_temp);
}
int attributes[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
};
_context = wglCreateContextAttribsARB(_hDC, _shared ? _shared->_context : 0, attributes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment