add Renderer code

This commit is contained in:
nek0 2020-02-06 05:11:10 +01:00
parent d21cc70759
commit 20b77a4068

43
app/Renderer.hs Normal file
View file

@ -0,0 +1,43 @@
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
]