Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've written a shader that uses three different textures, tex0, tex1, and tex2. I can load it into Slick and successfully display it, but I can't figure out how to set the three different textures. Whichever texture I last load or set is the one used for all three.

My code:

if (sp == null) {
    try {
        sp = ShaderProgram.loadProgram("passthrough.vert", "planet.frag");
        planet = TextureLoader.getTexture("png", new FileInputStream("earth.png"));
        clouds = TextureLoader.getTexture("png", new FileInputStream("clouds.png"));
        lights = TextureLoader.getTexture("png", new FileInputStream("lights.png"));
    } catch (Exception e) {


// Attempt to set tex0-tex2. This fails and just sets everything to tex2.
glUniform1i(sp.getUniform1i("tex0"), 0);
glBindTexture(GL_TEXTURE_2D, planet.getTextureID());

glUniform1i(sp.getUniform1i("tex1"), 1);
glBindTexture(GL_TEXTURE_2D, clouds.getTextureID());

glUniform1i(sp.getUniform1i("tex2"), 0);
glBindTexture(GL_TEXTURE_2D, lights.getTextureID());

sp.setUniform1f("time", tick * 0.03f);
sp.setUniform2f("resolution", 400f, 400f);

// Render a quad. This works, except that the textures are all the same.
glVertex2i(0, 0);
glVertex2i(0, 400);
glVertex2i(400, 400);
glVertex2i(400, 0);
share|improve this question

OK, it turns out that instead of

glUniform1i(sp.getUniform1i("tex0"), 0);

I should be using eg

sp.setUniform1i("tex0", 0);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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