Vector.Win32.Gdi.SetPixelFormat C# (CSharp) Méthode

SetPixelFormat() public static méthode

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);
public static SetPixelFormat ( IntPtr deviceContext, int pixelFormat, PIXELFORMATDESCRIPTOR &pixelFormatDescriptor ) : bool
deviceContext System.IntPtr /// Specifies the device context whose pixel format the function attempts to set. ///
pixelFormat int /// Index that identifies the pixel format to set. The various pixel formats supported by a device /// context are identified by one-based indexes. ///
pixelFormatDescriptor PIXELFORMATDESCRIPTOR /// Pointer to a structure that contains the logical pixel /// format specification. The system's metafile component uses this structure to record the logical /// pixel format specification. The structure has no other effect upon the behavior of the /// SetPixelFormat function. ///
Résultat bool
        public static bool SetPixelFormat(IntPtr deviceContext, int pixelFormat, ref PIXELFORMATDESCRIPTOR pixelFormatDescriptor)
        {
            Kernel.LoadLibrary("opengl32.dll");
            return _SetPixelFormat(deviceContext, pixelFormat, ref pixelFormatDescriptor);
        }
        #endregion BOOL SetPixelFormat(HDC hdc, int iPixelFormat, PIXELFORMATDESCRIPTOR* ppfd)