Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  OpenGLRaw Tutorial (jean verdier)
   2. Re:  OpenGLRaw Tutorial (Ertugrul S?ylemez)
   3. Re:  Beginners Digest, Vol 57, Issue 15 (Patrick Lynch)
   4. Re:  OpenGLRaw Tutorial (Michael Baker)
   5. Re:  OpenGLRaw Tutorial (Isaac Dupree)


----------------------------------------------------------------------

Message: 1
Date: Mon, 11 Mar 2013 12:15:45 +0100
From: jean verdier <[email protected]>
Subject: Re: [Haskell-beginners] OpenGLRaw Tutorial
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"

Instead of using some complex functions, you should probably try to
simply use simpler constructs to see if everything is correctly setup:
    glBegin gl_TRIANGLES
    glVertex3f 0.75    0.75    0.0
    glVertex3f 0.75    (-0.75) 0.0
    glVertex3f (-0.75) (-0.75) 0.0
    glEnd
or
    glBegin gl_TRIANGLES
    glVertex4f 0.75    0.75    0.0 1
    glVertex4f 0.75    (-0.75) 0.0 1
    glVertex4f (-0.75) (-0.75) 0.0 1
    glEnd
Your program shows something using this.
I haven't looked at the tutorial you're following but you should stick
to the OpenGL references as i've found that most tutorials are crap
(there are still good ones like NeHe stuff i think).

Back to your problem: 
you should use GLfloat and not Float in your vertex definition.
Your buffer definition should be:
      withArray verticies $ \ary -> 
        glBufferData 
          gl_ARRAY_BUFFER 
          -- (fromIntegral $ sizeOf ary) 
          (fromIntegral (length verticies * sizeOf (0::GLfloat)))
          ary 
          gl_STATIC_DRAW

The C version may get away with (sizeof vertices) because it uses the
actual array (may be false) size but you have to compute the size of the
array that is the number of elements times the size of elements.

You're trying to draw from a VBO so i think you should not use
      --glEnableVertexAttribArray 0
You use the VBO:
You need to enable client state
      glEnableClientState gl_VERTEX_ARRAY
Bind the buffer that holds the data
      glBindBuffer gl_ARRAY_BUFFER buffer
Set the bound buffer to be the vertex coords
      glVertexPointer 4 gl_FLOAT 0 nullPtr
Call the draw   
      glDrawArrays gl_TRIANGLES 0 3
 
      glDisableClientState gl_VERTEX_ARRAY 

This may be explained properly in:
http://nehe.gamedev.net/tutorial/vertex_buffer_objects/22002/

On Mon, 2013-03-11 at 01:45 -0500, Michael Baker wrote:
> I'm trying to follow this book on
> OpenGL: http://www.arcsynthesis.org/gltut/Basics/Tut01%20Following%
> 20the%20Data.html
> 
> 
> I'm trying to follow the examples using the OpenGLRaw package as the
> OpenGL package doesn't map very neatly to any of the examples. For
> instance, it is not clear to me now to create and use the vertex array
> used in the example that I linked to.
> 
> 
> However, I'm struggling a bit because I haven't used Haskell's foreign
> interface before. Here is an attempt which is expected to draw a
> triangle, but instead draws nothing: http://hpaste.org/83837
> 
> 
> Does anyone know of a tutorial for OpenGLRaw or the foreign interface
> that might help me understand how to marshall data around? It seems
> like many people turn to OpenGLRaw when they're learning OpenGL so
> that they can follow the tutorials. I imagine it would be useful to
> have a guide out there that covers how to actually use it.
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners





------------------------------

Message: 2
Date: Mon, 11 Mar 2013 12:43:25 +0100
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] OpenGLRaw Tutorial
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Michael Baker <[email protected]> wrote:

> However, I'm struggling a bit because I haven't used Haskell's foreign
> interface before. Here is an attempt which is expected to draw a
> triangle, but instead draws nothing: http://hpaste.org/83837

The first thing I notice is that you never set a vertex color, which is
black by default in all cases I've encountered.  So it may be drawing,
but you may simply not see it. =)

Before you begin drawing put this somewhere:

    glColor3f 1 0 0

That should draw a red shape.  Another option is to set a different
clear color:

    glClearColor 1 0 0 1

That sets a red background.


> Does anyone know of a tutorial for OpenGLRaw or the foreign interface
> that might help me understand how to marshall data around? It seems
> like many people turn to OpenGLRaw when they're learning OpenGL so
> that they can follow the tutorials. I imagine it would be useful to
> have a guide out there that covers how to actually use it.

My recommendation is to go with the higher level OpenGL library.  The
main difference is that the `gl` prefix is dropped and the numerous
similar functions (`color2f`, `color3f`, `color4f`, etc.) are collapsed
into a single polymorphic function `color`:

    import qualified Graphics.Rendering.OpenGL as GL

    GL.color (GL.Color3 1 0 (0 :: GL.GLfloat))

This looks more complicated, but it makes other things a lot easier, so
in the end you win.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130311/2d8a803e/attachment-0001.pgp>

------------------------------

Message: 3
Date: Mon, 11 Mar 2013 09:30:56 -0400
From: "Patrick Lynch" <[email protected]>
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 57, Issue 15
To: <[email protected]>
Message-ID: <FDC377B6DD82456D8A98939266B7A0D8@UserPC>
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
        reply-type=original

Good morning,
...anyone working with YESOD?
Good day

----- Original Message ----- 
From: <[email protected]>
To: <[email protected]>
Sent: Monday, March 11, 2013 7:00 AM
Subject: Beginners Digest, Vol 57, Issue 15


> Send Beginners mailing list submissions to
> [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://www.haskell.org/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
> [email protected]
>
> You can reach the person managing the list at
> [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>   1. Re:  Using stack inside a function without declaring it as
>      input (Krzysztof Skrz?tnicki)
>   2. Re:  Using stack inside a function without declaring it as
>      input (Emanuel Koczwara)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 11 Mar 2013 11:15:32 +0100
> From: Krzysztof Skrz?tnicki <[email protected]>
> Subject: Re: [Haskell-beginners] Using stack inside a function without
> declaring it as input
> To: doaltan <[email protected]>, The Haskell-Beginners Mailing List
> - Discussion of primarily beginner-level topics related to Haskell
> <[email protected]>
> Message-ID:
> <cam7aevhagkboornwmsu-ghym5sjixxg3haojtdjnya_x72t...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> There are some things clearly missing in your description. I think you 
> need
> to read your problem more carefully and perhaps consult some accompanying
> materials too.
>
> Other than that I see no way one can sensibly answer your question without
> more information.
>
> Best regards,
> Krzysztof Skrz?tnicki
>
>
> On Mon, Mar 11, 2013 at 10:36 AM, doaltan <[email protected]> wrote:
>
>> Hi I have a function like this :
>> myfunc :: [Char] -> [Char]
>> It  is supposed to work pretty much like this :
>>
>>    1. Take a string
>>    2. Put some elements of this input string to output string and put
>>    others to stack.
>>    3. Pop elements to that output string too.
>>    4. Do 2 and 3 recursively until stack is empty.
>>    5. Print the output string when stack is empty.
>>
>>
>> I couldn't figure out where to define stack and output string. Can you
>> help me with that? I'm new to Haskell so I can't think in Haskell's logic
>> very well.
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> <http://www.haskell.org/pipermail/beginners/attachments/20130311/b504dd28/attachment-0001.htm>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 11 Mar 2013 11:29:27 +0100
> From: Emanuel Koczwara <[email protected]>
> Subject: Re: [Haskell-beginners] Using stack inside a function without
> declaring it as input
> To: doaltan <[email protected]>, The Haskell-Beginners Mailing List
> - Discussion of primarily beginner-level topics related to Haskell
> <[email protected]>
> Message-ID:
> <1362997767.13571.11.camel@emanuel-Dell-System-Vostro-3750>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi,
>
> Dnia 2013-03-11, pon o godzinie 09:36 +0000, doaltan pisze:
>> Hi I have a function like this :
>> myfunc :: [Char] -> [Char]
>> It  is supposed to work pretty much like this :
>>      1. Take a string
>>      2. Put some elements of this input string to output string and
>>         put others to stack.
>>      3. Pop elements to that output string too.
>>      4. Do 2 and 3 recursively until stack is empty.
>>      5. Print the output string when stack is empty.
>>
>> I couldn't figure out where to define stack and output string. Can you
>> help me with that? I'm new to Haskell so I can't think in Haskell's
>> logic very well.
>>
>
>  You can try to define a second function inside myfunc with the stack
> as an argument:
>
> myfunc :: String -> String
> myfunc str = myfunc' [] str
>  where myfunc' stack str = ...
>
>  myfunc' can take the stack as an argument, myfunc can call myfunc'
> passing the empty stack.
>
>  You should describe your problem more precisely to get more accurate
> answers.
>
> Emanuel
>
>
>
>
>
> ------------------------------
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
> End of Beginners Digest, Vol 57, Issue 15
> *****************************************
> 




------------------------------

Message: 4
Date: Mon, 11 Mar 2013 10:41:58 -0500
From: Michael Baker <[email protected]>
Subject: Re: [Haskell-beginners] OpenGLRaw Tutorial
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CACwW0UY+qJC4HsOBhuDXSqLhwjC5xgLab9oXEP-+NFBmP=n...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Thanks for the advice everyone.

I'm using Haskell rather than C/C++ because I'm not particularly interested
in writing an entire application in C/C++. If I learn OpenGL using C, then
I'm still going to have to learn to use the bindings in whatever language I
ultimately decide to use. Haskell seems well suited to this given all of
its nice foreign interface packages. Additionally, knowing how to interface
with C libraries seems like a useful skill to have.

I've already gone through the first few chapters of the red book using the
higher level OpenGL. The concern that lead me to try OpenGLRaw instead is
that drawing every vertex/color/etc with a separate function call seems
incredibly inefficient. I imagine I'm going to have to learn to use buffers
at some point. In fact, there is a section about them in the second chapter
of the red book, which I skipped because I couldn't figure out how to do it
with the high level OpenGL package. Also, it seems like the high level
package only truly supports the 2.1 spec, whereas the Raw package supports
the 3.2 spec.

If everyone legitimately thinks that the higher level library is the way to
go for writing actual OpenGL programs then I'll give it another shot.  It
looks like the Haskell translations of the red book examples might get me
unblocked in that respect. I just felt like I would be better served by
learning how to use the lower level bindings, which are closer to actual
OpenGL.


On Mon, Mar 11, 2013 at 6:43 AM, Ertugrul S?ylemez <[email protected]> wrote:

> Michael Baker <[email protected]> wrote:
>
> > However, I'm struggling a bit because I haven't used Haskell's foreign
> > interface before. Here is an attempt which is expected to draw a
> > triangle, but instead draws nothing: http://hpaste.org/83837
>
> The first thing I notice is that you never set a vertex color, which is
> black by default in all cases I've encountered.  So it may be drawing,
> but you may simply not see it. =)
>
> Before you begin drawing put this somewhere:
>
>     glColor3f 1 0 0
>
> That should draw a red shape.  Another option is to set a different
> clear color:
>
>     glClearColor 1 0 0 1
>
> That sets a red background.
>
>
> > Does anyone know of a tutorial for OpenGLRaw or the foreign interface
> > that might help me understand how to marshall data around? It seems
> > like many people turn to OpenGLRaw when they're learning OpenGL so
> > that they can follow the tutorials. I imagine it would be useful to
> > have a guide out there that covers how to actually use it.
>
> My recommendation is to go with the higher level OpenGL library.  The
> main difference is that the `gl` prefix is dropped and the numerous
> similar functions (`color2f`, `color3f`, `color4f`, etc.) are collapsed
> into a single polymorphic function `color`:
>
>     import qualified Graphics.Rendering.OpenGL as GL
>
>     GL.color (GL.Color3 1 0 (0 :: GL.GLfloat))
>
> This looks more complicated, but it makes other things a lot easier, so
> in the end you win.
>
>
> Greets,
> Ertugrul
>
> --
> Not to be or to be and (not to be or to be and (not to be or to be and
> (not to be or to be and ... that is the list monad.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130311/d72ed588/attachment-0001.htm>

------------------------------

Message: 5
Date: Mon, 11 Mar 2013 13:37:23 -0400
From: Isaac Dupree <[email protected]>
Subject: Re: [Haskell-beginners] OpenGLRaw Tutorial
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

On 03/11/2013 11:41 AM, Michael Baker wrote:
> The concern that lead me to try OpenGLRaw
> instead is that drawing every vertex/color/etc with a separate function
> call seems incredibly inefficient. I imagine I'm going to have to learn
> to use buffers at some point.

You are correct.  Partly for that reason, glBegin()/glEnd()/glVertex*() 
don't even exist in OpenGL ES and are deprecated since OpenGL 3.0.  It's 
a shame that so many OpenGL tutorials still teach them.

Note to others: your program depends on glfw-b (or anyway, Hackage 
'glfw-b' works and Hackage 'glfw' doesn't).

glEnableVertexAttribArray/glVertexAttribPointer are for passing data to 
shader programs, I believe.  Everyone should use shader programs (GLSL). 
  GL without shader programs uses the "fixed-function pipeline" which is 
deprecated.  But I haven't used shaders yet, so I've attached how to do 
it with VBOs and the fixed-function pipeline.  I used 
glInterleavedArrays and glDrawArrays.  (That's probably not the only way 
to do it; OpenGL has lots of legacy and semi-redundant functions.)

As jean verdier noted, your byte count argument to glBufferData was 
wrong; "fromIntegral $ length verticies * sizeOf (head verticies)" fixes it.

Four coordinates per vertex is (as far as I know) not very useful for 
two-dimensional or three-dimensional shapes.

Doing glGenBuffers every frame without glDeleteBuffers leaks buffers. 
Either save them or delete them.  I didn't fix this. Control.Exception's 
bracket or bracket_ can be useful for this sort of thing.

I also attached a version that can attach a color to each vertex. 
Haskell FFI peeps, is there a better way to do this than writing a 
Storable instance for each GL buffer data layout?

-Isaac (who has been learning modern OpenGL for http://www.lasercake.net/ )

-------------- next part --------------
A non-text attachment was scrubbed...
Name: testglyay.hs
Type: text/x-haskell
Size: 947 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130311/f64ce309/attachment.hs>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testglyay2.hs
Type: text/x-haskell
Size: 1549 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130311/f64ce309/attachment-0001.hs>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 57, Issue 16
*****************************************

Reply via email to