
concerning the viewport
hello,
I encounter a problem when getting the viewport:
first I used the code glGetIntegerv (GL_VIEWPORT, viewport); to get the width and height of the current window. But according to the returned value, I found that the height is a bit larger than the actual window height.
Let vheight be the height value return by the above function, and let wheight be the acctual window''s height. Their subtraction (vheight - wheight) will be useful later.
What is more, I typed the following two lines:
GLfloat* zbuffer = (GLfloat*)calloc(viewport[2] * viewport[3], sizeof(GLfloat));
glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, zbuffer);
I am sure that the depth component has been successfully read into the zbuffer. However, I think there is something wrong in connection between the screen coordinate and the viewport coord. The problem appear like this:
when I use my mouse to click a pixel on the screen and get its screen coord(x,y), I can''t find its depth component in zbuffer[y* width +x], but could get it in zbuffer[ (y + (vheight-wheight) * width +x]. It seem to me that the content in the zbuffer does a translation vertically.
I also want to say that similar code generates successful result in other environment.
I don''t know if the above problem is common or there is something I need to correct.
I''d like to listen to your opinion.

first :
height = viewport[ 3 ] - viewport[ 1 ]
width = viewport[ 2 ] - viewport[ 0 ]
when you read back form the buffer coordinat system is changed. It''s origin is not at top left corner going right&down like in ortho mode but in lower left corner going right&up
pos = x + (height-y) * width or something like that...
There are more worlds than the one that you hold in your hand...
height = viewport[ 3 ] - viewport[ 1 ]
width = viewport[ 2 ] - viewport[ 0 ]
when you read back form the buffer coordinat system is changed. It''s origin is not at top left corner going right&down like in ortho mode but in lower left corner going right&up
pos = x + (height-y) * width or something like that...
There are more worlds than the one that you hold in your hand...
You should never let your fears become the boundaries of your dreams.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement