【问题标题】:Haskell load OpenGL texture with JuicyPixels-repa type errorHaskell 加载带有 JuicyPixels-repa 类型错误的 OpenGL 纹理
【发布时间】:2013-10-20 02:22:45
【问题描述】:

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

【问题讨论】:

    标签: opengl haskell types


    【解决方案1】:

    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 的错误消息中查找了相关类型。)

    【讨论】:

    • NB 问题中的代码是正确的如果您使用的是旧版本的 OpenGL (2.8.0.0)。从他的错误信息来看,他没有像这个答案那样使用旧版本(可能使用 2.9.0.0)。
    • 这正是问题所在,我没有意识到我正在查看旧文档。非常感谢!
    猜你喜欢
    • 2013-05-06
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 2017-04-28
    • 2023-03-31
    • 2013-11-27
    • 2017-06-11
    相关资源
    最近更新 更多