Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bleeding  (Read 19425 times)
0 Members and 1 Guest are viewing this topic.
Offline Cero
« Posted 2012-07-10 15:56:16 »

I have different games using different libs.
However almost all of them have the same problem: Zooming causes bleeding.

Here an isometric example

So I would appreciate it if you OpenGL experts would talk about: How, when and why it happens; and also of course how to avoid it.

Offline Roquen

JGO Kernel

Medals: 518

« Reply #1 - Posted 2012-07-10 17:17:25 »

I not sure what visual defect you're referring to.  As a guess: RGB colors even if alpha is 0 DO count, due to sampling.
Offline davedes
« Reply #2 - Posted 2012-07-10 17:30:08 »

This occurs because the filtering is set to GL_LINEAR. Bilinear filtering will select the nearest four pixels and blend them using a weighted average. As Roquen said, the RGB is blended even if the adjacent pixels have an alpha of zero.

For example, this 32x32 grass tile is located at (1, 1) on the sheet.

We see bleeding when we scale up:

This is because when GL goes to sample the edge pixels of our grass tile, it blends the grass with adjacent pixels (magenta).

The solution is to use GL_NEAREST for our sprite sheet, which only picks the "nearest" colour and doesn't blend adjacent pixels.

If the images don't need to be tiled, we could instead simply pad our sprite sheets with some transparent white pixels.

What if you need GL_LINEAR, and your sprites need to be tiled? Even if you pad the sprites, you will end up with bleeding (whatever is behind our tiles will bleed through, as it appears in your first screen shot). One hack/solution to this is to pad our sprites with pixels taken from opposing edges. The top line of pixels taken from the bottom, the left line of pixels taken from the right, etc:

The result when scaled:

This problem may also manifest itself if you're loading non-power-of-two textures with Slick/SlickUtil. In that case, Slick pads the extra dimensions (to make it power of two) with transparent black pixels. Therefore bleeding on the bottom/right edges may occur using GL_LINEAR, even if the scale is unchanged.

tl;dr - don't use GL_LINEAR

Bleeding may also occur if you are using non-power-of-two texture regions (i.e. sprites), due to floating point inaccuracies. Ideally you should stick to power-of-two where possible.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2012-07-11 00:02:33 »

If you're okay with limiting yourself to OpenGL 3+ cards you could just use a 2D texture array to hold the tiles. It's basically a 3D texture, but it won't interpolate between layers, meaning that you can create a 32x32xNUM_TILES texture array, and it magically works with filtering, mipmaps, etc since you can just enable GL_CLAMP_TO_EDGE.

Offline Cero
« Reply #4 - Posted 2012-07-11 00:45:01 »

If you're okay with limiting yourself to OpenGL 3+ cards...

Of course not. >_>

Offline davedes
« Reply #5 - Posted 2012-07-11 00:52:50 »

Many older cards support texture arrays through extension (GL_EXT_texture_array). My OpenGL 2.1 card supports it.

Offline matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

« Reply #6 - Posted 2012-07-11 17:13:00 »

Cero is rage-appreciating here Cheesy [Note: this is an unrelevant post, which is not necessary. This is also not edited Tongue ]

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ruben01

Senior Devvie

Medals: 4
Projects: 3

« Reply #7 - Posted 2012-07-11 23:52:50 »

Hi we had some problems with sprites, where the borders where looking ugly so we made a tool that bleeds the colors of the opaque pixels into the transparent ones, the pixels that are not 100% transparent are not changed, but the transparent pixels get the color of the neighouring pixels. This fixes the interpolation error that usually happens in those pixels.

The tool does this:

 the left image is the original one rendered over a red background, the middle one is the result with alpha disabled, and the right one is the result image rendered over a red background with alpha enabled.

The projects is available here: and there is a runnable jar in the downloads section.

If you have any question feel free to ask.

Offline Cero
« Reply #8 - Posted 2012-07-12 01:29:19 »

Cero is rage-appreciating here :D [Note: this is an unrelevant post, which is not necessary. This is also not edited :P ]

I saw someone appreciating posts in this thread that wasn't me - even though it was my question and I even say I would appreciate it. SO I figured, I gotta use that feature more often ;D


Looks like its rather for sprites than tiles

For tiles its more complicated...
Padding seems to work, however, I have of course build an entire game around these existing tilesets.
So we going to try to use texture arrays...

Offline theagentd
« Reply #9 - Posted 2012-07-12 17:48:18 »

That looks great! Even if it isn't perfect it's 100x better than nothing!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JFixby
« Reply #10 - Posted 2013-02-23 19:33:24 »

Here is merge of the the gemserk's source code with the available source code of the TexturePacker:

(+ explanatory blog-post

my dev log:
Pages: [1]
  ignore  |  Print  

Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5497 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5757 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

EgonOlsen (4659 views)
2018-06-10 19:43:48

EgonOlsen (5680 views)
2018-06-10 19:43:44

EgonOlsen (3196 views)
2018-06-10 19:43:20

DesertCoockie (4094 views)
2018-05-13 18:23:11

nelsongames (5113 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!