opengl - gluUnProject gives flippped y position -


i have set opengl, origin @ top left corner. however, using gluunproject convert mouse coordinates opengl coordinates, still gives me coordinates origin @ bottom left corner , not sure why is. so, opengl setup follows:

void setup_gl() {     glviewport(0, 0, width, height);     glmatrixmode(gl_projection);     glloadidentity();     // bottom , top flipped change origin     glortho(0, width, height, 0, 0, 1);     glmatrixmode(gl_modelview);     glloadidentity(); } 

the function convert screen coordinates opengl coordinates as:

point get_gl_from_screen(int x, int y) {     set_up_view();     glint viewport[4];     gldouble modelview[16];     gldouble projection[16];      glfloat z;     gldouble px, py, pz;      glgetdoublev(gl_modelview_matrix, modelview );     glgetdoublev(gl_projection_matrix, projection );     glgetintegerv(gl_viewport, viewport);     gluunproject(x, y, z, modelview, projection, viewport, &px, &py, &pz);      return point(px, py); } 

this returns py still if origin bottom left. not sure why. note input coordinates respect origin @ upper left corner.

opengl's window space always defined have origin @ bottom left corner. using projection matrix not flip this. add mirroring component transformation eye clip space (where later window coords derived from). if feed gluunporject point @ y=0, asking object space coordinates appeared @ bottom row after rendering.

in case, means due ortho matrix (and identity modelview), y=height result when ask that.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -