Search code examples
c#.netopentk

Plot a graph (x = y) in C# using OpenTK?


How to plot a simple graph (x=y) in C# using OpenTK ? both at Windws Form Application and at console App ?? What methods do use to plot that graph ?I'm new to this tool so a a good link or toutorial will help me a lot ....


Solution

    1. You should start with Learn OpenTK in 15'

    2. For a simple x=y graph, copy-paste the code snippet provided in the link above and remove the game.RenderFrame part and replace with code snippet pasted just below

      game.RenderFrame += (sender, e) =>
      
      {
           GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
      
           GL.Begin(PrimitiveType.Lines);
           GL.Color3(Color.White);
           //YAxis
           GL.Vertex2(0.0f, 2.0f);
           GL.Vertex2(0.0f, -2.0f);
      
           //X-Axis
           GL.Vertex2(2.0f, 0.0f);
           GL.Vertex2(-2.0f, 0.0f);
           GL.End();
      
           GL.Begin(PrimitiveType.Points);
           // Plotting the Graph
           GL.Color3(Color.DeepSkyBlue);
           for(float i=0;i<2.0;i=(float) (i+0.001))
           {
               GL.Vertex2(i,i);
           }
           GL.End();
           game.SwapBuffers();
      };