Example usage for org.lwjgl.opengl GL20 glUniform1f

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

Introduction

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

Prototype

public static void glUniform1f(@NativeType("GLint") int location, @NativeType("GLfloat") float v0) 

Source Link

Document

Specifies the value of a float uniform variable for the current program object.

Usage

From source file:com.grillecube.client.opengl.GLProgram.java

protected void loadUniformFloat(int location, float value) {
    GL20.glUniform1f(location, value);
}

From source file:com.opengrave.og.base.RenderableParticles.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    dealWithChange();//  w  w  w  . j av a2 s .c  om
    if (matList == null || !matList.valid()) {
        return;
    }
    GL30.glBindVertexArray(idVao);
    int pID = Resources.loadShader("particle.vs", "particle.fs").getProgram();
    GL20.glUseProgram(pID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 1, "in_Colour");
    GL20.glBindAttribLocation(pID, 2, "in_Scale");
    Util.checkErr();
    int texture = GL20.glGetUniformLocation(pID, "tex");
    GL20.glUniform1i(texture, 0);
    int wSS = GL20.glGetUniformLocation(pID, "windowSizeScale");

    GL20.glUniform1f(wSS, getContext().width / 1024f);
    getContext().setMatrices(pID, matrix);
    if (matList != null && matList.valid()) {
        matList.bind(pID, GL13.GL_TEXTURE0);
    }
    GL11.glEnable(GL20.GL_POINT_SPRITE);
    GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    GL11.glDepthMask(false);
    GL11.glDrawArrays(GL11.GL_POINTS, 0, size);
    GL11.glDepthMask(true);
    GL11.glDisable(GL20.GL_POINT_SPRITE);
    GL11.glDisable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);

    if (matList != null && matList.valid()) {
        matList.unbind();
    }
    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);

    Util.checkErr();

    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    Util.checkErr();
}

From source file:com.opengrave.og.base.RenderableParticles.java

License:Open Source License

@Override
public void renderForPicking(Matrix4f matrix, Pickable object) {
    dealWithChange();//from w  w w  .j  a v a  2s . c  o m
    GL30.glBindVertexArray(idVao);
    int pID = Resources.loadShader("particle.vs", "pickingmodel.fs").getProgram();
    GL20.glUseProgram(pID);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(2);
    GL20.glBindAttribLocation(pID, 0, "in_Position");
    GL20.glBindAttribLocation(pID, 2, "in_Scale");
    Util.checkErr();

    int wSS = GL20.glGetUniformLocation(pID, "windowSizeScale");

    GL20.glUniform1f(wSS, MainThread.lastW / 1024f);
    getContext().setMatrices(pID, matrix);
    GL11.glEnable(GL20.GL_POINT_SPRITE);
    GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    Picking.registerObject(pID, getContext(), object);
    GL11.glDrawArrays(GL11.GL_POINTS, 0, size);
    GL11.glDisable(GL20.GL_POINT_SPRITE);
    GL11.glDisable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);

    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(2);

    Util.checkErr();

    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    Util.checkErr();
}

From source file:com.opengrave.og.base.RenderablePoints.java

License:Open Source License

@Override
public void render(Matrix4f matrix, RenderStyle style) {
    Util.checkErr();/*w  ww.  j ava2s .c  o m*/

    dealWithChange();
    if (!visible) {
        return;
    }
    if (vertCount == 0) {
        return;
    }
    Util.checkErr();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    Util.checkErr();
    GL11.glPointSize(3f);
    Util.checkErr();
    int pID = Resources.loadShader("particle.vs", "particle.fs").getProgram();
    Util.checkErr();
    GL20.glUseProgram(pID);
    Util.checkErr();
    if (pID == 0) {
        return;
    }
    Util.checkErr();
    GL30.glBindVertexArray(vaoID);
    Util.checkErr();
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    Util.checkErr();
    int wSS = GL20.glGetUniformLocation(pID, "windowSizeScale");

    GL20.glUniform1f(wSS, MainThread.lastW / 1024f);

    getContext().setMatrices(pID, matrix);
    Util.checkErr();

    if (tex != null) {
        tex.bind(GL13.GL_TEXTURE0);
    }
    GL11.glEnable(GL20.GL_POINT_SPRITE);
    GL11.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    GL11.glDrawArrays(GL11.GL_POINTS, 0, vertCount);

    GL11.glDisable(GL20.GL_POINT_SPRITE);
    GL11.glDisable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    if (tex != null) {
        tex.unbind();
    }
    Util.checkErr();

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    Util.checkErr();

    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    Util.checkErr();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

From source file:com.opengrave.og.engine.RenderView.java

License:Open Source License

public void bindLights(int pID, int texture) {
    GL20.glUseProgram(pID);/*from   w w  w. j  ava 2 s .  c  o m*/
    int lights = MainThread.config.getInteger("lightCount", 16);
    int showShadows = GL20.glGetUniformLocation(pID, "showShadows");
    GL20.glUniform1i(showShadows, hasshadows ? 1 : 0);
    Util.checkErr();
    if (cam instanceof FlyByCamera) {
        int eyepos = GL20.glGetUniformLocation(pID, "eyepos");
        Util.checkErr();
        Location camL = ((FlyByCamera) cam).getCameraLocation();
        Util.checkErr();
        GL20.glUniform3f(eyepos, camL.getFullXAsFloat(), camL.getFullYAsFloat(), camL.getZ());
        Util.checkErr();
    }
    if (hasshadows) {
        int lightDir = GL20.glGetUniformLocation(pID, "sunDir");
        Vector3f dir = sceneNode.getSkyLight().getDirection().normalise(null);
        GL20.glUniform3f(lightDir, dir.x, dir.y, dir.z);
        int sunStr = GL20.glGetUniformLocation(pID, "sunStr");
        GL20.glUniform1f(sunStr, sceneNode.getSkyLight().getIntensity());
    }
    if (!shadows) {
        return;
    }

    int lightCount = GL20.glGetUniformLocation(pID, "lightCount");
    GL20.glUniform1i(lightCount, lights);

    if (lights < 4) {
        lights = 4;
    }
    for (int i = 0; i < lights; i++) {
        ShadowCube ls;
        if (i >= lightShadows.size()) {
            ls = new ShadowCube(MainThread.config.getInteger("shadowSize", 1024));
            lightShadows.add(ls);
        }
        ls = lightShadows.get(i);
        if (ls == null) {
            continue;
        }
        PointLightNode light = ls.getLight();
        if (light == null) {
            continue;
        }
        int cube = GL20.glGetUniformLocation(pID, "cube" + i);
        int lightcolour = GL20.glGetUniformLocation(pID, "lights[" + i + "].colour");
        int lightposition = GL20.glGetUniformLocation(pID, "lights[" + i + "].position");
        int lightpower = GL20.glGetUniformLocation(pID, "lights[" + i + "].power");
        Vector3f loc = light.getPosition().toVector3();
        if (cam != null) {
            // loc = light.getPosition().minus(cam.getLocation());
            // loc = cam.minus(light.getPosition());
        }
        Util.checkErr();
        // Only upload a shadow texture location if we're having shadows for
        // the light. Basic has lights but no shadows
        if (i < showShadows) {
            GL20.glUniform1i(cube, texture + i - GL13.GL_TEXTURE0);
            ls.getFramebuffer().bindDepthTexture(texture + i);
        }
        Util.checkErr();
        GL20.glUniform4f(lightcolour, light.getColour().x, light.getColour().y, light.getColour().z,
                light.getColour().w);
        Util.checkErr();
        GL20.glUniform4f(lightposition, loc.x, loc.y, loc.z, 1f);
        Util.checkErr();
        GL20.glUniform1f(lightpower, light.getPower());
        Util.checkErr();
        Util.checkErr();
    }
}

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

License:Open Source License

public static void loadMaterials(MaterialList matList, int pID) {
    int i = 0;/*ww  w. ja v a  2 s.  c  om*/
    for (Material m : matList.all()) {
        int locCol1 = GL20.glGetUniformLocation(pID, "material[" + i + "].colour");
        int locTex = GL20.glGetUniformLocation(pID, "material[" + i + "].textureindex");
        int locDTex = GL20.glGetUniformLocation(pID, "material[" + i + "].texturedataindex");

        /*
         * if (locCol == -1) { throw new
         * RuntimeException("No Material Colour location"); } if (locTex ==
         * -1) { throw new RuntimeException("No Material Texture location");
         * }
         */
        GL20.glUniform4f(locCol1, m.getColour().x, m.getColour().y, m.getColour().z, m.getColour().w);
        GL20.glUniform1f(locTex, (float) m.getTextureIndex());
        GL20.glUniform1f(locDTex, (float) m.getTextureDataIndex());

        i++;
    }
}

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

License:Apache License

public void setUniform(int location, float value) {
    GL20.glUniform1f(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  w  ww. ja  v  a  2 s .  co 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 uniform1f(String name, float 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.glUniform1f(loc, x);
    return true;
}

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

License:Apache License

/**
 * Pass a float to the active shader. The shader to which the value will be passed must be bound.
 * //from   ww w.  j  av a2 s . c o  m
 * @param varName Name of the variable that is in the shader program. Must be an exact match.
 * @param x Primitive float to be passed to the shader.
 */
public void putFloat(String varName, float x) {
    if (activeShader != null) {
        int location = GL20.glGetUniformLocation(activeShader.shaderProgram, varName);
        GL20.glUniform1f(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  w  w w .j  a  v a  2 s  .  c  o 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();
}