Closed somerandompiggo closed 9 months ago
Not really sure, but you might get something like that if you passed GL_UNSIGNED_SHORT
to glDrawElements
rather than GL_UNSIGNED_INT
. fastObjMesh::positions[0]
is a vertex at (0, 0, 0) - all valid indices are 1 based so it's never actually referenced, but if you got the size wrong to the glDrawElements
call GL would see lots of 0 indices and might give you something like you describe. Hopefully give you something to look for anyway...
Had another crack at it, no luck so far. Here is a more complete snippet, I hope it helps since my last one was really minimal
Initialization:
fastObjMesh* objmesh = fast_obj_read(path);
if (objmesh == NULL) {
printf("Error loading OBJ file with path: %s\n", path);
return;
}
mesh->count = objmesh->index_count;
glGenVertexArrays(1, &mesh->VAO);
glBindVertexArray(mesh->VAO);
glGenBuffers(1, &mesh->VBO);
glBindBuffer(GL_ARRAY_BUFFER, mesh->VBO);
glBufferData(GL_ARRAY_BUFFER, objmesh->position_count * sizeof(float) * 3, objmesh->positions, GL_STATIC_DRAW);
glGenBuffers(1, &mesh->EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, objmesh->index_count * sizeof(unsigned int), objmesh->indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
Draw loop:
glBindVertexArray(mesh->VAO);
glDrawElements(GL_TRIANGLES, mesh->count, GL_UNSIGNED_INT, 0);
Sorry, wrote my own loader to test. Exact same result, not an issue with the library. Will edit this comment when I find a fix
I'm testing the library with a cube OBJ exported from Blender. It seems to load fine, but loading it into a VBO and EBO using this code doesn't work properly:
When drawing with GL_TRIANGLES, nothing is displayed but if I use GL_LINES they go out from the origin to the 8 vertices of the cube. I think it's an issue with the indices, but I've been trying for days and I can't seem to figure out why
(view from inside renderdoc)
Thanks!
cube.obj: