get initial renderer to run
This commit is contained in:
parent
90d2ef73e6
commit
4a499165c4
4 changed files with 31 additions and 7 deletions
|
@ -32,5 +32,6 @@ executable renderer-tutorial
|
||||||
, VertexArray
|
, VertexArray
|
||||||
, IndexBuffer
|
, IndexBuffer
|
||||||
, Shader
|
, Shader
|
||||||
|
, Renderer
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
|
@ -17,7 +17,7 @@ data IndexBuffer a = IndexBuffer
|
||||||
{ iBufId :: GL.BufferObject -- buffer id
|
{ iBufId :: GL.BufferObject -- buffer id
|
||||||
, iBufSize :: GL.GLsizeiptr -- size of data
|
, iBufSize :: GL.GLsizeiptr -- size of data
|
||||||
, iBufData :: Ptr a -- pointer to 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
|
-- instanciate typeclass from BufferClass and fill in missing implementations
|
||||||
|
|
14
src/Main.hs
14
src/Main.hs
|
@ -37,6 +37,7 @@ import VertexArray
|
||||||
import VertexBuffer
|
import VertexBuffer
|
||||||
import IndexBuffer
|
import IndexBuffer
|
||||||
import Shader
|
import Shader
|
||||||
|
import Renderer
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
@ -169,11 +170,11 @@ main = do
|
||||||
-- clear buffers before drawing
|
-- clear buffers before drawing
|
||||||
GL.clear [GL.ColorBuffer]
|
GL.clear [GL.ColorBuffer]
|
||||||
|
|
||||||
-- rebind everything neccessary for draw call
|
-- -- rebind everything neccessary for draw call
|
||||||
bind vao
|
-- bind vao
|
||||||
-- (note the missing bindings to the vertex buffer and the attrib pointer)
|
-- -- (note the missing bindings to the vertex buffer and the attrib pointer)
|
||||||
bind ibo
|
-- bind ibo
|
||||||
bind sp
|
-- bind sp
|
||||||
|
|
||||||
-- throw away previous errors
|
-- throw away previous errors
|
||||||
-- void $ get GL.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)
|
setUniform sp "u_color" (GL.Color4 newRed 0.5 0 1 :: GL.Color4 GL.GLfloat)
|
||||||
|
|
||||||
-- the actual drawing happens here
|
-- 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
|
err <- get GL.errors
|
||||||
when (not $ null err) (print $ "loop errors: " <> show err)
|
when (not $ null err) (print $ "loop errors: " <> show err)
|
||||||
|
|
||||||
|
|
21
src/Renderer.hs
Normal file
21
src/Renderer.hs
Normal 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
|
Loading…
Reference in a new issue