I’m writing a plugin for a third party package which is handing me an AGLContext. The context lets me draw into a 500x300 rectangle in the middle of a 700x400 window.
I’m getting mouse events which are relative to the window’s origin. I need to convert those into view-relative coords so that I can draw a brush which follows the mouse pointer around.
I figured that I could just query GL_VIEWPORT and subtract its x and y offset from the mouse coords to get the view-relative coords. However, this doesn’t work because GL_VIEWPORT returns 0 for both the x and y offsets.
How can this be? If the viewport x and y offsets are both zero, then the rectangle that I’m drawing into should be positioned in the upper left corner of the window. Instead, it is centered in the window.
The modelview matrix is the identity, and projection matrix is a simple ortho projection so where else can those centering offsets be coming from?
This has me baffled.