I’m trying to create a go board using opengl. To do this, I’m trying to draw a bunch of lines to create the grid. However, every tutorial site (including opengl’s) has the examples in C++ and the Haskell wiki doesn’t do a good job of explaining it. I’m new to opengl and would like a tutorial.
Share
I’ll assume that you want to use OpenGL 2.1 or earlier. For OpenGL 3.0, you need different code.
So, in C you would write this:
You write the equivalent in Haskell like this:
With this code, since I used e.g.
1instead of some variable, you might get errors about ambiguous types (So you should replace1with(1 :: GLfloat)), but if you use actual variables that already have the typeGLfloat, you shouldn’t have to do this.Here’s a complete program that draws a white diagonal in the window:
The default OpenGL fixed-function projection uses (-1, -1) for the bottom left and (1, 1) for the top right of the window. You need to alter the projection matrix to get different coordinate spaces.
For more complete examples like this, see the Haskell port of the NEHE tutorials. They use the RAW OpenGL bindings, which are more like the C bindings.