Draw a Point Cloud with SharpGL

Mar 9, 2013 at 6:29 PM
Hi, i now can draw some GL_POINTS with this draw procedure:
private void OpenGLControl_OpenGLDraw(object sender, SharpGL.OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();         
            gl.Translate(-1.5f, 0.0f, -6.0f);
            gl.Begin(OpenGL.GL_POINTS);

                gl.Color(1.0f, 0.0f, 0.0f);     
                gl.Vertex(0.0f, 1.0f, 0.0f);    

            gl.End();                       
            gl.Flush();
        }
but if i have (and i will have) 1.000.000 points i can't do 1.000.000 times gl.vertex, i need some structure i can initialize once and overwrite at every draw.

How i can do it?

and, i tried to make every dot bigger with this:
gl.Enable(OpenGL.GL_PROGRAM_POINT_SIZE);
gl.PointSize(100.0f);
but it have no effect, why?
Thank you!
Coordinator
Mar 10, 2013 at 7:44 AM
Hi,

To draw a million points, indeed it's not a good idea to loop through them and send them to OGL each frame. What you should do is create a vertex buffer and render them through that- then all geometry will be cached in the graphics card. Take a look into:

http://www.opengl.org/wiki/Vertex_Specification

It's a lot more work, but it will be the only way to get acceptable performance.

Use glPointSize to set the point size by the way :)

FYI In response too:

From: AlexanderPD

Hi, i now can draw some GL_POINTS with this draw procedure:
private void OpenGLControl_OpenGLDraw(object sender, SharpGL.OpenGLEventArgs args)
    {
        OpenGL gl = args.OpenGL;
        gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
        gl.LoadIdentity();         
        gl.Translate(-1.5f, 0.0f, -6.0f);
        gl.Begin(OpenGL.GL_POINTS);

            gl.Color(1.0f, 0.0f, 0.0f);     
            gl.Vertex(0.0f, 1.0f, 0.0f);    

        gl.End();                       
        gl.Flush();
    }
but if i have (and i will have) 1.000.000 points i can't do 1.000.000 times gl.vertex, i need some structure i can initialize once and overwrite at every draw.

How i can do it?

and, i tried to make every dot bigger with this:
gl.Enable(OpenGL.GL_PROGRAM_POINT_SIZE);
gl.PointSize(100.0f);
but it have no effect, why?
Thank you!
Mar 10, 2013 at 11:17 AM
thank you for your reply! That link is very useful!

i'm just having some problem finding an example of this, even in the sample folder there are no use of gl.BindVertexArray, and i can't find some openGL var types like GLuint and GLenum.
I must use uint for GLuint? And what for GLenum? A simple example of vertex array use can save lot of headache to beginners like me, i hope i can find one!
Coordinator
Mar 14, 2013 at 4:10 PM
I'll see if I can get one done for the next release, for now, the Cel Shading example in the latest repro source code uses vertex buffers, it might work as a starting point!


On 10 March 2013 12:17, AlexanderPD <notifications@codeplex.com> wrote:

From: AlexanderPD

thank you for your reply! That link is very useful!

i'm just having some problem finding an example of this, even in the sample folder there are no use of gl.BindVertexArray, and i can't find some openGL var types like GLuint and GLenum.
I must use uint for GLuint? And what for GLenum? A simple example of vertex array use can save lot of headache to beginners like me, i hope i can find one!

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpgl@discussions.codeplex.com)

To start a new discussion for this project, email sharpgl@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 16, 2013 at 6:21 PM
Edited Mar 17, 2013 at 2:53 PM
hi again, i did this really simple code trying to make a simple vertex array:
            float[] vertici = new float[9];
            vertici[0] = 1.0f;
            vertici[1] = 0.0f;
            vertici[2] = 0.0f;
            vertici[3] = 0.0f;
            vertici[4] = 1.0f;
            vertici[5] = 0.0f;
            vertici[6] = 1.0f;
            vertici[7] = 1.0f;
            vertici[8] = 0.0f;
            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, vertici);
            gl.PointSize(10.0f);
            gl.DrawArrays(OpenGL.GL_POINTS, 0, 9);
            gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
and this works! but not as expected :( I set the first parameter of "g.VertextPointer" to 3, so every dot must be read from 3 coordinates, but the result act as i wrote "2" as parameter, here what i got:

Image

4 points? it really looks like it read only 2 float per vertex in a 2d space! what i'm missing?
if i set gl.VertexPointer(2, OpenGL.GL_FLOAT, 0, vertici); i got this:

Image

ps: there is a fast way to disable the bottom debug text?

edit: fixed using gl.DrawArrays(OpenGL.GL_POINTS, 0, 3); instead of 9!
Coordinator
Mar 17, 2013 at 4:46 PM
I'm looking into this right now, it does indeed seem like an issue. PS - for the debug text, just make 'DrawFPS' false on the control :)


On 16 March 2013 19:21, AlexanderPD <notifications@codeplex.com> wrote:

From: AlexanderPD

hi again, i did this really simple code trying to make a simple vertex array:
            float[] vertici = new float[9];
            vertici[0] = 1.0f;
            vertici[1] = 0.0f;
            vertici[2] = 0.0f;
            vertici[3] = 0.0f;
            vertici[4] = 1.0f;
            vertici[5] = 0.0f;
            vertici[6] = 1.0f;
            vertici[7] = 1.0f;
            vertici[8] = 0.0f;
            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, vertici);
            gl.PointSize(10.0f);
            gl.DrawArrays(OpenGL.GL_POINTS, 0, 9);
            gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
and this works! but not as expected :( I set the first parameter of "g.VertextPointer" to 3, so every dot must be read from 3 coordinates, but the result act as i wrote "2" as parameter, here what i got:

Image

4 points? it really looks like it read only 2 float per vertex in a 2d space! what i'm missing?
if i set gl.VertexPointer(2, OpenGL.GL_FLOAT, 0, vertici); i got this:

Image

ps: there is a fast way to disable the bottom debug text?

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpgl@discussions.codeplex.com)

To start a new discussion for this project, email sharpgl@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 11, 2013 at 1:51 AM
I'm seeing this same issue.
Dec 19, 2013 at 4:02 PM
Hi AlexanderPD,
I'm working on SharpGL to draw Point Cloud data (*.xyz file), I'm a beginner on SharpGL.
I tried to implement your example posted here but no success. In particular when I use function “VertexPointer” I cannot use as 4° parameter “vertici” because I have
this compiler error:

"Argument 4: cannot convert from ‘float[]’ to ‘System.IntPtr’"

To avoid compiler errors I have to modify your software as follow:
            float[] vertici = new float[9];
            vertici[0] = 1.0f;
            vertici[1] = 0.0f;
            vertici[2] = 0.0f;
            vertici[3] = 0.0f;
            vertici[4] = 1.0f;
            vertici[5] = 0.0f;
            vertici[6] = 1.0f;
            vertici[7] = 1.0f;
            vertici[8] = 0.0f;

            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            __var interp = new IntPtr(0);
            unsafe
            {
                fixed (float* pointer = vertici)
                {
                    interp = new IntPtr(pointer);                    
                }
            }
            gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, interp);__
            gl.PointSize(10.0f);            
            gl.DrawArrays(OpenGL.GL_POINT, 0, 3);
            gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
but when I run software I don't see points on OpenGLControl.....objects seems freezed because I don't see also timer and FPS string running on it.

I'm using Visual Studio Professional 2010 with SharpGL Extension 2.1.0.

Some ideas?

Your code posted is working as it is?

thanks in advance.

Paolo
Dec 28, 2013 at 11:31 PM
Hi, sorry but i'm not skilled enough to help you. I just made a few tries before running away from sharpGL :P
in some of my old tries i casted that "interp" to IntPrt, something like this:
gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, (IntPtr)(interp.Length * sizeof(float)));
or using a int[] instead float[].

does it works? i have no idea. I failed with sharpGL and used something more easy to handle for my project: Helix 3d Toolkit. Performance sucks but its damn easy.

ps: if you need a starting point just run the example projects included in SharpGL source code, get it from here: http://sharpgl.codeplex.com/SourceControl/latest
Dec 29, 2013 at 12:34 PM
Hi,
what you suggest (after substitute "interp" with "vertici") is ok for compiler: no error. But unfortunately it doesn't work….at run I have a white screen.

Let me ask again, did you succeed at least to show a point cloud? Or run away from SharpGL just with some tests? Because from your posts above it seems that you succeed to display something.

If you did, could you post the “entire” example?

I already had a look at SharpGL examples....but none uses "vertexPointer" or "DrawArrays" or similar. I think that if I don’t succeed with SharpGl I will try directly with OpenGl in C++.