View Full Version : Converting drawable coords to viewport coords

Dean Edmonds
01-19-2006, 10:40 PM
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.

01-20-2006, 01:18 AM
I think you want to grab the AGL_BUFFER_RECT from the context using aglGetInteger. Not 100% certain about that, though.

Dean Edmonds
01-20-2006, 05:41 AM
Yup, that was it! Thanx heaps.