[Haskell-beginners] OpenGLRaw Tutorial
Michael Baker
michaeltbaker at gmail.com
Mon Mar 11 16:41:58 CET 2013
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 <es at ertes.de> wrote:
> Michael Baker <michaeltbaker at gmail.com> 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
> Beginners at haskell.org
> 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.htm>
More information about the Beginners
mailing list