# 3d point cloud render from x,y,z 2d array with texture

Need some direction on 3d point cloud display using OpenGL in c++ (vs2008). I am brand new to OpenGL and trying to do a 3d point cloud display with a texture. I have 3 2D arrays (each same size 1024x512) representing x,y,z of each point. I think I am on the right track with

``````glBegin(GL_POLYGON);
for(int i=0; i<1024; i++)
{
for(int j=0; j<512; j++)
{
glVertex3f(x[i][j], y[i][j], z[i][j]);
}
}
glEnd();
``````

Now this loads all the vertices in the buffer (I think) but from here I am not sure how to proceed. Or I am completely wrong here.

Then I have another 2D array (same size) that contains color data (values from 0-255) that I want to use as texture on the 3D point cloud and display.

I understand that this maybe a very basic OpenGL implementation for some but for me this is a huge learning curve. So any pointers, nudge or kick in the right direction will be appreciated.

• Commented Nov 9, 2012 at 17:49
• Here is a simple tutorial on using textures with OpenGL. Hope it'll be useful. Commented Nov 16, 2012 at 15:21
• Maybe use GL_POINT instead of GL_POLYGON?
– tp1
Commented Nov 16, 2012 at 15:45

You should use a modern OpenGL approach, and forget about glBegin and glEnd. You can use this to learn it Learning Modern 3D Graphics Programming (on web archive).

First, you should put your data in a linear array, like (or something like that). Then you define the opengl buffers that point your data, and load the shader programs to paint it. And, after that your draw routine will be easy as:

``````glClearColor( 0.2f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );

glBindBuffer( GL_ARRAY_BUFFER, posBufferObject );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, 0 );

glBindBuffer( GL_ARRAY_BUFFER, colBufferObject );
glVertexAttribPointer( 1, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0 );

glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 1 );

glDrawArrays( GL_POINTS, 0, 1024*512 );

glDisableVertexAttribArray( 0 );
glDisableVertexAttribArray( 1 );
glUseProgram( 0 );
``````

The link shows everything you need. Your example code is deprecated, and using buffers and shaders is more efficient.