void ISupportInitialize.EndInit() { try { int width = this.Width, height = this.Height; if (this.designMode) { //this.assist.Resize(width, height); } else { this.KeyPress += WinSoftGLCanvas_KeyPress; this.MouseDown += WinSoftGLCanvas_MouseDown; this.MouseMove += WinSoftGLCanvas_MouseMove; this.MouseUp += WinSoftGLCanvas_MouseUp; this.MouseWheel += WinSoftGLCanvas_MouseWheel; this.KeyDown += WinSoftGLCanvas_KeyDown; this.KeyUp += WinSoftGLCanvas_KeyUp; } // Create the render context. ContextGenerationParams parameters = null; if (this.designMode) { parameters = new ContextGenerationParams(); } else { parameters = this.parameters; } var renderContext = new WinSoftGLRenderContext(width, height, parameters); renderContext.MakeCurrent(); this.renderContext = renderContext; // Set the most basic OpenGL styles. GL.Instance.ShadeModel(GL.GL_SMOOTH); GL.Instance.ClearDepth(1.0f); GL.Instance.Enable(GL.GL_DEPTH_TEST);// depth test is disabled by default. GL.Instance.DepthFunc(GL.GL_LEQUAL); GL.Instance.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); } catch (Exception ex) { Log.Write(ex); } }
/// <summary> /// creates render device and render context. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="parameters">parameters.</param> /// <returns></returns> public WinSoftGLRenderContext(int width, int height, ContextGenerationParams parameters) : base(width, height) { this.Parameters = parameters; { IntPtr dc = SoftOpengl32.StaticCalls.CreateDeviceContext(width, height); var paramNames = new string[0]; var paramValues = new uint[0]; IntPtr hrc = SoftOpengl32.StaticCalls.CreateContext(dc, width, height, paramNames, paramValues); SoftOpengl32.StaticCalls.MakeCurrent(IntPtr.Zero, IntPtr.Zero); SoftOpengl32.StaticCalls.DeleteContext(this.RenderContextHandle); SoftOpengl32.StaticCalls.MakeCurrent(dc, hrc); this.DeviceContextHandle = dc; this.RenderContextHandle = hrc; } // Make the context current. this.MakeCurrent(); }