我正在尝试将图像加载到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)) }'
答案 0 :(得分:4)
texImage2D :: TwoDimensionalTextureTarget t
=> t -> Proxy -> Level -> PixelInternalFormat -> TextureSize2D -> Border -> PixelData a -> IO ()
instances of class TwoDimensionalTextureTarget
为TextureTargetCubeMapFace
,TextureTargetCubeMap
和TextureTarget2D
。这些都不是任何类型的表单Maybe t
的类型同义词。因此,提供Nothing
作为textImage2D
的第一个参数不会进行类型检查。 (可能还有其他错误 - 我只是在Hackage上的错误消息中查找相关类型。)