[HOpenGL] Set polygon mode?

C Flynn scs4cajf at comp.leeds.ac.uk
Mon Jul 23 06:36:45 EDT 2007


On Sun, 22 Jul 2007, Sebastian Sylvan wrote:

> On 21/07/07, Hugh Perkins <hughperkins at gmail.com> wrote:
>> Hi, question, how do I do "Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_LINE);" in
>> HOpenGl?
>> 
>> Maybe something like "polygonMode $= (Line,Line)" ?
>> 
>> (By the way, what does "$=" do?)
>> 
>
>> From the docs (
> http://www.haskell.org/ghc/docs/latest/html/libraries/index.html ):
>
> polygonMode :: StateVar (PolygonMode, PolygonMode)
>
> So apparently it's a value of type "StateVar ...". Right, so look up
> StateVar and we see that it's a data type wich is an instance of
> HasGetter and HasSetter. So it appears that it models some sort of
> mutable state variable. In this case we want to set the variable, so
> HasSetter seems like the right place to look:
>
> class HasSetter s where
>      ($=) :: s a -> a -> IO ()
>
> There's no textual description in the doc, but from the type and name
> of the class it looks like this takes a statevar, a value, and sets
> the state variable to the value. So indeed the following should do
> what you want:
>
> polygonMode $= (Line,Line)
>
> And now you should also know what that operator does. It's just a
> convenient way of setting OpenGL state variables (and you can also
> find e.g. ($~) which modifies a state variable by the function you
> pass it).
>

I quite like the $= operator. Makes it clear you're playing around with an
underlying state variable. In the C binding it's often not clear you're
doing this which can lead to unexpected behaviours.

Charles,


More information about the HOpenGL mailing list