finish episode 12

This commit is contained in:
nek0 2020-05-17 21:27:35 +02:00
parent f5ae496256
commit 8c58ec6d81
2 changed files with 21 additions and 2 deletions

View file

@ -4,12 +4,16 @@ This softwre aims to be an OpenGL renderer written in Haskell following the
OpenGL tutorial by The Cherno OpenGL tutorial by The Cherno
(<https://www.youtube.com/playlist?list=PLlrATfBNZ98foTJPJ_Ev03o2oq3-GGOS2>). (<https://www.youtube.com/playlist?list=PLlrATfBNZ98foTJPJ_Ev03o2oq3-GGOS2>).
## Important notes
There are some major deviations from the tutorial setup here as follows: There are some major deviations from the tutorial setup here as follows:
* Code base is entirely written in Haskell, not C++ * Code base is entirely written in Haskell, not C++
* Instead of GLFW with GLEW I use SDL2 out of familiarity * Instead of GLFW with GLEW I use SDL2 out of familiarity
* Shaders are actually split into files per type, since IÄmnot willing to * Shaders are actually split into files per type, since IÄmnot willing to
unleash Haskell list magic unleash Haskell list magic
* Since I am using the OpenGL core profile from the start there is also a
vertex array creation call present from the start.
I leave as many helpful comments as possible throughout the code, so feel free I leave as many helpful comments as possible throughout the code, so feel free
to peruse it. to peruse it.

View file

@ -67,8 +67,8 @@ main = do
-- -- VERTICES -- -- VERTICES
-- first, create and bind a vertex array object -- first, create and bind a vertex array object
bo <- GL.genObjectName vao <- GL.genObjectName
GL.bindVertexArrayObject $= Just bo GL.bindVertexArrayObject $= Just vao
-- define vertices (positions of the triangle corners) as List of Floats -- define vertices (positions of the triangle corners) as List of Floats
let vertexPositions = let vertexPositions =
@ -155,6 +155,15 @@ main = do
-- -- EVENTING AND DRAWING -- -- EVENTING AND DRAWING
-- -- UNBINDING ALL BUFFERS AND VERTEX ARRAYS
GL.bindVertexArrayObject $= Nothing
GL.bindBuffer GL.ArrayBuffer $= Nothing
GL.bindBuffer GL.ElementArrayBuffer $= Nothing
GL.currentProgram $= Nothing
-- -- LOOPING
-- initial poll for events -- initial poll for events
evs <- newMVar =<< SDL.pollEvents evs <- newMVar =<< SDL.pollEvents
@ -175,6 +184,12 @@ main = do
-- clear buffers before drawing -- clear buffers before drawing
GL.clear [GL.ColorBuffer] GL.clear [GL.ColorBuffer]
-- rebind everything neccessary for draw call
GL.bindVertexArrayObject $= Just vao
-- (note the missing bindings to the vertex buffer and the attrib pointer)
GL.bindBuffer GL.ElementArrayBuffer $= Just ibo
GL.currentProgram $= Just sp
-- throw away previous errors -- throw away previous errors
-- void $ get GL.errors -- void $ get GL.errors