From 93d9412ba7b4386e5bb5bb600b46d72385152c0e Mon Sep 17 00:00:00 2001 From: Joey de Vries Date: Mon, 3 Oct 2016 18:23:35 +0200 Subject: [PATCH] Asteroid instancing example bugfix. --- README.md | 2 ++ .../10.instancing/instancing_asteroids_instanced.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5db32f2..2ebc133 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ All relevant libraries are found in /libs and all DLLs found in /dlls (pre-)comp The CMake script knows where to find the libraries so just run CMake script and generate project of choice. Note that you still have to manually copy the required .DLL files from the /dlls folder to your binary folder for the binaries to run. +Keep in mind the supplied libraries were generated with a specific compiler version which may or may not work on your system (generating la large batch of link errors). In that case it's advised to build the libraries yourself from the source. + ## Linux building First make sure you have CMake, Git, and GCC by typing as root (sudo) `apt-get install g++ cmake git` and then get the required packages: Using root (sudo) and type `apt-get install libsoil-dev libglm-dev libassimp-dev libglew-dev libglfw3-dev` . Next, run CMake (preferably CMake-gui). The source directory is LearnOpenGL and specify the build directory as LearnOpenGL/build. Creating the build directory within LearnOpenGL is important for linking to the resource files (it also will be ignored by Git). Hit configure and specify your compiler files (Unix Makefiles are recommended), resolve any missing directories or libraries, and then hit generate. Navigate to the build directory (`cd LearnOpenGL/build`) and type `make` in the terminal. This should generate the executables in the respective chapter folders. diff --git a/src/4.advanced_opengl/10.instancing/instancing_asteroids_instanced.cpp b/src/4.advanced_opengl/10.instancing/instancing_asteroids_instanced.cpp index 8c242bf..edfd731 100644 --- a/src/4.advanced_opengl/10.instancing/instancing_asteroids_instanced.cpp +++ b/src/4.advanced_opengl/10.instancing/instancing_asteroids_instanced.cpp @@ -112,17 +112,19 @@ int main() modelMatrices[i] = model; } + // forward declare the buffer + GLuint buffer; + glGenBuffers(1, &buffer); + glBindBuffer(GL_ARRAY_BUFFER, buffer); + glBufferData(GL_ARRAY_BUFFER, amount * sizeof(glm::mat4), &modelMatrices[0], GL_STATIC_DRAW); + // Set transformation matrices as an instance vertex attribute (with divisor 1) // NOTE: We're cheating a little by taking the, now publicly declared, VAO of the model's mesh(es) and adding new vertexAttribPointers // Normally you'd want to do this in a more organized fashion, but for learning purposes this will do. for(GLuint i = 0; i < rock.meshes.size(); i++) { GLuint VAO = rock.meshes[i].VAO; - GLuint buffer; glBindVertexArray(VAO); - glGenBuffers(1, &buffer); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glBufferData(GL_ARRAY_BUFFER, amount * sizeof(glm::mat4), &modelMatrices[0], GL_STATIC_DRAW); // Set attribute pointers for matrix (4 times vec4) glEnableVertexAttribArray(3); glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)0);