diff --git a/Makefile b/Makefile index 7058113..df2af7a 100644 --- a/Makefile +++ b/Makefile @@ -30,5 +30,6 @@ examples: $(LIBNAME) .PHONY: examples clean: - rm -rf $(OBJDIR)/* bin/* + rm -rf $(OBJDIR)/* + $(MAKE) clean -C $(EXAMPLEDIR) .PHONY: clean diff --git a/src/mesh.cpp b/src/mesh.cpp index 6fd68c2..7e6f14b 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -15,7 +15,7 @@ // forward declarations void assimpLogCB(const char* message, char* user); -meMeshInfo* allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has_texture); +meMeshInfo* allocateMeshInfo(uint num_vertices, uint num_indices); void freeMesh(meMeshInfo* mesh); inline glm::vec3 copyVector(aiVector3D v_in, glm::vec3& v_out); meMeshInfo* copyMeshInfo(const aiScene* scene, aiMesh* mesh); @@ -96,7 +96,7 @@ assimpLogCB(const char* message, char* user) } meMeshInfo* -allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has_texture) +allocateMeshInfo(uint num_vertices, uint num_indices) { meMeshInfo* mi = UTIL_ALLOC(1, meMeshInfo); mi->model_transform = glm::mat4(1); @@ -106,8 +106,8 @@ allocateMeshInfo(uint num_vertices, uint num_indices, bool has_normals, bool has mi->vertices = UTIL_ALLOC(mi->num_vertices, glm::vec3); mi->num_indices = num_indices; mi->indices = UTIL_ALLOC(num_indices, uint); - if (has_normals) mi->normals = UTIL_ALLOC(mi->num_vertices, glm::vec3); - if (has_texture) mi->texture_coords = UTIL_ALLOC(mi->num_vertices, glm::vec3); + mi->normals = UTIL_ALLOC(mi->num_vertices, glm::vec3); + mi->texture_coords = UTIL_ALLOC(mi->num_vertices, glm::vec3); return mi; } @@ -169,21 +169,15 @@ loadDiffuseTexture(const aiScene* scene, aiMesh* mesh, meMeshInfo* mi) meMeshInfo* copyMeshInfo(const aiScene* scene, aiMesh* mesh) { - bool has_tex = mesh->HasTextureCoords(0); - bool has_normals = mesh->HasNormals(); - meMeshInfo* mi = allocateMeshInfo(mesh->mNumVertices, mesh->mNumFaces * 3, has_normals, has_tex); + meMeshInfo* mi = allocateMeshInfo(mesh->mNumVertices, mesh->mNumFaces * 3); // copy vertices, normals, and texture coords for (uint i = 0; i < mi->num_vertices; i++) { copyVector(mesh->mVertices[i], mi->vertices[i]); - - if (has_normals) - copyVector(mesh->mNormals[i], mi->normals[i]); - - if (has_tex) { - mi->texture_coords[i].x = mesh->mTextureCoords[0][i].x; - mi->texture_coords[i].y = mesh->mTextureCoords[0][i].y; - } + copyVector(mesh->mNormals[i], mi->normals[i]); + mi->texture_coords[i].x = mesh->mTextureCoords[0][i].x; + mi->texture_coords[i].y = mesh->mTextureCoords[0][i].y; + mi->texture_coords[i].z = 0; } // copy indices diff --git a/src/render_object.cpp b/src/render_object.cpp index dcaef6f..6fd66bb 100644 --- a/src/render_object.cpp +++ b/src/render_object.cpp @@ -108,6 +108,8 @@ roDraw(render_object& ro, // TODO: could pass in a stride parameter here to enableGLFloatBuffer() // could then use a 2d buffer for uv coords enableGLFloatBuffer(ro.uv_buffer_id, 2); + glBindTexture(GL_TEXTURE_2D, ro.tex_id); + glUniform1i(shader.sampler_id, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ro.index_buffer_id); glDrawElements(GL_TRIANGLES, ro.index_buffer_count, GL_UNSIGNED_INT, 0);