Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active June 7, 2016 19:46
Show Gist options
  • Save pervognsen/93722d8a29e19171848ab51dfaafeb95 to your computer and use it in GitHub Desktop.
Save pervognsen/93722d8a29e19171848ab51dfaafeb95 to your computer and use it in GitHub Desktop.
void DrawMesh(Gob_Mesh *mesh) {
glVertexPointer(3, GL_FLOAT, mesh->positions.stride, GOB_BUFFER(mesh->positions.buffer)->data + mesh->positions.start);
char *index_buffer = GOB_BUFFER(mesh->indices.buffer)->data;
uint8_t index_size = mesh->indices.index_size;
GLenum index_type = (index_size == 2) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
for (size_t i = 0; i < mesh->sections_count; i++) {
glDrawElements(GL_TRIANGLES, mesh->sections[i].index_count, index_type, index_buffer + index_size * mesh->sections[i].index_start);
}
}
void DrawNode(Gob_Node *node) {
glPushMatrix();
float matrix[4][4];
ConvertTransformToMatrix(matrix, &node->transform);
glMultMatrixf((float *)matrix);
if (node->kind == GOB_MESH_NODE) {
DrawMesh(GOB_MESH(node->mesh));
}
for (size_t i = 0; i < node->children_count; i++) {
DrawNode(GOB_NODE(node->children[i]));
}
glPopMatrix();
}
void DrawScene(Gob_Scene *scene) {
DrawNode(GOB_NODE(scene->root));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment