summaryrefslogtreecommitdiff
path: root/testdata/PrimReduce.lc
blob: 6325c79f50cfff82b728faee621d1b83dc76e99f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
clear = FrameBuffer ((ColorImage @1 red))   -- ...

triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
colorFragmentCtx = accumulationContext ((ColorOp NoBlending (V4 True True True True)))

rasterizeWith = rasterizePrimitives
triangles = triangleRasterCtx

cubeVertexStream = fetch "stream4" ((Attribute "position4" :: Vec 4 Float))
mapFragments2 s fs = accumulate colorFragmentCtx  (\() -> ((fs))) s clear
transform s f =  mapPrimitives (\((v)) -> ((f v))) s

rotate :: Float -> Vec 4 Float -> Vec 4 Float
rotate a v = M44F (V4 c (-s) 0 0) (V4 s c 0 0) (V4 0 0 1 0) (V4 0 0 0 1) `PrimMulMatVec` v
  where
    c = PrimCos a
    s = PrimSin a

main =             cubeVertexStream      -- cube vertices
    `transform`    (scale 0.1 . rotate 3)             -- scale them
     &             rasterizeWith triangles ()  -- rasterize
    `mapFragments2` blue                -- set every pixel blue
     &             ScreenOut                 --  draw into screen