-
-
Save anonymous/c467efadc85c0389ea5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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