diff --git a/src/loader.cpp b/src/loader.cpp index 4845eee..224f8fb 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -28,7 +28,14 @@ Obj load_obj(const std::string& filename) { sscanf(line.c_str() + 2, "%f %f %f", &obj.vertices[(obj.vertex_count - 1) * 3], &obj.vertices[(obj.vertex_count - 1) * 3 + 1], &obj.vertices[(obj.vertex_count - 1) * 3 + 2]); } else if (line.substr(0, 2) == "f ") { // Face indices - unsigned int index1, + // f 2/1 3/2 1/3 + unsigned int index1, texture1, index2, texture2, index3, texture3; + sscanf(line.c_str() + 2, "%u/%u %u/%u %u/%u", &index1, &texture1, &index2, &texture2, &index3, &texture3); + obj.index_count += 3; + obj.indices = (unsigned int*)realloc(obj.indices, obj.index_count * sizeof(unsigned int)); + obj.indices[obj.index_count - 3] = index1 - 1; // OBJ indices are 1-based + obj.indices[obj.index_count - 2] = index2 - 1; + obj.indices[obj.index_count - 1] = index3 - 1; } else if (line.substr(0, 2) == "vn") { // Vertex normal obj.normal_count++; diff --git a/src/main.cpp b/src/main.cpp index e9029bf..55909f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) { init(); // Load shader program - Shader shader_program("shaders/triangle_untextured.vert", "shaders/triangle_untextured.frag"); + Shader shader_program("shaders/triangle.vert", "shaders/triangle.frag"); // Generate and set up textures Texture texture1("assets/crate.jpg");