Hello,
I am curently trying to get the gl Zbuffer through a color texture and then in a picture with the BMP format.
But, now what I obtain is a perfectly black picture!
So, I would like to know where is(are) the mistake(s) in my code.
So, first, I create a texture id for the depth buffer texture, called “shadowTex”
GLuint shadowTex;
glGenTextures(1, &shadowTex);
then I create a texture with the depth buffer data.
glBindTexture (GL_TEXTURE_2D, shadowTex);
glTexImage2D (GL_TEXTURE_2D,
0,
3,
shadowMapSize,
shadowMapSize,
0,
GL_DEPTH_COMPONENT24,
GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Now, I have some questions
I set the depth buffer’s depth to 24 with GL_DEPTH_COMPONENT24, so the size of each depth datum is 3 bytes. I would like to know, if I make mistake when I say: the texture’s data type is GL_UNSIGNED_BYTE so the depth buffer data is clamped to the [0 255] interval ?
then, I create the bitmap picture. I don’t put all the code (the first part concerns the header of the picture’s file).
first I read the texture data with the glReadPixels function and put it in an array (I allow the necessary memory previously, of course) and then I put it in the bitmap file:
for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)
{
glReadPixels( j, i, 1, 1, GL_DEPTH_COMPONENT24, GL_UNSIGNED_BYTE, pictData );
}
}
for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)
{
fwrite(pictData + 1*(i*width + j), 1*sizeof(char),1,picture); // R component
fwrite(pictData + 1*(i*width + j), 1*sizeof(char),1,picture); // G component
fwrite(pictData + 1*(i*width + j), 1*sizeof(char),1,picture); // B component
}
for(int j=0;j<nb0;j++) fwrite(&title[2],sizeof(char),1,picture); //zeros de fin de ligne
}
fclose(picture);
That’s all, there are not segmentation errors, but the picture is entirely black!
Thank you for your help.