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

心已入冬 提交于 2019-12-02 08:52:09

问题


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 ....


回答1:


Hey Carlos Oliveira,

Step 1: You should start with this link ( http://www.opentk.com/doc/chapter/0 )[1]

Step 2: For a simple x=y graph , copy-paste the code snippet provided in the link[1] 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();
            };

Thanks, Hope it helps

Also like Christos mentioned a simple search would have landed you on the initial chapters of openTK



来源:https://stackoverflow.com/questions/24629056/plot-a-graph-x-y-in-c-sharp-using-opentk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!