开发者

surfaces got broken when object is far away in iphone

I am using the opengl es to display objects.

when the object is near to the camera, everything is perfect. but if the objects are moved faraway from the camera, the surface of objects would break.

The broken objects will be like:

surfaces got broken when object is far away in iphone

the code snippet of draw objects is:

glVertexPointer(3, GL_FLOAT, 32, self.vertices);
glNormalPointer(GL_FLOAT, 32, &(self.vertices[3]));
开发者_如何学PythonglTexCoordPointer(2, GL_FLOAT, 32, &(self.vertices[6]));    

glDrawElements(GL_TRIANGLES, self.indexNumber, GL_UNSIGNED_SHORT, &(self.faces[0]));

I guess the reason could be the precision of float number.

Anyone have a solution for this? thanks


The problem is depth-buffer precision.

Depth values are scaled such that closer objects have a greater range of possible depth values than those further away. Distant objects are therefore more likely to exhibit z-fighting and other such problems. See question 12.070 in this FAQ.

The near and far frustum planes should always be set to be as close together as possible: i.e.: the near plane should be as far from the camera as possible while still being closer than the rendered object, and the far plane should be as close as possible while still being further away than the rendered object.

It looks like you're just rendering the one object - find the nearest and closest points on that object, add a bit of padding for safety, and use those values for the near and far planes.

If you have to render a scene with objects both in the distance and the foreground and you run into similar problems you can split the rendering into two phases. First render the distant objects with appropriate near and far values, then clear the depth buffer and render the foreground objects with their own appropriate near and far values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜