Windows Codebeispiel für den Renderingkontext
Das folgende Codebeispiel zeigt, wie der GLX-Renderingkontextcode im vorherigen Abschnitt aussieht, wenn er zu Windows portiert wurde.
HGLRC hRC; // rendering context variable
/* Create and initialize a window */
/* Window message switch in a window procedure */
case WM_CREATE: // Message when window is created
{
HDC hDC, hDCTemp; // device context handles
/* Get the handle of the windows device context. */
hDC = GetDC(hWnd);
/* Create a rendering context and make it the current context */
hRC = wglCreateContext(hDC);
if (!hRC)
{
MessageBox(NULL, "Cannot create context.", "Error", MB_OK);
return FALSE;
}
wglMakeCurrent(hDC, hRC);
}
break;
.
case WM_DESTROYED: // Message when window is destroyed
{
HGLRC hRC // rendering context handle
HDC hDC; // device context handle
/* Release and free the device context and rendering context. */
hDC = wglGetCurrentDC;
hRC = wglGetCurrentContext;
wglMakeCurrent(NULL, NULL);
if (hRC)
wglDeleteContext(hRC);
if (hDC)
ReleaseDC(hWnd, hDC);
PostQuitMessage (0);
}
break;