Hello
I’ve recently started to use open gl and I’ve been expericing a few difficulties to get into into. I’m “playing around” with some .obj and .mtl loaders. I want to load them to my screen and apply them some transformations like lightning, textures and stuff like that using shaders and so on.
I can load a few objs correctly, like the models from hammer and pawn, they have the right shape etc, but models that have more faces don’t look good. I can load them but then look flateneed. I’ve been loading pencil or archer and they just don’t look good.
Also, I don’t understand how can apply to the hammer 2 different textures. For example, I want the cable to have a texture, but I want the head to have another.
For now I’m creating 3 buffers, one with the vertices faces, one with the textures and one with the normals and then I’m loading them all. I can share some pieces of my code, but here it is my loadObj:
// make and bind the VAO
glGenVertexArrays(1, &gVAO);
glBindVertexArray(gVAO);
// make and bind the VBO
glGenBuffers(1, &gVBO);
glBindBuffer(GL_ARRAY_BUFFER, gVBO);
glBufferData(GL_ARRAY_BUFFER, f.vertices.size() *sizeof(glm::vec3), &f.vertices[0], GL_STATIC_DRAW);
// connect the xyz to the "vert" attribute of the vertex shader
glEnableVertexAttribArray(gProgram->attrib("vert"));
glVertexAttribPointer(gProgram->attrib("vert"), 3, GL_FLOAT, GL_FALSE, 0, NULL);
GLuint texturesVerts;
glGenBuffers(1, &texturesVerts);
glBindBuffer(GL_ARRAY_BUFFER, texturesVerts);
glBufferData(GL_ARRAY_BUFFER, f.textures.size() *sizeof(TextureC), &f.textures[0], GL_STATIC_DRAW);
// connect the uv coords to the "vertTexCoord" attribute of the vertex shader
glEnableVertexAttribArray(gProgram->attrib("vertTexCoord"));
//glVertexAttribPointer(gProgram->attrib("vertTexCoord"), 2, GL_FLOAT, GL_TRUE, 5 * sizeof(GLfloat), (const GLvoid*)(3 * sizeof(GLfloat)));
glVertexAttribPointer(gProgram->attrib("vertTexCoord"), 2, GL_FLOAT, GL_FALSE, 0, NULL);
GLuint normalbuffer;
glGenBuffers(1, &normalbuffer);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glBufferData(GL_ARRAY_BUFFER, f.normals.size() *sizeof(Normal), &f.normals[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(gProgram->attrib("vertNormal"));
glVertexAttribPointer(gProgram->attrib("vertNormal"), 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
// unbind the VAO
glBindVertexArray(0);
my “F” has 5 vectores. One with all the faces with their vertices, textures and normals separated by materials. One with all the materials separated by name. One with all the vertices, other with all the textures and other will all the normals.
Any help would be very welcome. Thank you in advance.