Skip to main content
GameDev.net gamedev.net
🔒 Locked

iPhone Quads Edges ZFight

Started by Miguel De La Cruz Nov 20, 2009 at 2:43 AM 1 replies 1.4k views
Original Post
Miguel De La Cruz
Miguel De La Cruz
Hello, I'm making a 2d tiled background system that uses quads to render each tile in the background. When the tile is repeating,if many tiles are the same texture next to each other, the problem does not happen. But when a different texture is used and placed next to one of those tiles, a black, some-what flickering line appears in the edge between the two tiles. Almost as if it were z fighting for that edge. I'm just using Obj-c and XCode loading the images up using "imagenamed". Has anyone run into these problems? Or, if you know of the problem and know its name, giving me its name would greatly help me on my search for the solution. Thanks to anyone who can help me.
Miguel De La Cruz
Miguel De La Cruz
Hm, it may not be Z fighting between the edges, as a lone-standing tile has its edges seem as if it were creating a floating point error with itself (like a grey, flickering border). Im thinking it could be the camera. I'm using glOrthof(0.0f, 480.0f, 320.0f, 0.0f, -1,1);
and am rendering all sprites at the z position of zero. I here thought those would be the problem, so i changed the far and near plane to be positive and not zero. near 1, far 1000. then i rendered all the sprites at z position 10. no difference at all 8 \. Changed the sprites to render on position along and ignore rotation and scale... i did all i could to not move the matrices.

But all's failed. As the camera scrolls in this 2d game, the floating point error still persists. Any light on this would be greatly appreciated.
Thygrrr
Thygrrr
I believe what happens is that you have subpixel rendering turned on (it is by default, and it's a good thing), so when you scroll your images, parts of neighboring pixels "outside" your intended texture coordinates are filtered into the fragments of the quads.

This is not visible when you use the same tiles, but it is when you use different tiles.

Two solutions: a) turn off subpixel rendering (bad idea, depending on how your game works), or b) make sure your textures have a sufficient border (for scrolling purposes of unscaled textures, a single pixel border outside the actual texture coordinates of the quad will suffice). Note that the border needs to be as inoccuous as possible, and fit all the textures. If you just copy the last row or line of pixels, you may end up with a strange "watery ripples" effect instead.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.