Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2015 03:38
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 anonymous/c467efadc85c0389ea5a to your computer and use it in GitHub Desktop.
Save anonymous/c467efadc85c0389ea5a to your computer and use it in GitHub Desktop.
PIXELFORMATDESCRIPTOR pixelFormatDesc;
memset(&pixelFormatDesc, 0, sizeof(PIXELFORMATDESCRIPTOR));
pixelFormatDesc.nSize = sizeof(pixelFormatDesc);
pixelFormatDesc.nVersion = 1;
pixelFormatDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pixelFormatDesc.iPixelType = PFD_TYPE_RGBA;
pixelFormatDesc.cColorBits = 24;
pixelFormatDesc.cDepthBits = 16;
pixelFormatDesc.iLayerType = PFD_MAIN_PLANE;
HDC deviceContext;
if (!(deviceContext = GetDC(hWnd)))
{
std::wstringstream ss;
ss << "Can't Create A GL Device Context. (0x" << std::hex << GetLastError() << ')';
MessageBox(nullptr, ss.str().c_str(), L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return nullptr;
}
int pixelFormat;
if (!(pixelFormat = ChoosePixelFormat(deviceContext, &pixelFormatDesc)))
{
std::wstringstream ss;
ss << "Can't Find A Suitable PixelFormat. (0x" << std::hex << GetLastError() << ')';
MessageBox(nullptr, ss.str().c_str(), L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return nullptr;
}
if (!SetPixelFormat(deviceContext, pixelFormat, &pixelFormatDesc))
{
std::wstringstream ss;
ss << "Can't Set The PixelFormat. (0x" << std::hex << GetLastError() << ')';
MessageBox(nullptr, ss.str().c_str(), L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return nullptr;
}
HGLRC renderContext;
if (!(renderContext = wglCreateContext(deviceContext)))
{
MessageBox(nullptr, L"Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return nullptr;
}
if (!wglMakeCurrent(deviceContext, renderContext))
{
MessageBox(nullptr, L"Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return nullptr;
}
return new Engine(hWnd, deviceContext, renderContext);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment