Win32 Rendering Context Code Sample

The following code sample shows how the GLX rendering context code in the previous section looks when it has been ported to Windows NT and Windows 95 using Win32 functions.

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;