1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| // Obtention du "Device context"
hDC = ::GetDC(hWnd);
if (hDC == 0) {
return false;
}
// On choisit le format pour le "Device context"
PIXELFORMATDESCRIPTOR pfd;
::ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.cStencilBits = 1;
pfd.iLayerType = PFD_MAIN_PLANE;
int format = ::ChoosePixelFormat(hDC, &pfd);
if (format == 0) {
::ReleaseDC(hWnd, hDC);
hDC = 0;
return false;
}
if (!::SetPixelFormat(hDC, format, &pfd)) {
::ReleaseDC(hWnd, hDC);
hDC = 0;
return false;
}
// Cr�ation du contexte
hRC = ::wglCreateContext(hDC);
if (hRC == 0) {
::ReleaseDC(hWnd, hDC);
hDC = 0;
return false;
}
// Activation du contexte
if (!::wglMakeCurrent(hDC, hRC)) {
::wglDeleteContext(hRC);
hRC = 0;
::ReleaseDC(hWnd, hDC);
hDC = 0;
return false;
}
// Tout s'est bien pass�
return true; |
Partager