/// <summary> /// Raises the <see cref="E:System.Windows.Forms.UserControl.Load" /> event. /// Sets all the properties up but only if the form is not in designer mode, /// because OpenGL calls in the Designer cause errors. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); _rect = new Rectangle(0, 0, this.Size.Width, this.Size.Height); this.MakeCurrent(); if (!(IsInDesignerMode())) { _shaders = new Shaders(Resources.LineShader_vert, Resources.LineShader_frag, Resources.TextShader_vert, Resources.TextShader_frag); _textInstance = new TextInstance(_shaders); _graphPane = new GraphPane(_rect, _textInstance); _graphPane.ReSize(new GLRectangleF(0, 0, (int)_rect.Width, (int)_rect.Height)); _textInstance.GenerateFontImage(_graphPane.Rect); GL.ClearColor(1.0f, 1.0f, 1.0f, 0.0f); _zoomPanState = new ZoomPanState(ref _graphPane); _FrameTimer.Tick += FrameTimer_Tick; _FrameTimer.Interval = 25; _FrameTimer.Start(); _stopwatch = new Stopwatch(); _stopwatch2 = new Stopwatch(); _stopwatch.Reset(); _stopwatch2.Reset(); _stopwatch.Start(); } }
/// <summary> /// Initializes a new instance of the <see cref="GL_Border"/> class. /// </summary> /// <param name="color">The color.</param> /// <param name="shaders">The shaders.</param> public GL_Border(Color color, Shaders shaders) { float db = 0.9995000f; _border = new float[8] {// border not at 1/-1 because it gets clipped by OpenGL otherwise 1.0f * db, 1.0f * db, 1.0f * db, -1.0f * db, -1.0f * db, -1.0f * db, -1.0f * db, 1.0f * db }; _VBO = GL.GenBuffer();//Set up Shaders, VBO and VAO _VAO = GL.GenVertexArray(); _shaders = shaders; _shaders.LineShader.Use(); GL.BindVertexArray(_VAO); GL.EnableVertexAttribArray(_shaders.LineShader.VertexLocation); GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO); // bind the VBO and put in the Vertices. GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * _border.Length), _border, BufferUsageHint.StaticDraw); _mat = Matrix4.Identity; //set the transformation to "no transformation" GL.UniformMatrix4(_shaders.LineShader.MatrixLocation, false, ref _mat); //set the Attribpointer for Vertex interpretation GL.VertexAttribPointer(_shaders.LineShader.VertexLocation, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0); GL.BindVertexArray(0); _shaders.LineShader.StopUse(); _color = color; }
/// <summary> /// Initializes a new instance of the <see cref="TextInstance"/> class. /// </summary> /// <param name="shaders">The shaders.</param> public TextInstance(Shaders shaders) { _fontBitmapFilename = "Font_bitmap.png"; _glyphsPerLine = 16; _glyphLineCount = 16; _atlasOffsetX = -3; _atlasOffsetY = -1; _fontSize = 24; _glyphWidth = (int)(0.7 * _fontSize); _glyphHeight = (int)(1.5 * _fontSize); _bitmapFont = false; _fontName = "Consolas"; _charXSpacing = _glyphWidth - 1; _shaders = shaders; }
/// <summary> /// Initializes a new instance of the <see cref="Chart"/> class. /// </summary> /// <param name="shaders">The shaders.</param> public Chart(Shaders shaders) { _glBorder = new GL_Border(Color.Black, shaders); }