Skip to content

Instantly share code, notes, and snippets.

@lian
Created September 25, 2013 21:47
Show Gist options
  • Select an option

  • Save lian/6706544 to your computer and use it in GitHub Desktop.

Select an option

Save lian/6706544 to your computer and use it in GitHub Desktop.
class Mesh
# ...
def draw
@meshes.each.with_index{|(vao, gl_type, faces_count),mesh_index|
GL.glBindTexture(GL::GL_TEXTURE_2D, @tex_ids[mesh_index]) if @tex_ids[mesh_index]
GL.glBindVertexArray(vao)
GL.glDrawElements(gl_type, faces_count, GL::GL_UNSIGNED_SHORT, 0)
}
end
# ...
end
w.draw_callback = proc{
GL.glClearColor(0.0, 0.0, 0.0, 0.0)
GL.glClearDepth(1.0)
GL.glClear(GL::GL_COLOR_BUFFER_BIT | GL::GL_DEPTH_BUFFER_BIT)
camera_matrix = MatrixStack.new( camera.look_at_matrix )
program.use{
GL.glUniformMatrix4fv(program.uniform_location('worldToCameraMatrix'), 1, GL::GL_FALSE, camera_matrix.top_pointer)
meshes.each{|mesh|
GL.glUniformMatrix4fv(program.uniform_location('modelToWorldMatrix'), 1, GL::GL_FALSE, mesh.model_matrix_pointer)
mesh.draw
}
}
w.swap_buffers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment