You use the texImage2D
function. You'd invoke it like this:
import Data.Vector.Storable (unsafeWith)
import Graphics.Rendering.OpenGL.GL.Texturing.Specification (texImage2D, Level, Border, TextureSize2D(..))
import Graphics.Rendering.OpenGL.GL.PixelRectangles.ColorTable (Proxy(..), PixelInternalFormat(..))
import Graphics.Rendering.OpenGL.GL.PixelRectangles.Rasterization (PixelData(..))
-- ...
(ImageRGBA8 (Image width height dat)) ->
-- Access the data vector pointer
unsafeWith dat $ \ptr ->
-- Generate the texture
texImage2D
-- No cube map
Nothing
-- No proxy
NoProxy
-- No mipmaps
0
-- Internal storage format: use R8G8B8A8 as internal storage
RGBA8
-- Size of the image
(TextureSize2D width height)
-- No borders
0
-- The pixel data: the vector contains Bytes, in RGBA order
(PixelData RGBA UnsignedByte ptr)
Note that Juicy doesn't always give back an RGBA image. You have to handle each of the different image variations:
ImageY8, ImageYA8, ImageRGB8, ImageRGBA8, ImageYCrCb8
Also, before this command, you have to have bound a texture object to store the texture data in.
import Data.ObjectName (genObjectNames)
import Graphics.Rendering.OpenGL.GL.Texturing.Objects (textureBinding)
import Graphics.Rendering.OpenGL.GL.Texturing.Specification (TextureTarget(..))
-- ...
-- Generate 1 texture object
[texObject] <- genObjectNames 1
-- Make it the "currently bound 2D texture"
textureBinding Texture2D $= Just texObject
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.