From 20b77a4068fc5c230c2cab8d48a72e86d5708e9b Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 6 Feb 2020 05:11:10 +0100 Subject: [PATCH] add Renderer code --- app/Renderer.hs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/Renderer.hs diff --git a/app/Renderer.hs b/app/Renderer.hs new file mode 100644 index 0000000..9bddb10 --- /dev/null +++ b/app/Renderer.hs @@ -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 + ]