1
\$\begingroup\$

I am about to develop a game completely in shades of grey using libGDX and just for testing purposes, i created two textures in photoshop:

  1. 2048 x 2048 plain white png image with RGB color mode of size 19.1KB
  2. 2048 x 2048 plain white png image with grayscale color mode of size 7.67KB

enter image description here

... so basically both are just plain white images to look at, but the GREY.png one takes comparatively less space than the RGB.png. While rendering the both the images one at a time, RGB image renders perfectly but the grayscale one does not render at all and the output is completely black. My code:

@Override
public void create() {

    texture = new Texture (Gdx.files.internal ("GREY.png")); // ...just change to "RGB.png" to render RGB.png image..
    batch = new SpriteBatch ();

}

@Override
public void render() {

    Gdx.gl.glClearColor (0, 1, 0, 1);
    Gdx.gl.glClear (GL20.GL_COLOR_BUFFER_BIT);

    batch.begin ();
    batch.draw (texture, 0, 0);
    batch.end ();

}

@Override
public void dispose() {
    texture.dispose ();
}

This is all it...No cameras are used, just 2 lines in create() and 5 lines in render() method and 1 line in dispose() method, nothing fancy at all...

Also it will be really stupid to load 19.1KB texture and render it in greyscale using shader when you can directly load same looking image of 7.67KB size.

I don't understand why libGDX does not render the image with grayscale color mode, is it not supported?

UPDATE: grayscaled images are supported by libGDX and

 texture = new Texture (Gdx.files.internal ("gs.png"), Pixmap.Format.LuminanceAlpha, true);

solved my problem.

\$\endgroup\$
4
  • \$\begingroup\$ Just to be clear, SpriteBatch uses it's own shader, internally. Also, AFAIK, there is no "grayscale mode" for GPU's; the colors that SpriteBatch outputs are float4's. For grayscale, the RGB components just happen to always be similar. Since it's using shaders anyway, you can just feed it "grayscaled" RGB textures, or feed your own grayscale pixel shader to batch.begin() and grayscale them on-demand. \$\endgroup\$
    – Jon
    Apr 5, 2015 at 14:30
  • \$\begingroup\$ Also, there are overloads for Texture() that allow you to pass a Pixmap.Format. The list of formats is quite limited. \$\endgroup\$
    – Jon
    Apr 5, 2015 at 14:40
  • \$\begingroup\$ Thanks for your reply, but texture = new Texture (Gdx.files.internal ("gs.png"), Pixmap.Format.LuminanceAlpha, true); solved my problem. \$\endgroup\$ Apr 10, 2015 at 5:22
  • \$\begingroup\$ Out of curiosity, where do the values actually end up? In Luminance, with Alpha 1, essentially premultiplied? \$\endgroup\$
    – Jon
    Apr 10, 2015 at 5:38

1 Answer 1

1
\$\begingroup\$

There are overloads for Texture() that allow you to pass a Pixmap.Format. The list of formats is quite limited.

Per OP:
texture = new Texture (Gdx.files.internal ("gs.png"), Pixmap.Format.LuminanceAlpha, true);

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .