private void GlControlPaint(object sender, PaintEventArgs e) { if (!_loaded) { GL.ClearColor(Color4.LightSteelBlue); GL.Clear(ClearBufferMask.ColorBufferBit); } else if (!_bound) { GL.ClearColor(Color4.SteelBlue); GL.Clear(ClearBufferMask.ColorBufferBit); } else if (_screenCap) { _screenCap = false; SuspendLayout(); _graph.HideUI(); Size tmp = glControl.Size; glControl.Size = new Size(2000, 750); CanvasManager.ChangeViewportSize(glControl.Size); GL.ClearColor(Color4.White); GL.Clear(ClearBufferMask.ColorBufferBit); _graph.DrawGraph(); Bitmap bmp = new Bitmap(glControl.Width, this.glControl.Height); BitmapData data = bmp.LockBits(glControl.ClientRectangle, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.Finish(); GL.ReadPixels(0, 0, this.glControl.Width, this.glControl.Height, PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); bmp.Save(_screenCapFile, ImageFormat.Png); glControl.Size = tmp; CanvasManager.ChangeViewportSize(glControl.Size); _graph.ShowUI(); ResumeLayout(); } else { GL.ClearColor(Color4.White); GL.Clear(ClearBufferMask.ColorBufferBit); _graph.DrawGraph(); } glControl.SwapBuffers(); }
public void DrawGraph() { if (!_canvasReady) { return; } CanvasManager.SimpleShader2D.UseProgram(); GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Modelview); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport((int)CanvasManager.CanvasLocationX, (int)CanvasManager.CanvasLocationY, (int)CanvasManager.CanvasWidth, (int)CanvasManager.CanvasHeight); GL.Scissor((int)CanvasManager.CanvasLocationX, (int)CanvasManager.CanvasLocationY, (int)CanvasManager.CanvasWidth, (int)CanvasManager.CanvasHeight); GL.Enable(EnableCap.ScissorTest); var scale = new GraphScaleData(_scaleData); if (_transitionState == 1) //reposition { float factor = _transitionCounter / Interval; //x difference scale.XShift = _scaleData.XShift + (_transitionCanvas.ScaleData.XShift - _scaleData.XShift) * factor; //scale difference scale.BaseScale = _scaleData.BaseScale + (_transitionCanvas.ScaleData.BaseScale - _scaleData.BaseScale) * factor; } else if (_transitionState == 2) { scale.XShift = _transitionCanvas.ScaleData.XShift; scale.BaseScale = _transitionCanvas.ScaleData.BaseScale; } else { scale.XShift = _scaleData.XShift; scale.BaseScale = _scaleData.BaseScale; } if (_transitionState == 2) //blend colors { //DataVolume.AlphaBlend = 1 - _transitionCounter / Interval; //PacketCount.AlphaBlend = 1 - _transitionCounter / Interval; CanvasCollection.AlphaBlend(1 - _transitionCounter / Interval); } _background.Draw(scale.XShift); ////draw data volume //DataVolume.Draw(scale); ////draw packet count //PacketCount.Draw(scale); // CanvasCollection.DrawCollection(scale); if (_transitionState == 2) { //DataVolume.DrawBackBuffer(scale.BaseScale, _transitionCanvas.ScaleData.MaxData, scale.XShift); //PacketCount.DrawBackBuffer(scale.BaseScale, _transitionCanvas.ScaleData.MaxCount, scale.XShift); CanvasCollection.DrawCollectionBackBuffer(scale); } //////reset viewport GL.Viewport(0, 0, CanvasManager.ControlWidth, CanvasManager.ControlHeight); GL.Disable(EnableCap.ScissorTest); Matrix4 transform = CanvasManager.ViewportTransform; GL.UniformMatrix4(CanvasManager.SimpleShader2D.UniformTransform, false, ref transform); GL.Uniform4(CanvasManager.SimpleShader2D.UniformColor, Color4.Black); GL.LineWidth(2f); Border.BeginDraw(); Border.Draw(BeginMode.LineLoop); Border.EndDraw(); //transform.Invert(); //float left = -(transform.M11 - transform.M41); //float right = transform.M11 + transform.M41; _yAxis.Draw(_scaleData.MaxData); _xAxis.Draw(scale.XShift, scale.BaseScale); }
public void ClearViewport() { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); }