Strange black pixels on model
I tried to draw a model with 197 polygons but i have strange black pixels on it:
alt text http://i.imagehost.org/0398/IMG_0172.png
When I run the code in the iPhone Simulator, it shows well without those black pixels, but on the device I have that problem.
I set perspective:
const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 45.0;
GLfloat size;
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
CGRect rect = self.bounds;
glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / (rect.size.width / rect.size.height), zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glColor4f(0,0,0,0.5f);
glEnable(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnableClientState(GL_VERTEX_ARRAY);
And draw (model vertices, indexes and normals store in global arrays.):
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
[EAGLContext setCurrentContext:context];
glBindFramebuffe开发者_运维知识库rOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glTranslatef(1.0, -9, -22);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glDrawElements(GL_TRIANGLES, 3*192, GL_UNSIGNED_BYTE, icosahedronFaces);
glDisableClientState(GL_NORMAL_ARRAY);
glTranslatef(-1.0, 9, 22);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
This could be a depth precision issue where the back-facing polygons are poking through. Try increasing the value of zNear as much as possible without clipping your scene.
It looks like an issue with some of the normals not being exactly perpendicular to their respective surface.
Try applying your normals before you translate.
精彩评论