From 8c58ec6d818aedb499643f0dac11097b6c4e3745 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 17 May 2020 21:27:35 +0200 Subject: [PATCH] finish episode 12 --- README.md | 4 ++++ src/Main.hs | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec6fc01..484ef1c 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,16 @@ This softwre aims to be an OpenGL renderer written in Haskell following the OpenGL tutorial by The Cherno (). +## Important notes + There are some major deviations from the tutorial setup here as follows: * Code base is entirely written in Haskell, not C++ * Instead of GLFW with GLEW I use SDL2 out of familiarity * Shaders are actually split into files per type, since IÄmnot willing to 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 to peruse it. diff --git a/src/Main.hs b/src/Main.hs index 59f170f..aaad3aa 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -67,8 +67,8 @@ main = do -- -- VERTICES -- first, create and bind a vertex array object - bo <- GL.genObjectName - GL.bindVertexArrayObject $= Just bo + vao <- GL.genObjectName + GL.bindVertexArrayObject $= Just vao -- define vertices (positions of the triangle corners) as List of Floats let vertexPositions = @@ -155,6 +155,15 @@ main = do -- -- 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 evs <- newMVar =<< SDL.pollEvents @@ -175,6 +184,12 @@ main = do -- clear buffers before drawing 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 -- void $ get GL.errors