コード例 #1
0
ファイル: DIBSection.cs プロジェクト: DarkCloud14/sharpcoregl
        /// <summary>
        /// This function sets the pixel format of the underlying bitmap.
        /// </summary>
        /// <param name="hDC">The handle to the device context.</param>
        /// <param name="bitCount">The bitcount.</param>
        protected virtual bool SetPixelFormat(IntPtr hDC, int bitCount)
        {
            //	Create the big lame pixel format majoo.
            Win32.PIXELFORMATDESCRIPTOR pixelFormat = new Win32.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;

            if ((iPixelformat = Win32.ChoosePixelFormat(hDC, pixelFormat)) == 0)
            {
                return(false);
            }

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

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns></returns>
        public override bool Create(OpenGL gl, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(gl, width, height, bitDepth, parameter);

            //  Cast the parameter to the device context.
            try
            {
                windowHandle = (IntPtr)parameter;
            }
            catch
            {
                throw new Exception("A valid Window Handle must be provided for the NativeWindowRenderContextProvider");
            }

            //	Get the window device context.
            deviceContextHandle = Win32.GetDC(windowHandle);

            //	Setup a pixel format.
            Win32.PIXELFORMATDESCRIPTOR pfd = new Win32.PIXELFORMATDESCRIPTOR();
            pfd.Init();
            pfd.nVersion     = 1;
            pfd.dwFlags      = Win32.PFD_DRAW_TO_WINDOW | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_DOUBLEBUFFER;
            pfd.iPixelType   = Win32.PFD_TYPE_RGBA;
            pfd.cColorBits   = (byte)bitDepth;
            pfd.cDepthBits   = 16;
            pfd.cStencilBits = 8;
            pfd.iLayerType   = Win32.PFD_MAIN_PLANE;

            //	Match an appropriate pixel format
            int iPixelformat;

            if ((iPixelformat = Win32.ChoosePixelFormat(deviceContextHandle, pfd)) == 0)
            {
                return(false);
            }

            //	Sets the pixel format
            if (Win32.SetPixelFormat(deviceContextHandle, iPixelformat, pfd) == 0)
            {
                return(false);
            }

            //	Create the render context.
            renderContextHandle = Win32.wglCreateContext(deviceContextHandle);

            //  Make the context current.
            MakeCurrent();

            //  Return success.
            return(true);
        }
コード例 #3
0
ファイル: DIBSection.cs プロジェクト: jochemgeussens/sharpgl
        /// <summary>
        /// This function sets the pixel format of the underlying bitmap.
        /// </summary>
        /// <param name="bitCount">The bitcount.</param>
        protected virtual bool SetPixelFormat(IntPtr hDC, int bitCount)
        {
            //	Create the big lame pixel format majoo.
            Win32.PIXELFORMATDESCRIPTOR pixelFormat = new Win32.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;
            if((iPixelformat = Win32.ChoosePixelFormat(hDC, pixelFormat)) == 0 )
                return false;

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

            return true;
        }
コード例 #4
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(OpenGL gl, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(gl, width, height, bitDepth, parameter);

            //	Create a new window class, as basic as possible.
            Win32.WNDCLASSEX wndClass = new Win32.WNDCLASSEX();
            wndClass.Init();
            wndClass.style         = Win32.ClassStyles.HorizontalRedraw | Win32.ClassStyles.VerticalRedraw | Win32.ClassStyles.OwnDC;
            wndClass.lpfnWndProc   = wndProcDelegate;
            wndClass.cbClsExtra    = 0;
            wndClass.cbWndExtra    = 0;
            wndClass.hInstance     = IntPtr.Zero;
            wndClass.hIcon         = IntPtr.Zero;
            wndClass.hCursor       = IntPtr.Zero;
            wndClass.hbrBackground = IntPtr.Zero;
            wndClass.lpszMenuName  = null;
            wndClass.lpszClassName = "SharpGLRenderWindow";
            wndClass.hIconSm       = IntPtr.Zero;
            Win32.RegisterClassEx(ref wndClass);

            //	Create the window. Position and size it.
            windowHandle = Win32.CreateWindowEx(0,
                                                "SharpGLRenderWindow",
                                                "",
                                                Win32.WindowStyles.WS_CLIPCHILDREN | Win32.WindowStyles.WS_CLIPSIBLINGS | Win32.WindowStyles.WS_POPUP,
                                                0, 0, width, height,
                                                IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            //	Get the window device context.
            deviceContextHandle = Win32.GetDC(windowHandle);

            //	Setup a pixel format.
            Win32.PIXELFORMATDESCRIPTOR pfd = new Win32.PIXELFORMATDESCRIPTOR();
            pfd.Init();
            pfd.nVersion     = 1;
            pfd.dwFlags      = Win32.PFD_DRAW_TO_WINDOW | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_DOUBLEBUFFER;
            pfd.iPixelType   = Win32.PFD_TYPE_RGBA;
            pfd.cColorBits   = (byte)bitDepth;
            pfd.cDepthBits   = 16;
            pfd.cStencilBits = 8;
            pfd.iLayerType   = Win32.PFD_MAIN_PLANE;

            //	Match an appropriate pixel format
            int iPixelformat;

            if ((iPixelformat = Win32.ChoosePixelFormat(deviceContextHandle, pfd)) == 0)
            {
                return(false);
            }

            //	Sets the pixel format
            if (Win32.SetPixelFormat(deviceContextHandle, iPixelformat, pfd) == 0)
            {
                return(false);
            }

            //	Create the render context.
            renderContextHandle = Win32.wglCreateContext(deviceContextHandle);

            //  Make the context current.
            MakeCurrent();

            //  Return success.
            return(true);
        }