Hi everyone!!!
I use glReadPixel(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z) and this function always return 1.0???
Does anybody know why???
Thanks a lot!![]()
Hi everyone!!!
I use glReadPixel(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z) and this function always return 1.0???
Does anybody know why???
Thanks a lot!![]()
The function returns 1, or the array is filled with 1's? It would seem very odd for the function to return 1 as it has a void return type.
Deiussum
Software Engineer and OpenGL enthusiast
After the execution of glReadPixels, z contains the value 1??? He's not supposed to return a value into 0 and 1?
Originally posted by Deiussum:
The function returns 1, or the array is filled with 1's? It would seem very odd for the function to return 1 as it has a void return type.
From MSDN:
GL_DEPTH_COMPONENT
Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0.0 and the maximum value maps to 1.0. Each component is then multiplied by GL_DEPTH_SCALE, added to GL_DEPTH_BIAS, and finally clamped to the range [0,1].
GL_RED
So yes, it is supposed to get set between 0 and 1. You are probably reading from a location that the depth was cleared and never had anything drawn to it to make it change the depth value.
If I remember right, the x,y components of that are read where (0,0) is the lower left, not the upper left so you may be getting confused by that.
Deiussum
Software Engineer and OpenGL enthusiast
try this glClearDepth( 0.44 );
now do your readpixels , if u get 0.44 then youre reading a pixel that hasnt had depth info written into it, ie no polygon is under the point
ReadPixel is doing what it is supposed to. You are reading from the screen position (x,y,1=z) so you havt to get 1 for depth always.Originally posted by Dagana:
I use glReadPixel(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z) and this function always return 1.0???
Chris
yes
DaViper, there is no z in glReadPixels...
If there was one, there would be no point to having such a function... It would be something like:Code :void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels );
Anyway, it'd be worth trying zed's suggestion and see what happens !Code :float GetZ(float X,float Y,float Z) { return(Z); }
Regards.
Eric
A common problem is that people forgets that OpenGL's Y-axis does not equal the window's Y-axis. OpenGL's Y-axis has it's zero in the bottom and grows upwards.
Your right Zed, I get 0.44! Why??? Maybe is because I draw only Points. My image is a mass of approximatively 250 000 points.
I need this information because I want the user to be able to crop the image, maybe anyone got another solution?
Originally posted by zed:
try this glClearDepth( 0.44 );
now do your readpixels , if u get 0.44 then youre reading a pixel that hasnt had depth info written into it, ie no polygon is under the point
I assure that I don't take you for a dummy but are you sure your depth buffer is enabled when you are drawing your scene ? (glEnable(GL_DEPTH)) And Are you sure your clear it at the beginning of each new frame ?
Sebb