public MyDataInfo() { this.components = new System.ComponentModel.Container(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.CopyLine = new ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.CopyLine }); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(155, 92); this.CopyLine.Text = "复制行距"; this.CopyLine.Size = new System.Drawing.Size(154, 22); this.CopyLine.Click += new System.EventHandler(this.CopyLine_Click); this.contextMenuStrip1.ResumeLayout(false); for (int i = 0; i < 70; i++) { Lcr.Add(new LCR(255, 255, 255, 255, 255, 255, 255)); } windowHandle = this.Handle; deviceContextHandle = Win32.GetDC(windowHandle); Win32.PIXELFORMATDESCRIPTOR pfd = new Win32.PIXELFORMATDESCRIPTOR(); renderContextHandle = Win32.wglCreateContext(deviceContextHandle); this.MouseDown += new MouseEventHandler(MyDataInfo_MouseDown); this.MouseMove += new MouseEventHandler(MyDataInfo_MouseMove); this.MouseUp += new MouseEventHandler(MyDataInfo_MouseUp); this.MouseWheel += new MouseEventHandler(MyDataInfo_MouseWheel); this.ResizeRedraw = true; this.Resize += new EventHandler(MyDataInfo_Resize); }
/// <summary> /// Creates the render context provider. Must also create the OpenGL extensions. /// </summary> /// <param name="openGLVersion">The desired OpenGL version.</param> /// <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> /// <exception cref="System.Exception">A valid Window Handle must be provided for the NativeWindowRenderContextProvider</exception> public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter) { // Call the base. base.Create(openGLVersion, 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 | Win32.PFD_GENERIC_ACCELERATED | Win32.PFD_SWAP_EXCHANGE; pfd.iPixelType = Win32.PFD_TYPE_RGBA; pfd.cColorBits = (byte)bitDepth; pfd.cDepthBits = 8;//16; pfd.cStencilBits = 8; pfd.iLayerType = Win32.PFD_MAIN_PLANE; //pfd.cAccumBits = 32; // 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(); // Update the render context if required. UpdateContextVersion(gl); // Return success. return(true); }
/// <summary> /// Creates the render context provider. Must also create the OpenGL extensions. /// </summary> /// <param name="openGLVersion">The desired OpenGL version.</param> /// <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> /// <exception cref="System.Exception">A valid Window Handle must be provided for the NativeWindowRenderContextProvider</exception> public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter) { // Call the base. base.Create(openGLVersion, 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(); // Update the render context if required. UpdateContextVersion(gl); // Return success. return true; }
private void InitRenderContext(IntPtr hwnd) { hdc = Win32.GetDC(hwnd); // 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)16; pfd.cDepthBits = 16; pfd.cStencilBits = 8; pfd.iLayerType = Win32.PFD_MAIN_PLANE; // Match an appropriate pixel format int iPixelformat; if ((iPixelformat = Win32.ChoosePixelFormat(hdc, pfd)) == 0) { MessageBox.Show("ChoosePixelFormat"); return; } // Sets the pixel format if (Win32.SetPixelFormat(hdc, iPixelformat, pfd) == 0) { MessageBox.Show("SetPixelFormat"); return; } hrc = Win32.wglCreateContext(hdc); if (hrc == IntPtr.Zero) { MessageBox.Show("创建渲染上下文失败"); return; } }
/// <summary> /// Creates the render context provider. Must also create the OpenGL extensions. /// </summary> /// <param name="openGLVersion">The desired OpenGL version.</param> /// <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(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter) { // Call the base. base.Create(openGLVersion, 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(); // Update the context if required. UpdateContextVersion(gl); // Return success. return(true); }
/// <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) { this.gl = gl; // 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 = 24; pfd.cDepthBits = 24; pfd.cStencilBits = 8; pfd.cAlphaBits = 8; pfd.cAuxBuffers = 0; pfd.iLayerType = Win32.PFD_MAIN_PLANE; pfd.cAccumBits = 0; // 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(); multiSampleExtensionsAvailable = gl.IsExtensionFunctionSupported("glRenderbufferStorageMultisampleEXT") && gl.IsExtensionFunctionSupported("glBlitFramebufferEXT"); CreateFramebuffers(); // Return success. return(true); }
/// <summary> /// Creates the render context provider. Must also create the OpenGL extensions. /// </summary> /// <param name="openGLVersion">The desired OpenGL version.</param> /// <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(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter) { // Call the base. base.Create(openGLVersion, 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(); // Update the context if required. UpdateContextVersion(gl); // Return success. return true; }