iDevGames Forums
Tile Bleeding with GL_NEAREST - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Tile Bleeding with GL_NEAREST (/thread-6022.html)



Tile Bleeding with GL_NEAREST - rzilibowitz - Dec 20, 2004 06:46 AM

I've noticed a few posts about tiling or tile based games in opengl, so forgive me if this question has already been dealt with... but I'm not sure if it has...

I am confounded by a problem with rendering 2d tiles under a glOrtho matrix. I am using GL_NEAREST so filtering should not be an issue.

When scrolled to some positions everything looks ok. But scrolled to another position the tiles get adjacent texels bleeding into them. I have all my tiles on a single texture and use fractional texture coords.

These two screenshots should make my problem fairly clear:

users.bigpond.net.au/rz/right.tiff
users.bigpond.net.au/rz/left.tiff

I have come across the article about the gluOrtho2D bug in OpenGL. Is this an example of the bug that I'm experiencing? And is this a bug in the OS X implementation of OpenGL or is it on all systems?


Tile Bleeding with GL_NEAREST - Sixten - Dec 20, 2004 07:44 AM

Is each of those tiles a separate quad, drawn side by side in the same plane? If so, then maybe you're seeing the problem described in the red book here (search for Figure 2-13).

Unfortunately, I'm not really sure the best way to solve this problem is in the tile scenario. You can't really make the joins non-orthogonal, like the book suggests.


Tile Bleeding with GL_NEAREST - Skorche - Dec 20, 2004 08:35 AM

Use integer coordinates instead, it'll give you much better results in tiled games. (and less headache) That way you won't get that "swimming tiles" look either.


Tile Bleeding with GL_NEAREST - rzilibowitz - Dec 20, 2004 03:39 PM

Yeah, if I convert my values for gluOrtho2D to integers it does solve the problem... almost.

I still have a strange problem of vertical flickering as it scrolls. - looks a bit like a tv with bad reception or something. That might sound wierd, but thats what it does.

I do have double buffering on and I checked with SDL_GL_GetAttribute. And it seems to be only vertical flicker regardless of whether I draw my tilemap rows first or columns first. It flickers with light and dark bands. Any ideas what could be causing this?


Tile Bleeding with GL_NEAREST - skyhawk - Dec 20, 2004 03:53 PM

rzilibowitz Wrote:I still have a strange problem of vertical flickering as it scrolls. - looks a bit like a tv with bad reception or something. That might sound wierd, but thats what it does.
do you have VBL syncing turned on? it's really simple to turn on in most applications


Tile Bleeding with GL_NEAREST - Josh - Dec 20, 2004 03:59 PM

[sourcecode]
const long synch = 1;
CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &synch);
[/sourcecode]Call that after all your SDL setup code to turn on VBL synch. You will have to include OpenGL/OpenGL.h in order to get the CGL functions.


Tile Bleeding with GL_NEAREST - rzilibowitz - Dec 20, 2004 04:13 PM

ok, thanks... this is really interesting. That stops the flickering from involving bands across the screen. It looks much better. But now it is a whole window flicker. It flickers noticeably between light and dark when scrolling. As soon as scrolling stops it settles on light which is how it should look. So the flickering problem hasn't gone away. Any ideas?


Tile Bleeding with GL_NEAREST - skyhawk - Dec 20, 2004 04:18 PM

do you have an LCD by chance?


Tile Bleeding with GL_NEAREST - rzilibowitz - Dec 20, 2004 04:25 PM

yes, I do... an ibook... what would that mean ?


Tile Bleeding with GL_NEAREST - rzilibowitz - Dec 20, 2004 05:12 PM

well, I tried my code on my iMac and sure enough it looked perfect on a CRT display. So the flickering was because of the lcd. Why on earth does this happen?


Tile Bleeding with GL_NEAREST - Skorche - Dec 20, 2004 06:20 PM

rzilibowitz Wrote:well, I tried my code on my iMac and sure enough it looked perfect on a CRT display. So the flickering was because of the lcd. Why on earth does this happen?

It takes the lcd pixels a while to go from light to dark. So depending on your tile graphics, you might be "smearing" them a bit because of the lcd's speed.


Tile Bleeding with GL_NEAREST - rzilibowitz - Dec 20, 2004 09:26 PM

wow, that's really interesting. makes sense. never wouldn't thought of that probably. thanks