get initial renderer to run

This commit is contained in:
nek0 2020-05-22 02:29:16 +02:00
parent 90d2ef73e6
commit 4a499165c4
4 changed files with 31 additions and 7 deletions

View file

@ -32,5 +32,6 @@ executable renderer-tutorial
, VertexArray
, IndexBuffer
, Shader
, Renderer
hs-source-dirs: src
default-language: Haskell2010

View file

@ -17,7 +17,7 @@ data IndexBuffer a = IndexBuffer
{ iBufId :: GL.BufferObject -- buffer id
, iBufSize :: GL.GLsizeiptr -- size of data
, iBufData :: Ptr a -- pointer to data
, iBufCount :: GL.GLuint -- number of data elements
, iBufCount :: GL.GLint -- number of data elements
}
-- instanciate typeclass from BufferClass and fill in missing implementations

View file

@ -37,6 +37,7 @@ import VertexArray
import VertexBuffer
import IndexBuffer
import Shader
import Renderer
main :: IO ()
main = do
@ -169,11 +170,11 @@ main = do
-- clear buffers before drawing
GL.clear [GL.ColorBuffer]
-- rebind everything neccessary for draw call
bind vao
-- (note the missing bindings to the vertex buffer and the attrib pointer)
bind ibo
bind sp
-- -- rebind everything neccessary for draw call
-- bind vao
-- -- (note the missing bindings to the vertex buffer and the attrib pointer)
-- bind ibo
-- bind sp
-- throw away previous errors
-- void $ get GL.errors
@ -186,7 +187,8 @@ main = do
setUniform sp "u_color" (GL.Color4 newRed 0.5 0 1 :: GL.Color4 GL.GLfloat)
-- the actual drawing happens here
GL.drawElements GL.Triangles 6 GL.UnsignedInt nullPtr
draw vao ibo sp
-- GL.drawElements GL.Triangles 6 GL.UnsignedInt nullPtr
err <- get GL.errors
when (not $ null err) (print $ "loop errors: " <> show err)

21
src/Renderer.hs Normal file
View file

@ -0,0 +1,21 @@
module Renderer where
import SDL (($=), get)
import qualified Graphics.Rendering.OpenGL as GL
import Foreign.Ptr
-- internal imports
import BindableClass
import VertexArray
import IndexBuffer
import Shader
draw :: VertexArray -> (IndexBuffer a) -> Shader -> IO ()
draw va ib sp = do
bind sp
bind va
bind ib
GL.drawElements GL.Triangles (iBufCount ib) GL.UnsignedInt nullPtr