Leggere in inglese

Condividi tramite


Scelta e impostazione di un formato pixel Best-Match

In questo argomento viene illustrata la procedura per associare un contesto di dispositivo a un formato pixel.

Per ottenere la corrispondenza migliore del contesto di dispositivo con un formato pixel

  1. Specificare il formato pixel desiderato in una struttura PIXELFORMATDESCRIPTOR.

  2. Chiamare ChoosePixelFormat.

    La funzione ChoosePixelFormat restituisce un indice di formato pixel, che è quindi possibile passare a SetPixelFormat per impostare la corrispondenza del formato pixel migliore come formato pixel corrente del contesto del dispositivo.

L'esempio di codice seguente illustra come eseguire i passaggi precedenti.

PIXELFORMATDESCRIPTOR pfd = { 
    sizeof(PIXELFORMATDESCRIPTOR),    // size of this pfd  
    1,                                // version number  
    PFD_DRAW_TO_WINDOW |              // support window  
    PFD_SUPPORT_OPENGL |              // support OpenGL  
    PFD_DOUBLEBUFFER,                 // double buffered  
    PFD_TYPE_RGBA,                    // RGBA type  
    24,                               // 24-bit color depth  
    0, 0, 0, 0, 0, 0,                 // color bits ignored  
    0,                                // no alpha buffer  
    0,                                // shift bit ignored  
    0,                                // no accumulation buffer  
    0, 0, 0, 0,                       // accum bits ignored  
    32,                               // 32-bit z-buffer      
    0,                                // no stencil buffer  
    0,                                // no auxiliary buffer  
    PFD_MAIN_PLANE,                   // main layer  
    0,                                // reserved  
    0, 0, 0                           // layer masks ignored  
}; 
HDC  hdc; 
int  iPixelFormat; 
 
// get the device context's best, available pixel format match  
iPixelFormat = ChoosePixelFormat(hdc, &pfd); 
 
// make that match the device context's current pixel format  
SetPixelFormat(hdc, iPixelFormat, &pfd);