[HOpenGL] (not?) using preservingMatrix

Sebastian Sylvan sebastian.sylvan at gmail.com
Fri Jan 5 13:28:15 EST 2007


On 1/5/07, jamin1001 <jamin1001 at yahoo.com> wrote:
>
> In C OpenGL, you can do something like this to use matrices for computation
> without affecting context:
>
> glMatrixMode (GL_MODELVIEW) ;
> glPushMatrix () ;
> glLoadMatrix (your_matrix) ;
> // do whatever you want with your your matrix
> // for exampl glMultMatrix (your_matrix2) ;
> ...
> // at the end of your calculations use
> glGetFloatv (GL_MODELVIEW_MATRIX, your_matrix_result) ;
> glPopMatrix () ; // nothing has changed !!!
>
> I'm not exactly sure how this is done with HOpenGL. i.e., how can I get the
> result of a matrix transformation not effecting the MODELVIEW, etc.
> matrices?  Could someone give an example?
>
>
> Thanks,
>
> Jamin

glPushMatrix() ; foo ; glPopMatrix();

Is written like so:

preservingMatrix foo

Often you would write things like
do foo
    preservingMatrix $
        do bar
            baz
    foo2

Here bar and baz may modify the matrices, but as soon as you leave the
scope of the action passed to preservingMatrix, the matrix stack is
popped (glPopMatrix()).

The Haskell way is better, since there is no way of ever forgetting to
pop the matrix - preservingMatrix is like a user defined control
structure. That's what first class actions buys you.

-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the HOpenGL mailing list