Re: get Scale of the window in HOpenGL?

Matthijs Kooijman <[email protected]> Tue, 2 Jun 2009 10:13:20 +0200
Newsgroups gmane.comp.lang.haskell.hopengl
Message-ID <[email protected]>
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

_______________________________________________
HOpenGL mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/hopengl
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkok3yAACgkQz0nQ5oovr7yEtACfQ+KPTmHb+JtAf/VdMB+4HBs1
ifoAoJuafI7UlI2ke/fd2q75UK/htzzp
=HYBn
-----END PGP SIGNATURE-----