Exemple #1
0
 public static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
        public void Start()
        {
            new Task(() =>
            {
                RegisterClass();
                CreateWindow();

                _hdc = User32.GetDC(_handle);

                if (_hdc == IntPtr.Zero) throw new Exception("Failed to get Device Context");
                var pfd = new PixelFormatDescriptor
                {
                    Size = PixelFormatDescriptor.SizeInBytes,
                    Version = 1,
                    Flags =
                        PixelFormatDescriptorFlags.DrawToWindow | PixelFormatDescriptorFlags.SupportOpenGL |
                        PixelFormatDescriptorFlags.DoubleBuffer,
                    PixelType = PixelType.RGBA,
                    ColorBits = (byte)Bits,
                    DepthBits = 16,
                };

                var pixelformat = GDI32.ChoosePixelFormat(_hdc, ref pfd);
                if (pixelformat == 0) throw new Exception("Failed to get find pixel format");
                if (!GDI32.SetPixelFormat(_hdc, pixelformat, ref pfd)) throw new Exception("Can't Set The PixelFormat.");

                _glHandle = WGL.CreateContext(_hdc);
                if (_glHandle == IntPtr.Zero) throw new Exception("Failed to create context");

                MakeCurrent();

                User32.ShowWindow(_handle, ShowWindowCommand.Show);
                User32.SetForegroundWindow(_handle);
                User32.SetFocus(_handle);

                if (Resized != null) Resized(Width, Height);
                if (Load != null) Load();
                //User32.ChangeDisplaySettingsEx()

                ProcessEvents();
            }).Start();
        }
Exemple #3
0
 public static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);