I made a parser for OBJ file and the oject is displayed correctly ( also tryed w but the texture is not applied correctly at all.
I read documents about how it needs to be done and watched videos but I can’t seem to get it working.
I use vectors and GLM to store data in vec2 and vec3 and GLuint for indices.
After reading the vertecies, texture coordinates and normals I use the function below to arrenge vertices with normals and texture coordinates.
void Obj::addIndices(std::string src, const std::vector<glm::vec3> &temp_vertices, const std::vector<glm::vec2> &temp_textureCoords, const std::vector<glm::vec3> &temp_normals, std::vector<glm::vec3> &vertices, std::vector<glm::vec2> &textureCoords, std::vector<glm::vec3> &normals, std::vector<GLuint> &indices)
{
GLfloat v1, v2, v3, t1, t2, t3, n1, n2, n3;
std::string scanStr = "f %f/%f/%f %f/%f/%f %f/%f/%f";
sscanf_s(src.c_str(), scanStr.c_str(), &v1, &t1, &n1, &v2, &t2, &n2, &v3, &t3, &n3);
v1--; v2--; v3--;
t1--; t2--; t3--;
n1--; n2--; n3--;
GLuint index = indices.size();
indices.push_back(index);
vertices.push_back(temp_vertices[v1]);
textureCoords.push_back(temp_textureCoords[t1]);
normals.push_back(temp_normals[n1]);
index = indices.size();
indices.push_back(index);
vertices.push_back(temp_vertices[v2]);
textureCoords.push_back(temp_textureCoords[t2]);
normals.push_back(temp_normals[n2]);
index = indices.size();
indices.push_back(index);
vertices.push_back(temp_vertices[v3]);
textureCoords.push_back(temp_textureCoords[t3]);
normals.push_back(temp_normals[n3]);
}
This is how it looks:
[ATTACH=CONFIG]1152[/ATTACH]
This is how it should look:
[ATTACH=CONFIG]1153[/ATTACH]