void ISupportInitialize.EndInit() { int width = this.Width, height = this.Height; if (this.designMode) { this.assist.Resize(width, height); } else { this.KeyPress += WinGLCanvas_KeyPress; this.MouseDown += WinGLCanvas_MouseDown; this.MouseMove += WinGLCanvas_MouseMove; this.MouseUp += WinGLCanvas_MouseUp; this.MouseWheel += WinGLCanvas_MouseWheel; this.KeyDown += WinGLCanvas_KeyDown; this.KeyUp += WinGLCanvas_KeyUp; } // Create the render context. const short bitDepth = 32; var renderContext = new FBORenderContext(width, height, bitDepth); 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); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); int width = this.Width, height = this.Height; if (width > 0 && height > 0) { FBORenderContext renderContext = this.renderContext; if (renderContext != null) { renderContext.MakeCurrent(); renderContext.SetDimensions(width, height); OpenGL.Viewport(0, 0, width, height); if (this.designMode) { GLCanvasHelper.ResizeGL(width, height); } this.Invalidate(); } } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { FBORenderContext renderContext = this.renderContext; if (renderContext == null) { base.OnPaint(e); return; } stopWatch.Reset(); stopWatch.Start(); // Make sure it's our instance of openSharpGL that's active. renderContext.MakeCurrent(); if (this.designMode) { try { DesignModeRendering(); } catch (Exception) { } } else { // If there is a draw handler, then call it. DoOpenGLDraw(e); } // Blit our offscreen bitmap. Graphics graphics = e.Graphics; IntPtr deviceContext = graphics.GetHdc(); renderContext.Blit(deviceContext); graphics.ReleaseHdc(deviceContext); stopWatch.Stop(); { ErrorCode error = (ErrorCode)OpenGL.GetError(); if (error != ErrorCode.NoError) { Debug.WriteLine(string.Format("{0}: OpenGL error: {1}", this.fullname, error)); } } this.FPS = 1000.0 / stopWatch.Elapsed.TotalMilliseconds; }
/// <summary> /// /// </summary> protected virtual void CreateRenderContext() { // Initialises OpenGL. var renderContext = new FBORenderContext(); // Create the render context. renderContext.Create(Width, Height, 32, null); this.RenderContext = renderContext; renderContext.MakeCurrent(); // 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); }
/// <summary> /// /// </summary> protected virtual void CreateRenderContext() { // Initialises OpenGL. var renderContext = new FBORenderContext(); // Create the render context. renderContext.Create(Width, Height, 32, null); this.renderContext = renderContext; renderContext.MakeCurrent(); // Set the most basic OpenGL styles. OpenGL.ShadeModel(OpenGL.GL_SMOOTH); OpenGL.ClearDepth(1.0f); OpenGL.Enable(OpenGL.GL_DEPTH_TEST);// depth test is disabled by default. OpenGL.DepthFunc(OpenGL.GL_LEQUAL); OpenGL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST); if (this.designMode) { GLCanvasHelper.ResizeGL(this.Width, this.Height); } }