Index: TODO.txt
===================================================================
--- TODO.txt	(revision 046ce72547fc2dc3475e5f7a3a5092e9544d4ae1)
+++ TODO.txt	(revision 1a530df0e4bd7623e792a480d86fe4339d9e78c6)
@@ -1,4 +1,9 @@
+DEBUGGING
+==========
+-Read the sections about shader debugging, starting from line 59
+-Change the background to gray in case my square is being rendered in black
+
 TODO
-=====
+==========
 -Change the logger class to use cout instead of printf. Consider how easy variable argument support would be.
 -Change all error messages to use the logger class so they get printed to the log file as well.
@@ -9,5 +14,5 @@
 
 DONE
-=====
+==========
 -Print a warning if texture images don't sizes of 2^x
 -Fix the texture-mapping code to not flip the texture upside down.
Index: color.vert
===================================================================
--- color.vert	(revision 046ce72547fc2dc3475e5f7a3a5092e9544d4ae1)
+++ color.vert	(revision 1a530df0e4bd7623e792a480d86fe4339d9e78c6)
@@ -1,3 +1,7 @@
 #version 410
+
+layout (std140) uniform model_block {
+   mat4 M;
+};
 
 uniform mat4 model, view, proj;
Index: new-game.cpp
===================================================================
--- new-game.cpp	(revision 046ce72547fc2dc3475e5f7a3a5092e9544d4ae1)
+++ new-game.cpp	(revision 1a530df0e4bd7623e792a480d86fe4339d9e78c6)
@@ -304,4 +304,14 @@
       vec3(points2[15], points2[16], points2[17]),
    };
+
+   int ubo_id = 0;
+   GLuint ubo = 0;
+   glGenBuffers(1, &ubo);
+   glBindBuffer(GL_UNIFORM_BUFFER, ubo);
+   glBufferData(GL_ARRAY_BUFFER, sizeof(float)*16*2, NULL, GL_STATIC_DRAW);
+
+   glBindBufferBase(GL_UNIFORM_BUFFER, ubo_id, ubo);
+   glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(float) * 16, value_ptr(objects[0].model_mat));
+   glBufferSubData(GL_UNIFORM_BUFFER, sizeof(float) * 16, sizeof(float) * 16, value_ptr(objects[1].model_mat));
 
    GLuint points_vbo = 0;
@@ -354,6 +364,43 @@
    glEnableVertexAttribArray(1);
 
+   // I can create a vbo to store all points for all models,
+   // and another vbo to store all colors for all models, but how do I allow alternating between
+   // using colors and textures for each model?
+   // Do I create a third vbo for texture coordinates and change which vertex attribute array I have bound
+   // when I want to draw a textured model?
+   // Or do I create one vao with vertices and colors and another with vertices and textures and switch between the two?
+   // Since I would have to switch shader programs to toggle between using colors or textures,
+   // I think I should use one vao for both cases and have a points vbo, a colors vbo, and a textures vbo
+   // One program will use the points and colors, and the other will use the points and texture coords
+   // Review how to bind vbos to vertex attributes in the shader.
+   //
+   // Binding vbos is done using glVertexAttribPointer(...) on a per-vao basis and is not tied to any specific shader.
+   // This means, I could create two vaos, one for each shader and have one use points+colors, while the other
+   // uses points+texxcoords.
+   //
+   // At some point, when I have lots of objects, I want to group them by shader when drawing them.
+   // I'd probably create some sort of set per shader and have each set contain the ids of all objects currently using that shader
+   // Most likely, I'd want to implement each set using a bit field. Makes it constant time for updates and iterating through them
+   // should not be much of an issue either.
+   // Assuming making lots of draw calls instead of one is not innefficient, I should be fine.
+   // I might also want to use one glDrawElements call per shader to draw multiple non-memory-adjacent models
+   //
+   // DECISION: Use a glDrawElements call per shader since I use a regular array to specify the elements to draw
+   // Actually, this will only work once I get UBOs working since each object will have a different model matrix
+   // For now, I could implement this with a glDrawElements call per object and update the model uniform for each object
+
    GLuint shader_program = loadShaderProgram("./color.vert", "./color.frag");
    GLuint shader_program2 = loadShaderProgram("./texture.vert", "./texture.frag");
+
+   GLuint ub_index = glGetUniformBlockIndex(shader_program, "model_block");
+   glUniformBlockBinding(shader_program, ub_index, ubo_id);
+
+   GLuint ub_index2 = glGetUniformBlockIndex(shader_program2, "model_block");
+   glUniformBlockBinding(shader_program2, ub_index2, ubo_id);
+
+   cout << "Uniform Buffer Debugging" << endl;
+   cout << "ubo: " << ubo << endl;
+   cout << "ub_index: " << ub_index << endl;
+   cout << "ub_index2: " << ub_index2 << endl;
 
    float speed = 1.0f;
@@ -403,8 +450,12 @@
    glUniformMatrix4fv(proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat));
 
+   glBindBufferRange(GL_UNIFORM_BUFFER, ub_index, ubo, 0, sizeof(float) * 16);
+
    glUseProgram(shader_program2);
    glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objects[1].model_mat));
    glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat));
    glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat));
+
+   glBindBufferRange(GL_UNIFORM_BUFFER, ub_index2, ubo, sizeof(float) * 16, sizeof(float) * 16);
 
    bool cam_moved = false;
Index: texture.vert
===================================================================
--- texture.vert	(revision 046ce72547fc2dc3475e5f7a3a5092e9544d4ae1)
+++ texture.vert	(revision 1a530df0e4bd7623e792a480d86fe4339d9e78c6)
@@ -1,3 +1,7 @@
 #version 410
+
+layout (std140) uniform model_block {
+   mat4 M;
+};
 
 uniform mat4 model, view, proj;
