建立轉譯內容並將其設定為最新狀態
下列程式碼範例示範如何建立 OpenGL 轉譯內容,以回應WM_CREATE訊息。 請注意,您會在建立轉譯內容之前設定像素格式。 另請注意,在此案例中,裝置內容不會在本機發行;當視窗關閉時,您會在讓轉譯內容成為目前狀態之後釋出它。 如需詳細資訊,請參閱 刪除轉譯內容。 最後,請注意,您可以針對裝置內容和轉譯內容控制碼使用區域變數,因為搭配 wglGetCurrentCoNtext 和 wglGetCurrentDC 函式,您可以視需要取得這些內容的控制碼。
// a window has been created, but is not yet visible
case WM_CREATE:
{
// local variables
HDC hdc ;
HGLRC hglrc ;
// obtain a device context for the window
hdc = GetDC(hWnd);
// set an appropriate pixel format
myPixelFormatSetupFunction(hdc);
// if we can create a rendering context ...
if (hglrc = wglCreateContext( hdc ) ) {
// try to make it the thread's current rendering context
bHaveCurrentRC = wglMakeCurrent(hdc, hglrc) ;
}
// perform miscellaneous other WM_CREATE chores ...
}
break;