Search code examples
libgdx

Pixmap thats just transparent....this should be easy right?


Here's my code;

Pixmap pm = new Pixmap(8,8,Format.RGBA8888); 
Pixmap.setBlending(Pixmap.Blending.None); //ensure when we draw transparent we REPLACE the pixels with a transparent color.
pm.setColor(Color.CLEAR);

//pm.setColor(0f,0f,0f,0f); //also didnt work.
//pm.fillRectangle(0, 0, 8, 8);  //also didnt work.
pm.fill();

Gdx.graphics.setCursor(Gdx.graphics.newCursor(pm, 0, 0));
//restore normal blending
Pixmap.setBlending(Pixmap.Blending.SourceOver);

I was trying to replacing the default cursor with a transparent pixmap.

This seemed to be the easiest way to completely replace the in game cursor (on desktop/gwt) without it also going outside the boundary's of the window, and thus irritating users.

Thing is, the replacement cursor always comes out black, not transparent. Am I making the Pixmap wrong?

Can you not have transparent cursors? (it says it cant be semi-transparent, but I want it fully invisible).

Kinda puzzled here as there doesn't seem many options left to try. I could just load a empty png I guess, but that seems....well....silly.

ideas?

Thanks,

Thomas


Solution

  • Ok, as far as I can tell its a bug in LibGDX pixmap fill function when used on small sizes. I came to this conclusion after noticing it works when the map is bigger.

    Pixmap pm = new Pixmap(x,y,Format.RGBA8888); 
    Pixmap.setBlending(Pixmap.Blending.None); 
    pm.setColor(0f,0f,0f,0f);
    pm.fillRectangle(0, 0, x, y);
    

    Experimenting with the size of the pixmap (x/y) I get the following results;

    8*8 - doesn't work. Comes out black.

    16*16 - works. Completely transparent.

    64*64 - works. Completely transparent.

    So the workaround is just using 16x16 or above. Its transparent anyway, so doesn't matter. Still, odd bug.

    CONCLUSION:

    Seems to be a bug in the windows library being used. Thread discussion here; https://github.com/libgdx/libgdx/issues/4292#issuecomment-244804073

    Unfortunately this likely means the workaround cant be relied upon.