2020-02-06 04:11:10 +00:00
|
|
|
module Renderer where
|
|
|
|
|
|
|
|
import SDL (($=))
|
|
|
|
|
|
|
|
import qualified Graphics.Rendering.OpenGL as GL
|
|
|
|
|
|
|
|
import Foreign
|
|
|
|
|
2020-02-06 22:18:05 +00:00
|
|
|
initSpriteRenderData = do
|
2020-02-06 04:11:10 +00:00
|
|
|
quadVAO <- GL.genObjectName
|
2020-02-06 04:19:07 +00:00
|
|
|
quadVBO <- GL.genObjectName
|
2020-02-06 04:11:10 +00:00
|
|
|
|
|
|
|
GL.bindBuffer GL.ArrayBuffer $= Just quadVBO
|
|
|
|
withArray rawVertices $ \ptr ->
|
2020-02-06 04:19:07 +00:00
|
|
|
GL.bufferData GL.ArrayBuffer $=
|
2020-02-06 04:11:10 +00:00
|
|
|
( fromIntegral $ length rawVertices * sizeOf (0 :: Float)
|
|
|
|
, ptr
|
|
|
|
, GL.StaticDraw
|
|
|
|
)
|
|
|
|
|
|
|
|
GL.bindVertexArrayObject $= Just quadVAO
|
|
|
|
|
2020-02-06 04:19:07 +00:00
|
|
|
GL.vertexAttribArray (GL.AttribLocation 0) $= GL.Enabled
|
2020-02-06 04:11:10 +00:00
|
|
|
|
2020-02-06 04:19:07 +00:00
|
|
|
GL.vertexAttribPointer (GL.AttribLocation 0) $=
|
2020-02-06 04:11:10 +00:00
|
|
|
( GL.ToFloat
|
2020-02-06 04:19:07 +00:00
|
|
|
, GL.VertexArrayDescriptor 4 GL.Float 0 (plusPtr nullPtr 0)
|
2020-02-06 04:11:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
]
|