i searched for the answer but i still didn't find a understandable answer, so i'm asking how to calculate the value at depth buffer.
In
https://en.wikipedia.org/wiki/Z-buffering
here is the formula as image:
and here it is written by me:
z' = (2^d -1 ) * ((far + near)/(2 * (far - near) + (1 / z) * (-far * near) / (far - near) + 1/2)
when d is the depth of the z-buffer (24 bits at my case)
and z is the z value of the vertex.
i wrote a simple code and tried to run it and read the depth buffer value and calculate it, but i receive deifferent answers.
my code example:
/* init */
#define CUBE_SIDE_SIZE 0.25
glViewport(0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1, 1, -1, 1, -1, 1);
/* draw */
glEnable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex3f(-CUBE_SIDE_SIZE, -CUBE_SIDE_SIZE, -CUBE_SIDE_SIZE);
glVertex3f(-CUBE_SIDE_SIZE, CUBE_SIDE_SIZE, -CUBE_SIDE_SIZE);
glVertex3f(CUBE_SIDE_SIZE, CUBE_SIDE_SIZE, -CUBE_SIDE_SIZE);
glVertex3f(CUBE_SIDE_SIZE, -CUBE_SIDE_SIZE, -CUBE_SIDE_SIZE);
glEnd();
I read from the depth buffer 0.375 value.
How can i get this value by calculation?
Thanks.