Index: new-game.cpp
===================================================================
--- new-game.cpp	(revision df652d5289289364aaa3a6d68ef5c3c7d339b37b)
+++ new-game.cpp	(revision 147ac6d98bbce1abca735e47d994310e71b0bf00)
@@ -28,5 +28,4 @@
 struct SceneObject {
    mat4 model_mat;
-   bool clicked;
 };
 
@@ -42,6 +41,4 @@
 vec3 cam_pos;
 
-int colors_i = 0;
-
 mat4 view_mat;
 mat4 proj_mat;
@@ -49,4 +46,7 @@
 vector<SceneObject> objects;
 vector<ObjectFace> faces;
+
+SceneObject* clickedObject = NULL;
+SceneObject* selectedObject = NULL;
 
 bool insideTriangle(vec3 p, ObjectFace* face);
@@ -198,4 +198,5 @@
    if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
       cout << "Mouse clicked (" << mouse_x << "," << mouse_y << ")" << endl;
+      selectedObject = NULL;
 
       float x = (2.0f*mouse_x) / width - 1.0f;
@@ -273,6 +274,8 @@
       printVector("Intersection", intersection);
 
-      obj->clicked = insideTriangle(intersection, face);
-      cout << (obj->clicked ? "true" : "false") << endl;
+      if (insideTriangle(intersection, face)) {
+         clickedObject = obj;
+      }
+      cout << (obj == clickedObject ? "true" : "false") << endl;
    }
 }
@@ -429,5 +432,4 @@
    // triangle
    objects.push_back(SceneObject());
-   objects[0].clicked = false;
 
    /*
@@ -448,5 +450,4 @@
    // square
    objects.push_back(SceneObject());
-   objects[1].clicked = false;
 
    // mat4 T_model2 = translate(mat4(), vec3(-1.0f, 0.0f, 0.0f));
@@ -596,14 +597,15 @@
       }
 
-      if (objects[0].clicked) {
-         glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
-
-         if (colors_i == 0) {
-            glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW);
-            colors_i = 1;
-         } else {
-            glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
-            colors_i = 0;
-         }
+      if (clickedObject == &objects[0]) {
+         selectedObject = &objects[0];
+      }
+
+      // At some point, I should change this to only rebind the buffer once per click, not once per frame
+      glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
+      if (selectedObject == &objects[0]) {
+         glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW);
+      }
+      else {
+         glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
       }
 
@@ -625,9 +627,10 @@
       glDrawArrays(GL_TRIANGLES, 0, numPoints);
 
-      if (objects[1].clicked) {
+      if (clickedObject == &objects[1]) {
          squareSelected = !squareSelected;
-      }
-
-      if (squareSelected) {
+         selectedObject = &objects[1];
+      }
+
+      if (selectedObject == &objects[1]) {
          glUseProgram(shader_program);
 
@@ -651,7 +654,5 @@
       glDrawArrays(GL_TRIANGLES, 0, numPoints2);
 
-      for (vector<SceneObject>::iterator it = objects.begin(); it != objects.end(); it++) {
-         it->clicked = false;
-      }
+      clickedObject = NULL;
 
       glfwPollEvents();
