![](/img/trans.png)
[英]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.