Created
November 14, 2012 01:21
-
-
Save Shaptic/4069619 to your computer and use it in GitHub Desktop.
Rendering meshes in a scene.
This file contains hidden or 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
void CScene::Render() | |
{ | |
// Model-view identity matrix, to be loaded later. | |
static math::matrix4x4_t MVMatrix = math::IDENTITY; | |
// Offload vertex data onto the GPU if it has not been done yet. | |
if(!m_GeometryVBO.Finalized()) m_GeometryVBO.FinalizeBuffer(); | |
// Bind VBO that contains the mesh vertex data. | |
m_GeometryVBO.Bind(); | |
// Render all of the meshes. | |
for(size_t i = 0; i < m_meshInstances.size(); ++i) | |
{ | |
// Load the model-view matrix. | |
m_meshInstances[i]->LoadPositionMatrix(MVMatrix); | |
// Render the mesh. | |
this->RenderMesh(m_meshInstances[i], MVMatrix); | |
} | |
} | |
void CScene::RenderMesh(gfx::CMeshInstance* pMesh, const math::matrix4x4_t& ModelView) | |
{ | |
// Bind the texture for rendering. | |
pMesh->BindTexture(); | |
// Use the default shader for basic transformations. | |
m_DefaultShader.Bind(); | |
// Pass the model-view matrix, loaded with position data, | |
// to the shader. | |
// SInce the matrix4x4_t class is row-major, it is necessary | |
// to pass GL_TRUE so transposing occurs. | |
glUniformMatrix4fv(m_mvloc, 1, GL_TRUE, ModelView.GetMatrixPointer()); | |
// Do rendering. This is normally a call to glDrawElements when working | |
// with both an index and vertex buffer in the VBO (as is the case in IronClad). | |
pMesh->Render(); | |
// Unbind shader and texture. | |
pMesh->UnbindTexture(); | |
m_DefaultShader.Unbind(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment