Let me preface this by saying I’m fairly new at OpenGL ES and OpenGL in general.
I’ve got a model object that our 3D guy exported from zBrush. It doesn’t have any normals in the .obj
file, and I think that’s what’s causing this behavior. I’m using obj2opengl to create a .h
file containing the vertices and texture coordinates, then importing those and rendering. Here’s what the import looks like:
glGenBuffers(1, &mushroomVertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, mushroomVertexBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(mushroom01b_LowVerts), mushroom01b_LowVerts, GL_STATIC_DRAW);
glGenBuffers(1, &mushroomTextureBufferID);
glBindBuffer(GL_ARRAY_BUFFER, mushroomTextureBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(mushroom01b_LowTexCoords), mushroom01b_LowTexCoords, GL_STATIC_DRAW);
When it’s time to draw the object, here’s the code I’m using:
glBindBuffer(GL_ARRAY_BUFFER, mushroomVertexBufferID);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, NULL);
glBindBuffer(GL_ARRAY_BUFFER, mushroomTextureBufferID);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, NULL);
self.effect.texture2d0.name = _mushroomTextureInfo.name;
self.effect.texture2d0.target = _mushroomTextureInfo.target;
[self.effect prepareToDraw];
glDrawArrays(GL_TRIANGLES, 0, mushroom01b_LowNumVerts);
This works, and for models where I’ve opened them in Blender, fixed the normals, and re-exported as OBJ with normals (adding code above for a third array buffer), it looks pretty good. But if I don’t modify the exported-from-zBrush OBJ at all, here’s what I get:
Now, this is with face culling enabled with glEnable(GL_CULL_FACE);
. If I don’t enable it, the model seems to be rendering inside-out.
Clearly the zBrush export is messed up somehow. My question is how to fix it.