Created
January 20, 2016 00:20
-
-
Save BGR360/b9b3bdaa01f3dab012f9 to your computer and use it in GitHub Desktop.
Excerpt from MeshRenderer.cpp from my 3D C++ game engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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