CSharpGL.DIBSection.Create C# (CSharp) Method

Create() public method

Creates the specified width.
public Create ( IntPtr deviceContext, int width, int height, int bitCount ) : bool
deviceContext System.IntPtr
width int The width.
height int The height.
bitCount int The bit count.
return bool
        public virtual bool Create(IntPtr deviceContext, int width, int height, int bitCount)
        {
            this.Width = width;
            this.Height = height;
            this.MemoryDeviceContext = Win32.CreateCompatibleDC(deviceContext);

            //	Destroy existing objects.
            this.DestroyBitmap();

            //	Create a bitmap info structure.
            var info = new BitmapInfo();
            info.Init();

            //	Set the data.
            info.biBitCount = (short)bitCount;
            info.biPlanes = 1;
            info.biWidth = width;
            info.biHeight = height;

            //	Create the bitmap.
            IntPtr mdc = this.MemoryDeviceContext;
            this.HBitmap = Win32.CreateDIBSection(mdc, ref info, Win32.DIB_RGB_COLORS, out this.bits, IntPtr.Zero, 0);

            Win32.SelectObject(mdc, this.HBitmap);

            //	Set the OpenGL pixel format.
            SetPixelFormat(mdc, bitCount);

            return true;
        }

Usage Example

Example #1
0
        //static List<WeakReference<FBORenderContext>> renderContextList = new List<WeakReference<FBORenderContext>>();
        //public FBORenderContext()
        //{
        //    renderContextList.Add(new WeakReference<FBORenderContext>(this));
        //}

        //public override void Destroy()
        //{
        //    bool found = false;
        //    WeakReference<FBORenderContext> target = null;
        //    for (int index = 0; index < renderContextList.Count; index++)
        //    {
        //        target = renderContextList[index];
        //        FBORenderContext context;
        //        if (target.TryGetTarget(out context))
        //        {
        //            if (context == this)
        //            { break; }
        //        }
        //    }
        //    if (found)
        //    {
        //        renderContextList.Remove(target);
        //    }

        //    base.Destroy();
        //}
        //public static FBORenderContext GetCurrentRenderContext()
        //{
        //    IntPtr renderContext = Win32.wglGetCurrentContext();

        //}

        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="bitDepth"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public override bool Create(int width, int height, int bitDepth, object parameter)
        {
            //  Call the base class.
            base.Create(width, height, bitDepth, parameter);

            // Create frame buffer object.
            Framebuffer framebuffer = CreateFramebuffer(width, height);

            this.framebuffer = framebuffer;

            //  Create the DIB section.
            var dibSection = new DIBSection();

            dibSection.Create(this.DeviceContextHandle, width, height, bitDepth);
            this.dibSection = dibSection;

            return(true);
        }
All Usage Examples Of CSharpGL.DIBSection::Create