我正在尝试将图像加载到 OpenGL 纹理中,但我不确定如何解决我遇到的类型错误。根据错误文本,我认为在我的GL.texImage2D
通话中某处我搞砸了,但这里似乎没有任何问题。
import Graphics.Rendering.OpenGL as GL
import Graphics.Rendering.OpenGL (($=))
import Codec.Picture.Repa as Repa
newImage fname = do
img <- Repa.readImage fname
case img of
Left _ -> return Nothing
Right x -> do
let (dat, w, h) = Repa.toForeignPtr . Repa.reverseColorChannel $ x
[tex] <- genObjectNames 1
GL.textureBinding GL.Texture2D $= Just tex
withForeignPtr dat $ \ptr -> do
(GL.texImage2D
Nothing
GL.NoProxy
0
GL.RGBA8
(GL.TextureSize2D (fromIntegral w) (fromIntegral h))
0
(GL.PixelData GL.RGBA GL.UnsignedByte ptr))
return $ Just tex
这是我得到的错误。
No instance for (TwoDimensionalTextureTarget (Maybe a0))
arising from a use of `texImage2D'
Possible fix:
add an instance declaration for
(TwoDimensionalTextureTarget (Maybe a0))
In a stmt of a 'do' block:
(texImage2D
Nothing
NoProxy
0
RGBA8
(TextureSize2D (fromIntegral w) (fromIntegral h))
0
(PixelData RGBA UnsignedByte ptr))
In the expression:
do { (texImage2D
Nothing
NoProxy
0
RGBA8
(TextureSize2D (fromIntegral w) (fromIntegral h))
0
(PixelData RGBA UnsignedByte ptr)) }
In the second argument of `($)', namely
`\ ptr
-> do { (texImage2D
Nothing
NoProxy
0
RGBA8
(TextureSize2D (fromIntegral w) (fromIntegral h))
0
(PixelData RGBA UnsignedByte ptr)) }'