[HOpenGL] get Scale of the window in HOpenGL?

Matthijs Kooijman matthijs at stdin.nl
Tue Jun 2 04:13:20 EDT 2009


Hi all,

> Depending on what you exactly want to achieve, it might be possible to setup 
> your modelview matrix and your projection matrix in such a way that you get a 
> 1:1 mapping between object coordinates and window coordinates, so you don't 
> have to apply the inverses.

I recently struggeled with this issue, the following reshape callback does
exactly this.

-- | This function is called when the window is resized
reshape s@(OpenGL.Size w h) = do
        -- Make sure that our model coordinates correspond to pixels
        OpenGL.matrixMode $= OpenGL.Projection
        OpenGL.loadIdentity
        OpenGL.ortho 0 (fromIntegral w) 0 (fromIntegral h) 0 1

        -- Do something funky with the viewport
        OpenGL.viewport $= (OpenGL.Position 0 0, s)


I'm not 100% confident about the final 0 and 1 arguments (which specify the
bounds on the depth axis, but it works like this (specifying 0 0 didn't work
and made the last line be silently ignored!).


Alternatively, you could probably set up the projection matrix such that the
model coordinates always range from -1 to 1 in both directions. IIRC that is
what happens when uinsg only identity matrices and is the default, but I'm not
100% sure. In any case, you always need to set the viewport, AFAIU.

Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/hopengl/attachments/20090602/aac04b09/attachment.bin


More information about the HOpenGL mailing list