module GLHelp (mglCreate,mglDelete,checkGLError,glCreate) where import Foreign.Marshal import Foreign.Ptr import Foreign.Storable import Graphics.GL.Core45 mglCreate :: (GLsizei -> Ptr GLuint -> IO ()) -> IO GLuint mglCreate f = alloca $ \ptr -> f 1 ptr >> peek ptr glCreate :: (GLsizei -> Ptr GLuint -> IO ()) -> Int -> IO [GLuint] glCreate f n = alloca $ \ptr -> f (fromIntegral n) ptr >> peekArray n ptr mglDelete :: (GLsizei -> Ptr GLuint -> IO ()) -> GLuint -> IO () mglDelete f i = with i $ f 1 checkGLError :: String -> IO () checkGLError s = do err <- glGetError case err of 0 -> return () i -> error $ "OpenGL error: " ++ show i ++ " - " ++ s