pascx86's picture

Problem coloring point clound ( density lower )

Hi, thank you for your time. I'm trying to read a .bmp ( a "height map" ) and create a point cloud in 3D. Everything works except for coloring each point with a different color.
So, first, I'm running in c# .net 4.0 on VS 2010.
I've created a Vector3[] and loaded it like this :

var vertices = new Vector3[bitmap.Height * bitmap.Width];
// for each vertices I set x,y and z depending of the color of the pixel
// ...
vbo = GL.GenVertexArray();
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                                   new IntPtr(vertices.Length * Vector3.SizeInBytes),
                                   vertices, BufferUsageHint.StaticDraw);

and then and array of "Color" like this :

Color[] color = new Color[vertices.Length ];
// set color
GL.GenBuffers(1, out vbo_color);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_color);
                              new IntPtr(color.Length * sizeof(byte) * 4),
                              color, BufferUsageHint.StaticDraw);

so, if I show the point cloud like this :

// translate, rotate and ... ( setting "camera" )
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, new IntPtr(0));
GL.DrawArrays(PrimitiveType.Points, 0, vLength);

so, like this, everything works but they appear white.
if i add this before "GL.EnableClientState(ArrayCap.VertexArray);" :

GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_color);
GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, 0);

( I disable ArrayCap.ColorArray after the draw )
The point get colored but the "density" of the point cloud change. Many point just disappear !
I've changed many small thing when looking on the forum but nothing worked!

Thank you!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ds_creamer's picture

I haven't double-checked your code, so I'm not sure of this, but I think you should be using BufferTarget.ElementArrayBuffer for the colors. (Keep BufferTarget.ArrayBuffer for the vertex positions.)

pascx86's picture

I've changed
Color[] color=...
Int[] color=...
and when I assign the color I must do :
color[i]=my_color.ToArgb() to convert to color to an "int".
Now it work...

the Fiddler's picture

Ah, yes, this is a very annoying issue: System.Drawing.Color is not safe for interop. AFAIK, it's internal representation is a 8-byte long value, not a 4-byte integer as one would expect.

You can either use ToArgb() to cast to an int, as you are doing now, or you can define your own color structure that has known properties:

struct Color
    public byte R, G, B, A;
    public Color(System.Drawing.Color c)
        R = c.R;
        B = c.B;
        G = c.G;
        A = c.A;

Note that there is a small bug in your code:

vbo = GL.GenVertexArray(); // should be GL.GenBuffer() instead

GenVertexArray gives you a VAO, not a VBO.