[Haskell-beginners] OpenGLRaw Tutorial

jean verdier verdier.jean at gmail.com
Mon Mar 11 12:15:45 CET 2013


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
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners





More information about the Beginners mailing list