Skip to content

Instantly share code, notes, and snippets.

@sarnesjo
Last active December 14, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarnesjo/5151894 to your computer and use it in GitHub Desktop.
Save sarnesjo/5151894 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int glfwInit();
void glfwOpenWindowHint(int, int);
int glfwOpenWindow(int, int, int, int, int, int, int, int, int);
const unsigned char * glGetString(unsigned int);
void glfwTerminate();
int main()
{
glfwInit();
glfwOpenWindowHint(0x00020014, 3);
glfwOpenWindowHint(0x00020015, 2);
glfwOpenWindowHint(0x00020018, 0x00050001);
glfwOpenWindow(640, 640, 0, 0, 0, 0, 24, 8, 0x00010001);
printf("%s\n", glGetString(0x1F01));
glfwTerminate();
return 0;
}
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign.C.String
import Foreign.C.Types
import Foreign.Ptr
foreign import ccall unsafe glfwInit :: IO CInt
foreign import ccall unsafe glfwOpenWindowHint :: CInt -> CInt -> IO ()
foreign import ccall unsafe glfwOpenWindow :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO CInt
foreign import ccall unsafe glGetString :: CUInt -> IO (Ptr CUChar)
foreign import ccall unsafe glfwTerminate :: IO ()
main :: IO ()
main = do
glfwInit
glfwOpenWindowHint 0x00020014 3
glfwOpenWindowHint 0x00020015 2
glfwOpenWindowHint 0x00020018 0x00050001
glfwOpenWindow 640 640 0 0 0 0 24 8 0x00010001
glGetString 0x1F01 >>= (peekCString . castPtr) >>= putStrLn
glfwTerminate
{-# LANGUAGE ForeignFunctionInterface #-}
import Control.Concurrent
import Foreign.C.String
import Foreign.C.Types
import Foreign.Ptr
foreign import ccall unsafe glfwInit :: IO CInt
foreign import ccall unsafe glfwOpenWindowHint :: CInt -> CInt -> IO ()
foreign import ccall unsafe glfwOpenWindow :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO CInt
foreign import ccall unsafe glGetString :: CUInt -> IO (Ptr CUChar)
foreign import ccall unsafe glfwTerminate :: IO ()
thread :: MVar () -> IO ()
thread v = do
glfwInit
glfwOpenWindowHint 0x00020014 3
glfwOpenWindowHint 0x00020015 2
glfwOpenWindowHint 0x00020018 0x00050001
glfwOpenWindow 640 640 0 0 0 0 24 8 0x00010001
glGetString 0x1F01 >>= (peekCString . castPtr) >>= putStrLn
glfwTerminate
putMVar v ()
main :: IO ()
main = do
v <- newEmptyMVar
forkOS (thread v)
takeMVar v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment