Haskell使用JuicyPixels-repa类型错误加载OpenGL纹理

时间:2013-10-20 02:22:46

标签: opengl haskell types

我正在尝试将图像加载到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)) }'

1 个答案:

答案 0 :(得分:4)

type signature of texImage2D

texImage2D :: TwoDimensionalTextureTarget t
           => t -> Proxy -> Level -> PixelInternalFormat -> TextureSize2D -> Border -> PixelData a -> IO ()

instances of class TwoDimensionalTextureTargetTextureTargetCubeMapFaceTextureTargetCubeMapTextureTarget2D。这些都不是任何类型的表单Maybe t的类型同义词。因此,提供Nothing作为textImage2D的第一个参数不会进行类型检查。 (可能还有其他错误 - 我只是在Hackage上的错误消息中查找相关类型。)