Depth buffer
I''d like to know how is possible to read how far is an object, or an object vertex, drawn on the screen. If i''m not mistaken glReadPixel just return the color information of a certain pixel, so that wouldn''t help much. I need that in the terrain engine i''m developing now, i''d like to get the coordinates of terrain vertices when i move the mouse on them. Thx
It''d be easier to just transform the a vertex and find its distance from the near plane of the frustum than to use the depth buffer. But, if you really want/need to use the depth buffer, it can be done through glReadPixels. Use GL_DEPTH_COMPONENT as the format of the data you''re requesting.


I coded a little routine as follows:
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor glReadPixels(xPos,viewport[3]-yPos,GL_DEPTH_COMPONENT,GL_FLOAT,(void *)pixel_vertex_depth);
When i move the mouse over the terrain, i get values going from 0.999287 (closer to eyepoint) to 0.999540 (most far). Outside the terrain grid value is 0. Is this correct ? I guess my depth scale is somehow out of range, i tought i''d get values from 0 to 1 , but they start from 0.999 already.
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor glReadPixels(xPos,viewport[3]-yPos,GL_DEPTH_COMPONENT,GL_FLOAT,(void *)pixel_vertex_depth);
When i move the mouse over the terrain, i get values going from 0.999287 (closer to eyepoint) to 0.999540 (most far). Outside the terrain grid value is 0. Is this correct ? I guess my depth scale is somehow out of range, i tought i''d get values from 0 to 1 , but they start from 0.999 already.
yes. thats correct. I don''t really see how you will be able to work out what what vertex is selected though.
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement