Skip to content

Instantly share code, notes, and snippets.

@BGR360
Created January 20, 2016 00:20
Show Gist options
  • Save BGR360/b9b3bdaa01f3dab012f9 to your computer and use it in GitHub Desktop.
Save BGR360/b9b3bdaa01f3dab012f9 to your computer and use it in GitHub Desktop.
Excerpt from MeshRenderer.cpp from my 3D C++ game engine
//THIS is where aaalll the magic happens.
void MeshRenderer::render()
{
ShaderProgram* shader = m_material->getShader();
//Update the "modelMatrix" uniform
string modelMatrixStr("modelMatrix");
if (!shader->hasUniform(modelMatrixStr))
{
//throw BengineException("The compiled shader is missing uniform 'modelMatrix'.");
}
else
{
shader->setUniform(
"modelMatrix",
getGameObject()->getTransform()->toModelMatrix());
}
//Bind the material
m_material->bind();
//Bind the Vertex Array
GLuint vao = m_mesh->getVAO();
glBindVertexArray(vao);
//DrawElements
glDrawElements(
GL_TRIANGLES,
m_mesh->getIndices().size(),
GL_UNSIGNED_INT,
0);
//Unbind the Vertex Array
glBindVertexArray(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment