Skip to content

Instantly share code, notes, and snippets.

@jhegedus42
Created July 10, 2015 07:25
Show Gist options
  • Save jhegedus42/a523aff2a411c71aecd3 to your computer and use it in GitHub Desktop.
Save jhegedus42/a523aff2a411c71aecd3 to your computer and use it in GitHub Desktop.
clear = FrameBuffer $ (DepthImage @1 1000, ColorImage @1 navy) -- ...
triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
colorFragmentCtx = AccumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
rasterizeWith = Rasterize
triangles = triangleRasterCtx
cubeVertexStream = Fetch "stream4" Triangles (Attribute "position4" :: Vec 4 Float)
mapFragments s fs = Accumulate colorFragmentCtx PassAll (\a -> FragmentOutRastDepth $ fs a) s clear
transform s f = Transform (\v -> VertexOut (f v) 1 () (Smooth v)) s
rotate' v = (Uniform "MVP" :: Mat 4 4 Float) *. v
pulse = (abs ((sin time)/3))
main = cubeVertexStream -- cube vertices
`transform` (scale ( pulse ). rotate') -- scale them
& rasterizeWith triangles -- rasterize
`mapFragments` id
& ScreenOut -- draw into screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment