[英]How to call the function glMultiDrawElements :: GLenum -> GHC.Ptr.Ptr GLsizei -> GLenum -> GHC.Ptr.Ptr (GHC.Ptr.Ptr a) -> GLsizei -> IO ()
[英]How to call a function of type Ptr GLubyte -> IO() in Haskell
在 OpenGL 原始库中是以下 function:
glPolygonStipple :: Ptr GLubyte -> IO ()
The C counterpart to this function accepts a pointer to an array, but how can I call this function with an array/list in a Haskell program?
您将使用 mallocArray 分配 memory 和 pokeArray 将您的列表放入其中:
就像是:
do
arrayOfGLuBytes <- (mallocArray 15) :: IO (Ptr GLubyte)
pokeArray arrayOfGLuBytes [1,2,3,4]
glPolygonStipple arrayOfGLuBytes
free arrayOfGLuBytes -- free from Foreign.Marshall.Alloc
Probably best way to go in this situation is storable vectors in the vector package [http://hackage.haskell.org/packages/archive/vector/0.7.1/doc/html/Data-Vector-Storable.html][1 ]。 Package 为不可变和可变向量提供了丰富的接口,因此不必在 IO monad 中创建向量。 除了列表是链表和转换为 arrays inovlve 复制
您的特定示例可能看起来像
let myVector = fromList [1,2,3,4]
in unsafeWith myVector glPolygonStipple
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.