Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
    
Are you looking for an implementation answer or a how do I go about this answer? If you're looking for an implementation answer this may be better asked on SO. –  Walter Oct 10 '12 at 12:52
    
Checkout stackoverflow.com/questions/6540461/… –  Martin Beckett Nov 9 '12 at 17:49
    
Here is a simple tutorial on using textures with OpenGL. Hope it'll be useful. –  Roman Nov 16 '12 at 15:21
1  
Maybe use GL_POINT instead of GL_POLYGON? –  tp1 Nov 16 '12 at 15:45
add comment

1 Answer

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

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 );

glUseProgram( myShaderProgram );

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.