示例#1
0
        /// <summary>
        /// Create a simple context.
        /// </summary>
        /// <returns>
        /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be
        /// created, it returns IntPtr.Zero.
        /// </returns>
        internal override IntPtr CreateSimpleContext()
        {
            IntPtr rContext;

            // Define most compatible pixel format
            Wgl.PIXELFORMATDESCRIPTOR pfd = new Wgl.PIXELFORMATDESCRIPTOR(24);
            int  pFormat;
            bool res;

            // Find pixel format match
            pfd.dwFlags |= Wgl.PixelFormatDescriptorFlags.DepthDontCare | Wgl.PixelFormatDescriptorFlags.DoublebufferDontCare | Wgl.PixelFormatDescriptorFlags.StereoDontCare;

            pFormat = Wgl.ChoosePixelFormat(_DeviceContext, ref pfd);
            Debug.Assert(pFormat != 0);

            // Get exact description of the pixel format
            res = Wgl.DescribePixelFormat(_DeviceContext, pFormat, (uint)pfd.nSize, ref pfd);
            Debug.Assert(res);

            // Set pixel format before creating OpenGL context
            res = Wgl.SetPixelFormat(_DeviceContext, pFormat, ref pfd);
            Debug.Assert(res);

            // Create a dummy OpenGL context to retrieve initial informations.
            rContext = CreateContext(IntPtr.Zero);
            Debug.Assert(rContext != IntPtr.Zero);

            return(rContext);
        }