SetPixelFormat ( IntPtr deviceContext, int pixelFormat, PIXELFORMATDESCRIPTOR &pixelFormatDescriptor ) : bool |
The SetPixelFormat function sets the pixel format of the specified device context to the format specified by the iPixelFormat index. If hdc references a window, calling the SetPixelFormat function also changes the pixel format of the window. Setting the pixel format of a window more than once can lead to significant complications for the Window Manager and for multithread applications, so it is not allowed. An application can only set the pixel format of a window one time. Once a window's pixel format is set, it cannot be changed.
You should select a pixel format in the device context before calling the Wgl.wglCreateContext function. The wglCreateContext function creates a rendering context for drawing on the device in the selected pixel format of the device context.
An OpenGL window has its own pixel format. Because of this, only device contexts retrieved for the client area of an OpenGL window are allowed to draw into the window. As a result, an OpenGL window should be created with the WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles. Additionally, the window class attribute should not include the CS_PARENTDC style.
The following code example shows SetPixelFormat usage:
HDC hdc; int pixelFormat; Gdi.PIXELFORMATDESCRIPTOR pfd; // size of this pfd pfd.nSize = (ushort) sizeof(Gdi.PIXELFORMATDESCRIPTOR); // version number pfd.nVersion = 1; // support window, support OpenGL, double buffered pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW | Gdi.PFD_SUPPORT_OPENGL | Gdi.PFD_DOUBLEBUFFER; // RGBA type pfd.iPixelType = Gdi.PFD_TYPE_RGBA; // 24-bit color depth pfd.cColorBits = 24; // color bits and shift bits ignored pfd.cRedBits = 0; pfd.cRedShift = 0; pfd.cGreenBits = 0; pfd.cGreenShift = 0; pfd.cBlueBits = 0; pfd.cBlueShift = 0; pfd.cAlphaBits = 0; pfd.cAlphaShift = 0; // no accumulation buffer, accum bits ignored pfd.cAccumBits = 0; pfd.cAccumRedBits = 0; pfd.cAccumGreenBits = 0; pfd.cAccumBlueBits = 0; pfd.cAccumAlphaBits = 0; // no stencil buffer pfd.cStencilBits = 0; // no auxiliary buffer pfd.cAuxBuffers = 0; // main layer pfd.iLayerType = Gdi.PFD_MAIN_PLANE; // reserved pfd.bReserved = 0; // layer masks ignored pfd.dwLayerMask = 0; pfd.dwVisibleMask = 0; pfd.dwDamageMask = 0; pixelFormat = Gdi.ChoosePixelFormat(hdc, &pfd); // make that the pixel format of the device context Gdi.SetPixelFormat(hdc, pixelFormat, &pfd); |
|