1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
// Recuperation de la profondeur
GLfloat * depth = malloc(WIDTH * HEIGHT *sizeof(GL_FLOAT));
glReadPixels (0, 0, WIDTH, HEIGHT, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
float min, max;
min = depth[0];
max = depth[0];
for (i = 0; i < WIDTH * HEIGHT; i++) {
if (depth[i] < min)
min = depth[i];
if (depth[i] > max)
max = depth[i];
}
// Coloration
GLfloat *rgb = malloc (3 * WIDTH * HEIGHT * sizeof (GL_FLOAT));
glReadPixels (0, 0, WIDTH, HEIGHT, GL_RGB, GL_FLOAT, rgb);
for (i = 0; i < WIDTH * HEIGHT; i++) {
depth[i] = (depth[i] - min) / (max - min);
if (depth[i] > 0 && depth[i] < 0.5)
rgb[3 * i] = 1.0;
if (depth[i] >= 0.5 && depth[i] < 0.8)
rgb[3 * i + 1] = 1.0;
if (depth[i] >= 0.8 && depth[i] < 1.)
rgb[3 * i + 2] = 1.0;
}
glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_FLOAT, rgb); |
Partager