endless terrain distortion

endless terrain distortion
0.0 0


I have an endless terrain that looks fine at beginning but when it get further and further the graphic(terrain) becomes distorted. I am using code below. Can anyone shed some light why this is happening?


glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, _hillVertices);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, _hillTexCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nHillVertices);

Capture.PNG (51.2 KB)


Is your UV coordinates ALWAYS in range 0.0…1.0?


@Saby83 when you say UV coordinates do you mean _hillTexCoords in my sample code?

Much Thanks!


As you get further away from the origin the precision of your floating point values for x and y positions will fall. If you are a long way from the origin you will get all sorts of weird problems. This will affect any physics badly as well. Try to find a method to reset around the origin before the co-ords get too big. Hope this helps.


IslandPlaya, you are correct on the issue. I am a newb indie game developer any help with “reset around the origin before the co-ords get too big” will be AWESOME :slight_smile: I see raywenderlich tutorial have the same problem. http://www.raywenderlich.com/forums/viewtopic.php?f=20&t=7404

Perhaps rendering the offset would be better done by updating the vertices x co-ordinates to include the offset like suggested in above linked forum?

Any other help or hints would be greatly appreciated!

Edited - you can fix box2d by using b2World::ShiftOrigin