Reputation: 7458
Is it possible to render a gray-scale image in 3D using pixel value as Z-coordinate? Where should I start? What is the command for drawing a point in OpenGL and what is the basic setup for ensuring this point is visible?
I'm using Qt, and was able to cmpile and run the Qt's OpenGL examples.
Upvotes: 1
Views: 971
Reputation: 7458
Ok, I've found out how to do it and implemented a small demo using Qt:
https://github.com/vheinitz/Cell3DViewerDemo
The main thing to understand seemed to be how to create the list of vertexes:
glNewList(_vertexes, GL_COMPILE);
GLenum mode = GL_TRIANGLES;//GL_TRIANGLES GL_POINTS GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUADS
glBegin(mode);
for (int y = 0; y < height - 2; y++) {
int x = 0;
float gy = y*sy -yo;
float gy1 = (y+1)*sy-yo;
for (x; x < width-2; x++) {
float z = qGray(qimg.pixel(x, y));
float gx = x*sx -xo;
float gx1 = (x+1)*sx -xo;
float gz = qGray(qimg.pixel(x, y))*sz -zo;
glColor3f(0, gz, 0);
glVertex3f(gx, gz, gy);
gz = qGray(qimg.pixel(x, y+1))*sz -zo;
glColor3f(0, gz, 0);
glVertex3f(gx, gz, gy1);
gz = qGray(qimg.pixel(x+1, y))*sz -zo;
glColor3f(0, gz, 0);
glVertex3f(gx1, gz, gy);
glVertex3f(gx1, gz, gy);
gz = qGray(qimg.pixel(x, y+1))*sz -zo;
glColor3f(0, gz, 0);
glVertex3f(gx, gz, gy1);
gz = qGray(qimg.pixel(x+1, y+1))*sz -zo;
glColor3f(0, gz, 0);
glVertex3f(gx1, gz, gy1);
}
}
glEnd();
glEndList();
Upvotes: 2