Search code examples
performanceopenglanimationgraphicssharpgl

SharpGL Animation Questions


So I am writing a program that parses files with xyz points and makes a bunch of connected lines. What I am trying to do is animate each line being drawn. I have tried to use VBO's and Display Lists in order to increase performance (as I am dealing with large amount of data points i.e. 1,000,000 points) but I could not figure out how to use them in SharpGL. So the code I am using to draw right now is as follows:

private void drawInput(OpenGL gl)
            {

                gl.Begin(OpenGL.GL_LINE_STRIP);
                for (int i = 0; i < parser.dataSet.Count; i++)
                {


                    gl.Color((float) i, 3.0f, 0.0f);
                    gl.Vertex(parser.dataSet[i].X, parser.dataSet[i].Y, parser.dataSet[i].Z);
                    gl.Flush();
                }
                gl.End();

            }

I know immediate mode is super noobzore5000 of me, but I can't find any SharpGL examples of VBO's or Display Lists. So know what I want to do is to 'redraw' the picture after each line is drawn. I thought when the flush method is called, it draws everything up to that point. But it still 'batches' it, and displays all the data at once, how can I animate this? I am incredibly desperate, I don't think thoroughly learning OpenGL or DirectX is practical for such a simple task.


Solution

  • After lots of tinkering, I chose to go with OpenTK because I did end up figuring out VBO's for SharpGL and the performance is AWFUL compared to OpenTK. I will give an answer as to how to animate in the way that I wanted.

    My solution works with Immediate Mode and using VBO's. The main concept is making a member integer (animationCount) that you increase every time your paint function gets called, and paint up to that number.

    Immediate Mode:

    private void drawInput(OpenGL gl)
            {
    
                gl.Begin(OpenGL.GL_LINE_STRIP);
                for (int i = 0; i < animationCount; i++)
                {
    
    
                    gl.Color((float) i, 3.0f, 0.0f);
                    gl.Vertex(parser.dataSet[i].X, parser.dataSet[i].Y, parser.dataSet[i].Z);
                }
                gl.End();
    
                animationCount++;
            }
    

    or

    VBO:

     private void glControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
     {
     GL.DrawArrays(PrimitiveType.LineStrip, 0, animationCount);
     animationCount++;
     }