1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| void Model::DrawInstance(float x, float y, float z, glm::mat4 viewMatrix, glm::mat4 projectionMatrix, unsigned int instance) { glEnable(GL_DEPTH_TEST); mVertexBuffer->Bind(); glm::mat4 it = glm::inverseTranspose(mModelMatrix); mShader->SetVec4("U_CameraPos", x, y, z, 1.0f); mShader->Bind(glm::value_ptr(mModelMatrix), glm::value_ptr(viewMatrix), glm::value_ptr(projectionMatrix));
glUniformMatrix4fv(glGetUniformLocation(mShader->mProgram, "IT_ModelMatrix"), 1, GL_FALSE, glm::value_ptr(it)); mVertexBuffer->Unbind();
float posOffsets[] = { 0.01f,0.0f,0.0f,1.0f, 0.0f,0.0f,0.0f,1.0f, -0.01f,0.0f,0.0f,1.0f };
GLuint offsetVBO = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(float) * 12, GL_STATIC_DRAW, posOffsets); GLuint offsetLocation = glGetAttribLocation(mShader->mProgram, "offset"); glBindBuffer(GL_ARRAY_BUFFER, offsetVBO); glEnableVertexAttribArray(offsetLocation); glVertexAttribPointer(offsetLocation, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void*)0); glBindBuffer(GL_ARRAY_BUFFER, 0); glVertexAttribDivisor(offsetLocation, 1); glDrawArraysInstanced(GL_TRING, 0, mVertexBuffer->mVertexCount, instance);
mShader->Unbind(); }
|