glBindFramebuffer GL_FRAMEBUFFER fbo for int depthFillProg- use glFram

  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
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
glBindFramebuffer (GL_FRAMEBUFFER, fbo);
for (int i = 0; i < 5; ++i) {
depthFillProg->use();
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, current, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glReadBuffer(GL_COLOR_ATTACHMENT0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
printf ("invalid framebuffer status");
exit(1);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glPushMatrix();
// 0.5020 0.6235 0.0000 0.0000 = 0.5
// 0.5608 0.6863 0.0000 0.0000 = 1.0
// result: 0.4392 0.6235 0.0 0.0 ???
// real: 0.5020 0.6863 0.0 0.0
glTranslated (0.0, 0.0, 0.5 + 0.1 * i);
// draw call 1
glutSolidCube(1);
glPopMatrix();
unionResultProg->use();
glActiveTexture (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, current);
glActiveTexture (GL_TEXTURE1);
glBindTexture (GL_TEXTURE_2D, result);
if (unionResultProg->setUniformVariable("Texture0", 0) != true) {
int error = glGetError();
if (error != GL_NO_ERROR) {
fprintf (output, "glError: %s\n", gluErrorString(error));
} else {
printf ("glError: unknown error\n");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram (0);
exit (1);
}
if (unionResultProg->setUniformVariable("Texture1", 1) != true) {
int error = glGetError();
if (error != GL_NO_ERROR) {
printf ("glError: %s\n", gluErrorString(error));
} else {
printf ("glError: unknown error\n");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram (0);
exit (1);
}
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, interim, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glReadBuffer(GL_COLOR_ATTACHMENT0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
printf ("invalid framebuffer status");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram (0);
exit(1);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
begin2D(1024, 768);
// draw call 2
glPolygonMode(GL_FRONT, GL_FILL);
glBegin (GL_QUADS);
glTexCoord2d(0, 0); glVertex2f(0.0, 0.0);
glTexCoord2d(0, 1); glVertex2f(0.0, 768.0);
glTexCoord2d(1, 1); glVertex2f(1024.0, 768.0);
glTexCoord2d(1, 0); glVertex2f(1024.0, 0.0);
glEnd();
end2D();
swap (interim, result);
}
glBindTexture(GL_TEXTURE_2D, result);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, buffer);