0
votes

I have recently began developing a LibGDX application and am currently developing the GUI. However, I have encountered a problem relating to Labels within Scene2D. The Image below should speak a thousand words:

Image of the issue

As you can see, the word 'Score' is displayed, but it has a per-character black background that is not consistent with the one behind it.

The label itself is contained within the light grey table, which is within another table holding the upper elements. This table is housed within a master table.

Initially, I believed the background to be related to the GLClearColor, however from testing, I have found that it is not - a red GLClearColor still produces a black background. Also, I have checked that the colours of the tables contain an alpha value of 1, I have tried changing the font, changing the font colour as well as the scaling. I have now ran out of ideas.

Here are the code extracts relating to the label:

private Label score;

score = new Label("Score:", skin);
score.setFontScale(3);

Then the label is added to the 'scoreTable':

scoreTable.add(score).expand().fill();
scoreTable.pack();

The skin is defined as below in 'uiskin.json':

// @formatter:off
{
    com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: homestile.fnt } },
    com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
        default: { down: default-round-down, up: default-round, font: default-font},
    },
    com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
        default:  {
            titleFont: default-font
        }
    },
    "com.badlogic.gdx.graphics.Color": {
        "white": { "r": 1, "g": 1, "b": 1, "a": 1},
        "black": { "r": 0, "g": 0, "b": 0, "a": 1},
    },
    com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
        default: { font: default-font, fontColor: white }
    }
}

Can anyone shine some light on this problem?

Edit : Here are the font files:

http://i.stack.imgur.com/xDmL1.png (Note that this is a white font, so viewing it when there is a white background makes it look invisible. Trust me, it is there)

https://drive.google.com/file/d/0B9Xrus17wYbNUXlOVHFKX2YybjQ/view?usp=sharing

1
Can you show us the Bitmap used in the BitmapFont? I know the fonts support varying "lightness" values and if there is a black outline in the actual font that could be the problem.Fooble
Looks like it would look if blending were turned off, but Stage shouldn't be doing that normally. I'd guess the image file you're using for the font lacks an alpha channel.Tenfour04
There you go - see the editCryptoclysm
It seem clear to me that the alpha channel is being ignored. The font image file has one, so I'm wondering if it's the display pixel format that's the problem. Questions: Does this happen on all devices or just some? If some, which? If it's happening on the Desktop, have you done anything unusual in the DesktopLauncher?Phil Anderson
Just checked on a few android devices and the problem persists. The launchers used are just the defaults.Cryptoclysm

1 Answers

0
votes

After searching for 'blend' in the code, I found the answer. It appears that somewhere else in the code, I call this:

batch.enableBlending();
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glEnable(GL20.GL_BLEND);
batch.draw(texture,this.getX(),getY());
Gdx.gl.glDisable(GL20.GL_BLEND);
batch.disableBlending();

When these lines are removed (namely Gdx.gl.glDisable(GL20.GL_BLEND);), the problem is resolved and the text renders correctly. I assumed that stage would enable it by default, but it appears that it relies on the initial state of GL_BLEND being on, within LibGDX. Lesson learnt.