Display a point cloud from Array

Hi community,
I am totally new to the field of OpenGL. Just read the lighthouse3d tutorials and program the samples. Till this moment everything worked fine.
For me, the actual factor to deal with OpenGL is to display and rotate a point cloud. So, I tried to customize the samples to my benefit. At that time my problems began.
I declared two arrays:

  • float imgdata[480][640][3]; //contains the three-dimensional coordinates
  • float texture[480][640][3]; //contains the color values for each point

The points from these array should be converted into glVertex3f, set by the renderScene() function. If anything will be changed the function reshape() should just redraw the window.
After running my program I just got a white screen. Receive no useful results =(
Hope You understand my problem. So, can you please help me?
I am very grateful for any support.
Cheers

Thats my actual code:

void reshape (int w, int h) 
{
	glViewport (0, 0, (GLsizei)w, (GLsizei)h);  
	glMatrixMode (GL_PROJECTION);  
	glLoadIdentity ();  
	gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 500.0);
	glMatrixMode (GL_MODELVIEW);  
}

void renderScene(void)
{
	glClear (GL_COLOR_BUFFER_BIT);  
	glLoadIdentity();
	glRotatef(ry, 0.0, 1.0, 0.0); //rotate about the z axis
	glRotatef(rx-180, 1.0, 0.0, 0.0); //rotate about the y axis  

	float x,y,z;  
	glPointSize(1.0);   
	glBegin(GL_POINTS);  
	for (int i=0;i<480;i++)
	{   
		for (int j=0;j<640;j++)
		{  
			glColor3f(texture[i][j][0]/255, texture[i][j][1]/255, texture[i][j][2]/255);
			x=imgdata[i][j][0];
			y=imgdata[i][j][1];   
			z=imgdata[i][j][2];   
			glVertex3f(x,y,z);   
		}  
	}  
	glEnd();  
	glFlush();  
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);  
	glutInitWindowPosition(10,10);
	glutInitWindowSize(640, 480);  
	glutCreateWindow("3D disparity image"); 

	glutDisplayFunc(renderScene);
	glutReshapeFunc(reshape);
	glutIdleFunc(renderScene);
	glutMainLoop();
}

glClear (GL_COLOR_BUFFER_BIT);

You are not clearing the depth buffer.
At the end of renderScene you should swap buffers: glutSwapBuffers()


glRotatef(ry, 0.0, 1.0, 0.0); //rotate about the z axis
glRotatef(rx-180, 1.0, 0.0, 0.0); //rotate about the y axis  

Here comments don’t match the code. Are you sure you are setting up your view in a way that the points are actually visible (i.e. not behind the “camera”).

Once you have this working, read up on Vertex Buffer Objects (VBO) and how to use them so that you don’t have to send the vertex data to the GPU each frame - otherwise rendering larger point clouds will be terribly inefficient.

Hey Carsten,
thank you very much!! Now I got the ouput.
But as you said, the program is really slow. Especially, when I change the cam orientation.

The problem is, that I got the point cloud from two cams (stereoscopy). Hence, the point cloud should change every frame. Anyway, is it also possible to make my program faster?
Kind regards.

Probably, at least a bit. As I said, read up on VBOs, that way you can send the data to the GPU with a single function call instead of piecewise (via the glColor, glVertex calls).
With that you could look into improving the streaming of the buffer data, there are a couple of threads on the topic on these forums, but I don’t know the details.