Eri*_*ric 4 opengl haskell ffi
在OpenGL Raw库中有以下功能:
glPolygonStipple :: Ptr GLubyte -> IO ()
Run Code Online (Sandbox Code Playgroud)
此函数的C对应接受指向数组的指针,但如何在Haskell程序中使用数组/列表调用此函数?
您将使用mallocArray分配内存,并使用pokeArray将列表放入其中:
就像是:
do
arrayOfGLuBytes <- (mallocArray 15) :: IO (Ptr GLubyte)
pokeArray arrayOfGLuBytes [1,2,3,4]
glPolygonStipple arrayOfGLuBytes
free arrayOfGLuBytes -- free from Foreign.Marshall.Alloc
Run Code Online (Sandbox Code Playgroud)