canvas/app/Renderer.hs

44 lines
955 B
Haskell
Raw Normal View History

2020-02-06 04:11:10 +00:00
module Renderer where
import SDL (($=))
import qualified Graphics.Rendering.OpenGL as GL
import qualified Graphics.GLUtil as GLU
import Foreign
initRenderData = do
quadVAO <- GL.genObjectName
quadVBO <- GL.genObjectname
GL.bindBuffer GL.ArrayBuffer $= Just quadVBO
withArray rawVertices $ \ptr ->
GL.bufferData Gl.ArrayBuffer $=
( fromIntegral $ length rawVertices * sizeOf (0 :: Float)
, ptr
, GL.StaticDraw
)
GL.bindVertexArrayObject $= Just quadVAO
Gl.VertexattribArray (GL.AttribLocation 0) $= GL.Enabled
Gl.vertexAttribPointer (GL.AttribLocation 0) $=
( GL.ToFloat
, GL.VertesArrayDescriptor 4 GL.Float 0 (plusPtr nullptr 0)
)
GL.bindBuffer GL.ArrayBuffer $= Nothing
GL.bindVertexArrayObject $= Nothing
where
rawVertices :: [Float]
rawVertices =
[ 0, 1, 0, 0
, 1, 0, 1, 0
, 0, 0, 0, 0
, 0, 1, 0, 1
, 1, 1, 1, 1
, 1, 0, 1, 0
]