Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CurveItem"/> class.
        /// Sets up the OpenGL Objects VAO and VBO and AttribPointers
        /// </summary>
        /// <param name="pane">The pane.</param>
        /// <param name="label">The label.</param>
        /// <param name="points">The points.</param>
        /// <param name="color">The color.</param>
        /// <param name="linesShader">The lines shader.</param>
        public CurveItem(GraphPane pane, string label, RollingVec2List points, Color color, LinesShader linesShader)
        {
            _rollingV2List = points;
            _GraphVertex   = new Vector2[points.Capacity];
            _label         = label;
            _color         = color;
            _yAxisIndex    = 0;
            _linesShader   = linesShader;

            _pane = pane;

            _linesShader.Use();//use the Shader, generate and bindd VAO and VBO
            _VAO = GL.GenVertexArray();
            _VBO = GL.GenBuffer();

            GL.BindVertexArray(_VAO);
            GL.EnableVertexAttribArray(_linesShader.VertexLocation); //enable the in variable of the Shader, where the Vertices are put

            GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO);           //bind the VBO and give it an empty array
            GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * _GraphVertex.Length), _GraphVertex, BufferUsageHint.StreamDraw);
            //set up the Pointer for OpenGL to interpret Vertices
            GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);

            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the Item into the <see cref="GraphPane"/><see cref="Chart"/><see cref="GLRectangleF"/>
        /// </summary>
        /// <param name="pane">The <see cref="GraphPane"/> owning the <see cref="Chart"/> area</param>
        public void Draw(GraphPane pane)
        {                                       //set the OpenGL focus onto the Chart rectangle
            GL.Viewport((int)pane.PChart.Rect.X, (int)pane.PChart.Rect.Y, (int)pane.PChart.Rect.Width, (int)pane.PChart.Rect.Height);
            YAxis   tempYAxis = GetYAxis(pane); //fetching the yAxis and its transformation matrix
            Matrix4 TraFo     = tempYAxis.TraFo;

            _linesShader.Use();//using the Shader and binding the VAO
            GL.BindVertexArray(_VAO);

            GL.Uniform4(_linesShader.ColorLocation, _color);//Set the Color and the Matrix inside the Shader
            GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref TraFo);

            //Only put points into the VBO if there are new ones
            if (_rollingV2List.HasUndrawnPoint)
            {
                _GraphVertex = _rollingV2List.TailToHeadCopy(); //copy the circular buffer into the sorted array
                GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO);  //bind the VBO and give the sorted array to it
                GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * _GraphVertex.Length), _GraphVertex, BufferUsageHint.StreamDraw);
                //set the VertexAttribPointer so OpenGL refreshes its buffer
                GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);

                _rollingV2List.HasUndrawnPoint = false;
            }
            //draw all the Points in the VBO
            GL.DrawArrays(PrimitiveType.LineStrip, 0, _rollingV2List.Count - 1);
            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Scale"/> class.
        /// </summary>
        /// <param name="ownerAxis">The owner axis.</param>
        /// <param name="TextInstance">The text instance.</param>
        public Scale(Axis ownerAxis, TextInstance TextInstance)
        {
            _ownerAxis    = ownerAxis;
            _textInstance = TextInstance;

            _min = 0.0;
            _max = 10.0;

            _majorStep         = 1;
            _minorStep         = 0.1;
            _targetXSteps      = 7;
            _targetYSteps      = 7;
            _targetMinorXSteps = 5;
            _targetMinorYSteps = 5;

            _VBO = GL.GenBuffer(); //generate VBO, VAO and setting them up here
            _VAO = GL.GenVertexArray();

            _linesShader = TextInstance.Shaders.LineShader;
            _linesShader.Use();

            GL.BindVertexArray(_VAO);

            GL.EnableVertexAttribArray(_linesShader.VertexLocation);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO);

            _mat = Matrix4.Identity;
            GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref _mat);

            GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0);

            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Legend"/> class.
        /// </summary>
        /// <param name="textInstance">The text instance.</param>
        public Legend(TextInstance textInstance)
        {
            _legendEntries = new List <LegendEntry>();
            _border        = new GL_Border(Color.Black, textInstance.Shaders);
            _textInstance  = textInstance;
            _linesShader   = textInstance.Shaders.LineShader;
            _rect          = new GLRectangleF(0, 0, 0, 0);
            _innerRect     = new GLRectangleF(0, 0, 0, 0);
            _entryGapX     = 2;
            _nEntriesVert  = 5;
            _margin        = new Margin();
            _margin.Left   = 10;
            _margin.Right  = 10;
            _margin.Top    = 2;
            _margin.Bottom = 5;
            _lineHeight    = textInstance.FontSize * 0.8;

            _VBOLine = GL.GenBuffer();//set up OpenGL by generating buffers and using the shader
            _VAOLine = GL.GenVertexArray();
            _linesShader.Use();

            GL.BindVertexArray(_VAOLine);//setting up VAO states and binding the VBO

            GL.EnableVertexAttribArray(_linesShader.VertexLocation);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _VBOLine);
            _mat = Matrix4.Identity;
            GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref _mat);

            GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0);

            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the legend lines.
        /// </summary>
        /// <param name="pane">The <see cref="GraphPane"/>.</param>
        public void DrawLegendLines(GraphPane pane)
        {
            GL.Viewport((int)pane.Rect.X, (int)pane.Rect.Y, (int)pane.Rect.Width, (int)pane.Rect.Height);
            _linesShader.Use();
            GL.BindVertexArray(_VAOLine);//use Shader and bind VAO
            //put the transformation matrix into the Shader and bind the VBO
            GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref _mat);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _VBOLine);

            GL.LineWidth(3.0f);//thicker line for better visibility
            foreach (LegendEntry Item in _legendEntries)
            {
                GL.Uniform4(_linesShader.ColorLocation, Item.Color);//set the items color, then put in the vertices
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * Item.line.Length), Item.line, BufferUsageHint.StaticDraw);
                //draw the lines
                GL.DrawArrays(PrimitiveType.Lines, 0, Item.line.Length / 2);
            }
            GL.LineWidth(1.0f);//reset line width

            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draws the major tics. First their Number and their
        /// Positions are calculated, then they are given to the
        /// VBO as vertices to then be drawn.
        /// </summary>
        /// <param name="nTics">The n tics.</param>
        /// <param name="pane">The pane.</param>
        /// <param name="chart">The chart.</param>
        internal void DrawMajorTics(int nTics, GraphPane pane, Chart chart)
        {
            double   dVal;
            float    pixVal;
            MajorTic tic      = _ownerAxis._majorTic;
            int      firstTic = (int)(_min / _majorStep + 0.99);
            int      k        = 0;

            _ticsArray = new Vector2[2 * nTics + 2];

            for (int i = firstTic; i < nTics + firstTic; i++)
            {
                dVal = _majorStep * i;
                // If we're before the start of the scale, just go to the next tic
                if (dVal < _min)
                {
                    continue;
                }
                // if we've already past the end of the scale, then we're done
                if (dVal > _max)
                {
                    break;
                }

                pixVal = LocalTransform(dVal);
                if (this._ownerAxis is XAxis)//Add two x/y-tupels to the array, one above, one below the axis
                {
                    _ticsArray[k].X     = -2 * pixVal / chart.Rect.Width + 1;
                    _ticsArray[k + 1].X = -2 * pixVal / chart.Rect.Width + 1;
                    _ticsArray[k].Y     = -1;
                    _ticsArray[k + 1].Y = 1;
                }
                else if (this._ownerAxis is YAxis)
                {
                    _ticsArray[k].X     = -1;
                    _ticsArray[k + 1].X = 1;
                    _ticsArray[k].Y     = -2 * pixVal / chart.Rect.Height + 1;
                    _ticsArray[k + 1].Y = -2 * pixVal / chart.Rect.Height + 1;
                }
                DrawTicValue(pane, chart, this._ownerAxis, pixVal, dVal);//at the position of every majorTic, draw a number
                k += 2;
            }

            if (this._ownerAxis is XAxis)
            {//the Viewports are directly put over the axis, so the _ticsArray has numbers rangig from -1 to 1 int one direction, just fitting the rectangle
                GL.Viewport((int)chart.Rect.X, (int)(chart.Rect.Y - tic.Size), (int)chart.Rect.Width, (int)(2 * tic.Size));
            }
            else if (this._ownerAxis is YAxis)
            {
                GL.Viewport((int)(chart.Rect.X - tic.Size - _ownerAxis._fixedSpace * (this._ownerAxis as YAxis).Index), (int)chart.Rect.Y, (int)(2 * tic.Size), (int)chart.Rect.Height);
                if ((this._ownerAxis as YAxis).Index != 0)
                {//Draw the vertical line for yAxes that dont border the pChart area and so dont have one by default.
                    _ticsArray[k].X     = 0;
                    _ticsArray[k + 1].X = 0;
                    _ticsArray[k].Y     = -1;
                    _ticsArray[k + 1].Y = 1;
                    k += 2;
                }
            }

            _linesShader.Use();//use Shader, bind VAO, bind VBO and give the tic values to the VBO
            GL.BindVertexArray(_VAO);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO);
            GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * _ticsArray.Length), _ticsArray, BufferUsageHint.StaticDraw);

            GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);

            GL.Uniform4(_linesShader.ColorLocation, Color.Black);//set uniform variables Color and Transformationmatrix
            GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref _mat);

            GL.DrawArrays(PrimitiveType.Lines, 0, k);//draw the lines
            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }