Skip to content

Instantly share code, notes, and snippets.

@paolino
Created November 25, 2011 11:20
Show Gist options
  • Save paolino/1393305 to your computer and use it in GitHub Desktop.
Save paolino/1393305 to your computer and use it in GitHub Desktop.
linking buggy
import System.Exit ( exitWith, ExitCode(ExitSuccess) )
import Graphics.UI.GLUT
import Foreign.Marshal.Array
myInit :: IO ()
myInit = do
clearColor $= Color4 0 0 0 0
display :: DisplayCallback
display = do
clear [ ColorBuffer, DepthBuffer ]
color (Color3 1.0 1.0 1.0 :: Color3 GLfloat)
withNURBSObj () $ \nurbsObj -> do
nurbsBeginEndCurve nurbsObj $
withArrayLen knots $ \nKnots knots ->
withArray controls $ \controls -> do
nurbsCurve nurbsObj (fromIntegral nKnots) knots stride controls order
flush
where
order = 3
stride = 4 -- number of floats in Vertex
controls = zipWith mkControl points weights
mkControl (x, y) w = Vertex4 (x*w) (y*w) 0 w
-- mkControl (x, y) w = Vertex4 x y 0 w
knots = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
weights = let a = sqrt 0.5 in [1, a, 1, a, 1, a, 1, a, 1]
points = [
(x0, y1), (x0, y2), (x1, y2),
(x2, y2), (x2, y1), (x2, y0),
(x1, y0), (x0, y0), (x0, y1)
]
y1 = (y0 + y2) / 2
x1 = (x0 + x2) / 2
(x0, x2) = (50, 450)
(y0, y2) = (x0, x2)
reshape :: ReshapeCallback
reshape size@(Size w h) = do
viewport $= (Position 0 0, size)
matrixMode $= Projection
loadIdentity
-- ortho2D 0 (fromIntegral w) 0 (fromIntegral h)
-- the following line is not in the original example, but it's good style...
matrixMode $= Modelview 0
keyboard :: KeyboardMouseCallback
keyboard (Char '\27') Down _ _ = exitWith ExitSuccess
keyboard _ _ _ _ = return ()
-- Request double buffer display mode.
-- Register mouse input callback functions
main :: IO ()
main = do
(progName, _args) <- getArgsAndInitialize
initialDisplayMode $= [ SingleBuffered, RGBMode ]
initialWindowSize $= Size 500 500
initialWindowPosition $= Position 100 100
createWindow "Test"
myInit
displayCallback $= display
reshapeCallback $= Just reshape
keyboardMouseCallback $= Just keyboard
mainLoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment