protected void CreateFakeWnd() { WNDCLASSEX wndClsEx = new WNDCLASSEX(); wndClsEx.Init(); wndClsEx.style = WndClassType.CS_VREDRAW | WndClassType.CS_HREDRAW; wndClsEx.lpfnWndProc = m_DefWndProcDelegate; wndClsEx.cbClsExtra = 0; wndClsEx.cbWndExtra = 0; wndClsEx.hInstance = NativeMethods.GetModuleHandle(null); wndClsEx.hIcon = IntPtr.Zero; wndClsEx.hIconSm = IntPtr.Zero; wndClsEx.hCursor = IntPtr.Zero; wndClsEx.hbrBackground = IntPtr.Zero; wndClsEx.lpszClassName = m_WndClsName; wndClsEx.lpszMenuName = null; bool success = NativeMethods.RegisterClassEx(ref wndClsEx) != 0; Debug.Assert(success, "RegisterWndClass failed."); UInt32 dwExStyle = WS_EX.WS_EX_LAYERED | WS_EX.WS_EX_TRANSPARENT | WS_EX.WS_EX_NOACTIVATE | WS_EX.WS_EX_LEFT; UInt32 dwStyle = (uint)WindowStyle.WS_VISIBLE | (uint)WindowStyle.WS_OVERLAPPED; m_FakeWndHandle = NativeMethods.CreateWindowEx((Int32)dwExStyle , m_WndClsName , null , (Int32)dwStyle , this.Left , this.Top , m_BgImg.Width , m_BgImg.Height , this.Handle , IntPtr.Zero , NativeMethods.GetModuleHandle(null) , IntPtr.Zero ); Debug.Assert(NativeMethods.IsWindow(m_FakeWndHandle), "CreateWindowEx failed."); }
public WNDCLASSEX GetGLWindowClass() { var wndClass = new WNDCLASSEX(); wndClass.Init(); wndClass.style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw | 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 = _nativeWindowClassName; wndClass.hIconSm = IntPtr.Zero; Native.RegisterClassEx(ref wndClass); return(wndClass); }
/// <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(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter) { // Call the base. base.Create(openGLVersion, width, height, bitDepth, parameter); // Create a new window class, as basic as possible. WNDCLASSEX wndClass = new WNDCLASSEX(); wndClass.Init(); wndClass.style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw | 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", "", WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | 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. PIXELFORMATDESCRIPTOR pfd = new 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(); // 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(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter) { // Call the base. base.Create(openGLVersion, width, height, bitDepth, parameter); // Create a new window class, as basic as possible. WNDCLASSEX wndClass = new WNDCLASSEX(); wndClass.Init(); wndClass.style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw | 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", "", WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | 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. PIXELFORMATDESCRIPTOR pfd = new 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(); // Return success. return true; }