Skip to content

Instantly share code, notes, and snippets.

@zao
Created October 29, 2012 18:19
Show Gist options
  • Save zao/3975450 to your computer and use it in GitHub Desktop.
Save zao/3975450 to your computer and use it in GitHub Desktop.
Render function
void DrawGame()
{
double const t = glfwGetTime();
glUseProgram(tileProgram);
BindStreams(tileCoord->vbs, tileCoord->bindings);
geom::ShaderLocations::Semantic semantics[] = {
geom::MakeSemantic("MODEL"),
geom::MakeSemantic("VIEW"),
geom::MakeSemantic("PROJECTION"),
geom::MakeSemantic("DIFFUSE"),
geom::MakeSemantic("SELECTED"),
};
glUniformMatrix4fv(tileUniformLocs.mapping[semantics[1]], 1, GL_FALSE, glm::value_ptr(viewMatrix));
glUniformMatrix4fv(tileUniformLocs.mapping[semantics[2]], 1, GL_FALSE, glm::value_ptr(projectionMatrix));
std::deque<std::pair<glm::mat4, boost::shared_ptr<geom::ResolvedMesh>>> drawables;
BOOST_FOREACH(auto xfp, tiles.transforms)
{
drawables.push_back(std::make_pair(xfp.second, tileCoord));
}
BOOST_FOREACH(auto xfp, drawables)
{
glm::mat4 tileWorld = xfp.first;
auto entity = xfp.second;
int tileCoord;
glUniformMatrix4fv(tileUniformLocs.mapping[semantics[0]], 1, GL_FALSE, glm::value_ptr(tileWorld));
glUniform1ui(tileUniformLocs.mapping[semantics[3]], 0);
glBindSampler(0, clampBilinearSampler);
BOOST_FOREACH(geom::Object obj, entity->objects)
{
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, textures[obj.material]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *entity->ib);
glDrawElements(GL_TRIANGLES, obj.primitiveCount*3, GL_UNSIGNED_INT, (GLvoid const*)(obj.offset*4));
}
}
UnbindStreams(tileCoord->bindings);
glUseProgram(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment