<div dir="ltr">Excellent Isaac, thanks!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 11, 2013 at 12:37 PM, Isaac Dupree <span dir="ltr">&lt;<a href="mailto:ml@isaac.cedarswampstudios.org" target="_blank">ml@isaac.cedarswampstudios.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 03/11/2013 11:41 AM, Michael Baker wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The concern that lead me to try OpenGLRaw<br>
instead is that drawing every vertex/color/etc with a separate function<br>
call seems incredibly inefficient. I imagine I&#39;m going to have to learn<br>
to use buffers at some point.<br>
</blockquote>
<br></div>
You are correct.  Partly for that reason, glBegin()/glEnd()/glVertex*() don&#39;t even exist in OpenGL ES and are deprecated since OpenGL 3.0.  It&#39;s a shame that so many OpenGL tutorials still teach them.<br>
<br>
Note to others: your program depends on glfw-b (or anyway, Hackage &#39;glfw-b&#39; works and Hackage &#39;glfw&#39; doesn&#39;t).<br>
<br>
glEnableVertexAttribArray/<u></u>glVertexAttribPointer are for passing data to shader programs, I believe.  Everyone should use shader programs (GLSL).  GL without shader programs uses the &quot;fixed-function pipeline&quot; which is deprecated.  But I haven&#39;t used shaders yet, so I&#39;ve attached how to do it with VBOs and the fixed-function pipeline.  I used glInterleavedArrays and glDrawArrays.  (That&#39;s probably not the only way to do it; OpenGL has lots of legacy and semi-redundant functions.)<br>

<br>
As jean verdier noted, your byte count argument to glBufferData was wrong; &quot;fromIntegral $ length verticies * sizeOf (head verticies)&quot; fixes it.<br>
<br>
Four coordinates per vertex is (as far as I know) not very useful for two-dimensional or three-dimensional shapes.<br>
<br>
Doing glGenBuffers every frame without glDeleteBuffers leaks buffers. Either save them or delete them.  I didn&#39;t fix this. Control.Exception&#39;s bracket or bracket_ can be useful for this sort of thing.<br>
<br>
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?<br>
<br>
-Isaac (who has been learning modern OpenGL for <a href="http://www.lasercake.net/" target="_blank">http://www.lasercake.net/</a> )<br>
<br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>