0
\$\begingroup\$

I've recently encountered a strange problem with my program and I can't seem to fix it. When I try to apply a shader to my SpriteBatch it doesn't change. I've debugged this problem like so:

if (test) {
    System.out.println("Batch shader: " + stage.getBatch().getShader());
    System.out.println("Default shader: " + Assets.getDefaultShader());
    System.out.println("Default batch: " + Assets.SPRITE_BATCH);
    System.out.println("Stage batch: " + stage.getBatch());
}

stage.getBatch().setShader(null);
if (test)
    System.out.println("Batch shader: " + stage.getBatch().getShader()); //Should print null
stage.act();
if (test)
    System.out.println("Batch shader: " + stage.getBatch().getShader());
stage.draw();
if (test)
    System.out.println("Batch shader: " + stage.getBatch().getShader());
test = false;

All of those shaders print the exact same thing, and the batches are also the same (the batches are supposed to be the same). Any ideas why?

\$\endgroup\$
0
\$\begingroup\$

After sitting with this problem for hours I finally found out what was wrong.

If you set the shader to null on your SpriteBatch, it uses the default shader provided to the SpriteBatch. For me, the default shader was Assets.getDefaultShader(), so when I set the shader to null it just used that shader. I fixed this by simply not settings a default shader to the SpriteBatch.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.