Example usage for org.lwjgl.opengl GL20 glUniform1i

List of usage examples for org.lwjgl.opengl GL20 glUniform1i

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glUniform1i.

Prototype

public static void glUniform1i(@NativeType("GLint") int location, @NativeType("GLint") int v0) 

Source Link

Document

Specifies the value of an int uniform variable for the current program object.

Usage

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

public void dumpTestingImage() {
    // TESTING/*  w ww  . ja v a2 s .  c o  m*/
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    int pID = Resources.loadShader("test.vs", "test.fs").getProgram();
    GL20.glUseProgram(pID);
    int shadow = GL20.glGetUniformLocation(pID, "shadowMap");
    GL20.glUniform1i(shadow, 0);
    GL30.glBindVertexArray(vao_ID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    shadowMap.bind(GL13.GL_TEXTURE0);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, count * 3);
    shadowMap.unbind();
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);

    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    // END TESTING
}

From source file:com.opengrave.og.Util.java

License:Open Source License

public static void setRenderStyle(int pID, RenderStyle style) {
    int i = 0;//w  ww.jav a 2  s . c  om
    if (style == RenderStyle.GRAYSCALE) {
        i = 1;
    } else if (style == RenderStyle.SEPIA) {
        i = 2;
    } else if (style == RenderStyle.HALO) {
        i = 3;
    }
    GL20.glUniform1i(GL20.glGetUniformLocation(pID, "renderStyle"), i);

}

From source file:com.redthirddivision.quad.rendering.shaders.Shader.java

License:Apache License

public void setUniform(int location, int value) {
    GL20.glUniform1i(location, value);
}

From source file:com.samrj.devil.gl.ShaderProgram.java

License:Open Source License

/**
 * Specifies the value of a uniform variable for this program. Program must
 * be in use. Returns true if and only if the uniform exists and is active.
 * //from   ww  w  .j  ava2 s.c o  m
 * @param name The name of the uniform to specify.
 * @param x The value to set the uniform to.
 * @return Whether or not the uniform exists and is active.
 */
public boolean uniform1i(String name, int x) {
    if (DGL.currentProgram() != this)
        throw new IllegalStateException("Program must be in use.");
    int loc = GL20.glGetUniformLocation(id, name);
    if (loc < 0)
        return false;
    GL20.glUniform1i(loc, x);
    return true;
}

From source file:com.sgflt.ShaderManager.ShaderManager.java

License:Apache License

/**
 * Pass an integer to the active shader. The shader to which the value will be passed must be bound.
 * //from   ww  w .  j a  v a2 s  . c  om
 * @param varName String name of the variable that is in the shader program. Must be an exact match.
 * @param x Primitive integer to be passed to the shader.
 */
public void putInt(String varName, int x) {
    if (activeShader != null) {
        //Grab the location of the variable
        int location = GL20.glGetUniformLocation(activeShader.shaderProgram, varName);
        //Pass the value to the variable location
        GL20.glUniform1i(location, x);
    }
}

From source file:com.xrbpowered.gl.examples.GLFractal.java

License:Open Source License

@Override
protected void setupResources() {
    super.setupResources();
    palette = new Texture("palette.png");
    shader = new PostProcessShader("post_fractal_f.glsl") {
        private int aspectLocation;
        private int pivotLocation;
        private int zoomLocation;
        private int maxiLocation;

        @Override//from ww  w  .  ja v  a2 s.  co  m
        protected void storeUniformLocations() {
            super.storeUniformLocations();
            aspectLocation = GL20.glGetUniformLocation(pId, "aspect");
            pivotLocation = GL20.glGetUniformLocation(pId, "pivot");
            zoomLocation = GL20.glGetUniformLocation(pId, "zoom");
            maxiLocation = GL20.glGetUniformLocation(pId, "maxi");
            GL20.glUseProgram(pId);
            GL20.glUniform1i(GL20.glGetUniformLocation(pId, "palette"), 0);
            GL20.glUseProgram(0);
        }

        @Override
        public void updateUniforms() {
            super.updateUniforms();
            GL20.glUniform1f(aspectLocation, (float) Display.getWidth() / (float) Display.getHeight());
            GL20.glUniform2f(pivotLocation, pivotx, pivoty);
            GL20.glUniform1f(zoomLocation, zoom);
            GL20.glUniform1i(maxiLocation, maxi);
        }
    };
    uiDebugPane.setVisible(false);
    resetBuffer();
}

From source file:com.xrbpowered.gl.examples.GLGlass.java

License:Open Source License

@Override
protected void setupResources() {
    super.setupResources();
    glassShader = new GlassShader();

    diffuse = new Texture("checker.png");
    alpha1 = BufferTexture.createPlainColor(4, 4, new Color(0x22777777, true));
    alpha2 = BufferTexture.createPlainColor(4, 4, new Color(0x00ffffff, true));
    normal = new Texture("glass_n.png");
    blurMask = new Texture("glass_blur.png");
    plane = FastMeshBuilder.plane(4f, 1, 1, StandardShader.standardVertexInfo, null);

    Random random = new Random();
    objectActors = new StaticMeshActor[NUM_OBJECTS];
    for (int i = 0; i < NUM_OBJECTS; i++) {
        objectActors[i] = StaticMeshActor.make(scene, plane, StandardShader.getInstance(), diffuse,
                noSpecularTexture, plainNormalTexture);
        objectActors[i].position.x = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        objectActors[i].position.y = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        objectActors[i].position.z = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        objectActors[i].rotation.x = (float) Math.PI / 2f;
        objectActors[i].updateTransform();
    }//from w  ww  .j a  v a2 s. com
    planeActors1 = new StaticMeshActor[NUM_PLANES];
    planeActors2 = new StaticMeshActor[NUM_PLANES];
    for (int i = 0; i < NUM_PLANES; i++) {
        planeActors1[i] = StaticMeshActor.make(scene, plane, StandardShader.getInstance(), alpha1,
                plainSpecularTexture, normal);
        planeActors1[i].setShader(glassShader);
        planeActors2[i] = StaticMeshActor.make(scene, plane, StandardShader.getInstance(), alpha2,
                noSpecularTexture, normal);
        planeActors2[i].setShader(glassShader);
        planeActors1[i].position.x = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        planeActors1[i].position.y = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        planeActors1[i].position.z = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        planeActors1[i].rotation.x = (float) Math.PI / 2f;
        planeActors2[i].position = planeActors1[i].position;
        planeActors2[i].rotation = planeActors1[i].rotation;
        planeActors1[i].updateTransform();
        planeActors2[i].updateTransform();
    }

    interBuffers = new OffscreenBuffers(getTargetWidth(), getTargetHeight(), false);
    blurBuffers = new OffscreenBuffers(getTargetWidth() / 6, getTargetHeight() / 6, false);
    postProc = new PostProcessShader("post_blur_f.glsl") {
        @Override
        protected void storeUniformLocations() {
            super.storeUniformLocations();
            GL20.glUseProgram(pId);
            GL20.glUniform1i(GL20.glGetUniformLocation(pId, "numSamples"), 5);
            GL20.glUniform1f(GL20.glGetUniformLocation(pId, "range"), 15f);
            GL20.glUseProgram(0);
        }
    };

    lightActor.rotation = new Vector3f((float) Math.PI, 0, 0);
    lightActor.updateTransform();
}

From source file:com.xrbpowered.gl.examples.GLPerlin.java

License:Open Source License

@Override
protected void setupResources() {
    super.setupResources();
    shader = new PostProcessShader("post_noise_f.glsl") {
        private int pivotLocation;
        private int scaleLocation;
        private int seedLocation;

        @Override/*from ww  w. ja  v  a  2  s  . c om*/
        protected void storeUniformLocations() {
            super.storeUniformLocations();
            pivotLocation = GL20.glGetUniformLocation(pId, "pivot");
            scaleLocation = GL20.glGetUniformLocation(pId, "scale");
            seedLocation = GL20.glGetUniformLocation(pId, "seed");
            GL20.glUseProgram(pId);
            GL20.glUniform1i(GL20.glGetUniformLocation(pId, "palette"), 0);
            GL20.glUseProgram(0);
        }

        @Override
        public void updateUniforms() {
            super.updateUniforms();
            GL20.glUniform2f(pivotLocation, pivotx, pivoty);
            GL20.glUniform2f(scaleLocation, buffer.getWidth() / 2, buffer.getHeight() / 2);
            GL20.glUniform1i(seedLocation, seed);
        }
    };
    resetBuffer();
}

From source file:com.xrbpowered.gl.res.shaders.PostProcessShader.java

License:Open Source License

@Override
protected void storeUniformLocations() {
    timeLocation = GL20.glGetUniformLocation(pId, "time");
    GL20.glUseProgram(pId);//from   ww w. j  a  va 2s .c om
    GL20.glUniform1i(GL20.glGetUniformLocation(pId, "colorBuf"), 0);
    GL20.glUseProgram(0);
}

From source file:com.xrbpowered.gl.res.shaders.Shader.java

License:Open Source License

protected void initSamplers(String[] names) {
    GL20.glUseProgram(pId);/* w w w . jav  a2  s  .c o  m*/
    for (int i = 0; i < names.length; i++) {
        GL20.glUniform1i(GL20.glGetUniformLocation(pId, names[i]), i);
    }
    GL20.glUseProgram(0);
}