How do I load a texture using Haskell, OpenGL and the JuicyPixels library?
I can get as far as this:
loadImage :: IO ()
loadImage = do image <- readPng "data/Picture.png"
case image of
(Left s) -> do print s
exitWith (ExitFailure 1)
(Right d) -> do case (ImageRGBA i) -> do etc...
How do I convert this to a TextureObject? I think I need to do a conversion between a Vector Word8 and PixelData (for OpenGL to recognize)
You use the
texImage2Dfunction. You’d invoke it like this:Note that Juicy doesn’t always give back an RGBA image. You have to handle each of the different image variations:
Also, before this command, you have to have bound a texture object to store the texture data in.
BTW, many of those imports are added automatically when you import
Graphics.Rendering.OpenGL; you don’t have to import each thing individually if you don’t want.