Index: new-game.cpp
===================================================================
--- new-game.cpp	(revision 0e0f851a9c036c86fd7761ec28ab1b72e823161f)
+++ new-game.cpp	(revision 25b47d78111d993d43913eb57cfe056b67e70164)
@@ -142,6 +142,6 @@
                   GLuint normals_vbo,
                   GLuint ubo,
-                  GLuint asteroid_hp_ubo,
-                  GLuint model_mat_idx_vbo);
+                  GLuint model_mat_idx_vbo,
+                  GLuint asteroid_sp);
 void removeObjectFromScene(SceneObject& obj, GLuint ubo);
 
@@ -155,5 +155,4 @@
                   GLuint* normals_vbo,
                   GLuint* ubo,
-                  GLuint* asteroid_hp_ubo,
                   GLuint* model_mat_idx_vbo);
 
@@ -166,6 +165,6 @@
                   GLuint normals_vbo,
                   GLuint ubo,
-                  GLuint asteroid_hp_ubo,
-                  GLuint model_mat_idx_vbo);
+                  GLuint model_mat_idx_vbo,
+                  GLuint asteroid_sp);
 
 void copyObjectDataToBuffers(SceneObject& obj,
@@ -177,6 +176,6 @@
                   GLuint normals_vbo,
                   GLuint ubo,
-                  GLuint asteroid_hp_ubo,
-                  GLuint model_mat_idx_vbo);
+                  GLuint model_mat_idx_vbo,
+                  GLuint asteroid_sp);
 
 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo);
@@ -187,5 +186,5 @@
 
 void translateLaser(Laser* laser, const vec3& translation, GLuint ubo);
-void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp, GLuint asteroid_hp_loc);
+void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp);
 bool getLaserAndAsteroidIntersection(vec3& start, vec3& end, SceneObject& asteroid, vec3& intersection);
 
@@ -452,7 +451,6 @@
 
    GLuint points_vbo, colors_vbo, selected_colors_vbo, texcoords_vbo,
-      normals_vbo, ubo, asteroid_hp_ubo, model_mat_idx_vbo;
-
-   cout << "Initializing buffers" << endl;
+      normals_vbo, ubo, model_mat_idx_vbo;
+
    initializeBuffers(
       &points_vbo,
@@ -462,8 +460,6 @@
       &normals_vbo,
       &ubo,
-      &asteroid_hp_ubo,
       &model_mat_idx_vbo);
 
-   cout << "Populating buffers" << endl;
    populateBuffers(objects,
       shaderBufferInfo,
@@ -474,8 +470,6 @@
       normals_vbo,
       ubo,
-      asteroid_hp_ubo,
-      model_mat_idx_vbo);
-
-   cout << "Done" << endl;
+      model_mat_idx_vbo,
+      asteroid_sp);
 
    GLuint color_vao = 0;
@@ -601,5 +595,4 @@
    GLuint asteroid_view_mat_loc = glGetUniformLocation(asteroid_sp, "view");
    GLuint asteroid_proj_mat_loc = glGetUniformLocation(asteroid_sp, "proj");
-   GLuint asteroid_hp_loc = glGetUniformLocation(asteroid_sp, "hp");
    GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(asteroid_sp, "models");
    //GLuint asteroid_sp_hp_ub_index = glGetUniformBlockIndex(asteroid_sp, "hp_uniform");
@@ -623,19 +616,11 @@
 
 
-   GLfloat tempHp = 10.0f;
-   mat4 hp(tempHp);
-
    glUseProgram(asteroid_sp);
    glUniformMatrix4fv(asteroid_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat));
    glUniformMatrix4fv(asteroid_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat));
-   glUniformMatrix4fv(asteroid_hp_loc, 1, GL_FALSE, value_ptr(hp));
 
    glUniformBlockBinding(asteroid_sp, asteroid_sp_models_ub_index, ub_binding_point);
    glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);
 
-   /*
-   glUniformBlockBinding(asteroid_sp, asteroid_sp_hp_ub_index, ub_binding_point);
-   glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, asteroid_hp_ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);
-   */
 
    glUseProgram(texture_sp);
@@ -725,6 +710,6 @@
                normals_vbo,
                ubo,
-               asteroid_hp_ubo,
-               model_mat_idx_vbo);
+               model_mat_idx_vbo,
+               asteroid_sp);
 
             elapsed_seconds_spawn -= 0.5f;
@@ -785,6 +770,6 @@
                normals_vbo,
                ubo,
-               asteroid_hp_ubo,
-               model_mat_idx_vbo);
+               model_mat_idx_vbo,
+               asteroid_sp);
          } else if (key_state[GLFW_KEY_Z] == GLFW_RELEASE) {
             removeObjectFromScene(*leftLaser, ubo);
@@ -803,6 +788,6 @@
                normals_vbo,
                ubo,
-               asteroid_hp_ubo,
-               model_mat_idx_vbo);
+               model_mat_idx_vbo,
+               asteroid_sp);
          } else if (key_state[GLFW_KEY_X] == GLFW_RELEASE) {
             removeObjectFromScene(*rightLaser, ubo);
@@ -826,8 +811,8 @@
 
          if (leftLaser != NULL && !leftLaser->deleted) {
-            updateLaserTarget(leftLaser, objects, points_vbo, asteroid_sp, asteroid_hp_loc);
+            updateLaserTarget(leftLaser, objects, points_vbo, asteroid_sp);
          }
          if (rightLaser != NULL && !rightLaser->deleted) {
-            updateLaserTarget(rightLaser, objects, points_vbo, asteroid_sp, asteroid_hp_loc);
+            updateLaserTarget(rightLaser, objects, points_vbo, asteroid_sp);
          }
       }
@@ -1287,6 +1272,6 @@
    GLuint normals_vbo,
    GLuint ubo,
-   GLuint asteroid_hp_ubo,
-   GLuint model_mat_idx_vbo) {
+   GLuint model_mat_idx_vbo,
+   GLuint asteroid_sp) {
    objects.push_back(obj);
 
@@ -1312,6 +1297,6 @@
          normals_vbo,
          ubo,
-         asteroid_hp_ubo,
-         model_mat_idx_vbo);
+         model_mat_idx_vbo,
+         asteroid_sp);
    } else {
       copyObjectDataToBuffers(*objects.back(), shaderBufferInfo,
@@ -1322,6 +1307,6 @@
          normals_vbo,
          ubo,
-         asteroid_hp_ubo,
-         model_mat_idx_vbo);
+         model_mat_idx_vbo,
+         asteroid_sp);
    }
 }
@@ -1873,5 +1858,4 @@
                   GLuint* normals_vbo,
                   GLuint* ubo,
-                  GLuint* asteroid_hp_ubo,
                   GLuint* model_mat_idx_vbo) {
    *points_vbo = 0;
@@ -1892,7 +1876,4 @@
    *ubo = 0;
    glGenBuffers(1, ubo);
-
-   *asteroid_hp_ubo = 0;
-   glGenBuffers(1, asteroid_hp_ubo);
 
    *model_mat_idx_vbo = 0;
@@ -1908,6 +1889,6 @@
                   GLuint normals_vbo,
                   GLuint ubo,
-                  GLuint asteroid_hp_ubo,
-                  GLuint ubo_idx_vbo) {
+                  GLuint ubo_idx_vbo,
+                  GLuint asteroid_sp) {
    GLsizeiptr num_points = 0;
    GLsizeiptr num_objects = 0;
@@ -2003,9 +1984,4 @@
    glBufferData(GL_UNIFORM_BUFFER, num_objects * sizeof(mat4), NULL, GL_DYNAMIC_DRAW);
 
-   /*
-   glBindBuffer(GL_UNIFORM_BUFFER, asteroid_hp_ubo);
-   glBufferData(GL_UNIFORM_BUFFER, num_objects * sizeof(mat4), NULL, GL_DYNAMIC_DRAW);
-   */
-
    glBindBuffer(GL_ARRAY_BUFFER, ubo_idx_vbo);
    glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW);
@@ -2019,6 +1995,6 @@
          normals_vbo,
          ubo,
-         asteroid_hp_ubo,
-         ubo_idx_vbo);
+         ubo_idx_vbo,
+         asteroid_sp);
    }
 }
@@ -2032,6 +2008,6 @@
                   GLuint normals_vbo,
                   GLuint ubo,
-                  GLuint asteroid_hp_ubo,
-                  GLuint model_mat_idx_vbo) {
+                  GLuint model_mat_idx_vbo,
+                  GLuint asteroid_sp) {
    BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program];
 
@@ -2065,12 +2041,11 @@
    glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat));
 
-   /*
-   //if (obj.type == TYPE_ASTEROID) {
-      glBindBuffer(GL_UNIFORM_BUFFER, asteroid_hp_ubo);
-      GLfloat tempHp = 0.1f; // this value has no impact on the actual color, wtf
-      mat4 tempMat(tempHp);
-      glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(tempMat));
-   //}
-   */
+   if (obj.type == TYPE_ASTEROID) {
+      glUseProgram(asteroid_sp);
+
+      ostringstream oss;
+      oss << "hp[" << obj.ubo_offset << "]";
+      glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp);
+   }
 
    bufferInfo->vbo_offset += obj.num_points;
@@ -2121,5 +2096,5 @@
 }
 
-void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp, GLuint asteroid_hp_loc) {
+void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp) {
    // TODO: A lot of the values calculated here can be calculated once and saved when the laser is created,
    // and then re-used here
@@ -2156,5 +2131,5 @@
 
       if (closestAsteroid != NULL) {
-         eot = new EffectOverTime(closestAsteroid->hp, -10.0f, closestAsteroid);
+         eot = new EffectOverTime(closestAsteroid->hp, -20.0f, closestAsteroid);
          effects.push_back(eot);
       }
@@ -2172,11 +2147,11 @@
       length = glm::length(closestIntersection - start);
 
-      // TODO: Find a better way of doing this
-
-      GLfloat tempHp = closestAsteroid->hp;
-      mat4 hp(tempHp);
+      // TODO: Find a more generic way of updating the laser hp than in updateLaserTarget
 
       glUseProgram(asteroid_sp);
-      glUniformMatrix4fv(asteroid_hp_loc, 1, GL_FALSE, value_ptr(hp));
+
+      ostringstream oss;
+      oss << "hp[" << closestAsteroid->ubo_offset << "]";
+      glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), closestAsteroid->hp);
    }
 
@@ -2436,50 +2411,50 @@
    obj->colors = {
       // front
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
 
       // top
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
 
       // bottom
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
 
       // back
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
 
       // right
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
 
       // left
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
-      0.8f, 0.0f, 0.0f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
+      0.4f, 0.4f, 0.4f,
    };
    obj->texcoords = { 0.0f };
