[Haskell-beginners] OpenGLRaw Tutorial

Isaac Dupree ml at isaac.cedarswampstudios.org
Mon Mar 11 18:37:23 CET 2013


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-0002.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-0003.hs>


More information about the Beginners mailing list