Search code examples
javaopenglopengl-eslibgdx

libGDX: Outer Glow for image using shader


I am game developer using libGDX framework, but new in shader OpenGL. I was trying to do outer glow like this image:

enter image description here

I found simple tutorials in different sites for example like this 2D Selection Outline Shader in LibGDX. It works fine but Outline only drew and the image didn't draw I don't know why !

The image:

enter image description here

In render method:

@Override
public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    shaderOutline.begin();
    shaderOutline.setUniformf("u_viewportInverse", new Vector2(1f / 99, 1f / 94));
    shaderOutline.setUniformf("u_offset", 2);
    shaderOutline.setUniformf("u_step", Math.min(1f, 99 / 70f));
    shaderOutline.setUniformf("u_color", new Vector3(123/255, 1, 71/255));
    shaderOutline.end();

    batch.setShader(shaderOutline);
    batch.begin();
    batch.draw(img, 240, 400);
    batch.end();
    batch.setShader(null);

}

Output:

enter image description here

Finally, I need any advice in this field (shading language).


Solution

  • You need to add the drawing of the image itself as well:

    In render:

    batch.setShader(shaderOutline);
    batch.begin();
    batch.draw(img, 240, 400);
    batch.end();
    batch.setShader(null);
    // Add this:
    batch.begin();
    batch.draw(img, 240, 400);
    batch.end();