[Haskell-cafe] Loading a texture in OpenGL
dagitj at gmail.com
Mon Feb 6 23:55:08 CET 2012
On Mon, Feb 6, 2012 at 12:00 PM, Clark Gaebel
<cgaebel at csclub.uwaterloo.ca> wrote:
> Using the OpenGL package on Hackage, how do I load a texture from an array?
The answer will depend on a few things:
* Which OpenGL package you use, for example OpenGL vs. OpenGLRaw
* What type of 'array' you use.
In the case of the OpenGL package you need to create a PixelData value
and pass that on. You can find example code here:
> In the red book, I see their code using glGenTextures and glBindTexture,
> but I can't find these in the documentation. Are there different functions I
> should be calling?
Yes. As you've noticed the API of the OpenGL package sometimes
(often?) differs from that of the C OpenGL api. If that's what you're
more familiar with then take a look at OpenGLRaw. Here is how to do
the same thing as the previous two links but using OpenGLRaw:
Instead of using Arrays as defined by Haskell98, I would recommend
using something else like Data.Vector. The standard arrays must be
converted to something else to work with OpenGL. Data.Vector on the
other hand allows direct access to the pinned pointer and is thus
suitable for use with OpenGL as is.
Have you seen JuicyPixels? The version on hackage uses arrays, but the
version in github uses vector. I'd recommend using the version from
github. It's faster and it will be easier to pass the data to OpenGL:
More information about the Haskell-Cafe