CSharpGL.DIBSection.SetPixelFormat C# (CSharp) Method

SetPixelFormat() protected method

This function sets the pixel format of the underlying bitmap.
protected SetPixelFormat ( IntPtr hDC, int bitCount ) : bool
hDC System.IntPtr
bitCount int The bitcount.
return bool
        protected virtual bool SetPixelFormat(IntPtr hDC, int bitCount)
        {
            //	Create the big lame pixel format majoo.
            var pixelFormat = new PixelFormatDescriptor();
            pixelFormat.Init();

            //	Set the values for the pixel format.
            pixelFormat.nVersion = 1;
            pixelFormat.dwFlags = (Win32.PFD_DRAW_TO_BITMAP | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_SUPPORT_GDI);
            pixelFormat.iPixelType = Win32.PFD_TYPE_RGBA;
            pixelFormat.cColorBits = (byte)bitCount;
            pixelFormat.cDepthBits = 32;
            pixelFormat.iLayerType = Win32.PFD_MAIN_PLANE;

            //	Match an appropriate pixel format
            int iPixelformat = Win32.ChoosePixelFormat(hDC, pixelFormat);
            if (iPixelformat == 0) { return false; }

            //	Sets the pixel format
            if (Win32.SetPixelFormat(hDC, iPixelformat, pixelFormat) == 0)
            {
                int lastError = Marshal.GetLastWin32Error();
                return false;
            }

            return true;
        }