Example usage for org.lwjgl.opengl GL20 glUniform4f

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

Introduction

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

Prototype

public static void glUniform4f(@NativeType("GLint") int location, @NativeType("GLfloat") float v0,
        @NativeType("GLfloat") float v1, @NativeType("GLfloat") float v2, @NativeType("GLfloat") float v3) 

Source Link

Document

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

Usage

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

License:Open Source License

public static void loadMaterials(MaterialList matList, int pID) {
    int i = 0;//from   w ww  .  ja  va2  s.co  m
    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.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 w  w  .jav  a2  s  . co  m*/
 * @param name The name of the uniform to specify.
 * @return Whether or not the uniform exists and is active.
 */
public boolean uniform4f(String name, float x, float y, float z, float w) {
    if (DGL.currentProgram() != this)
        throw new IllegalStateException("Program must be in use.");
    int loc = GL20.glGetUniformLocation(id, name);
    if (loc < 0)
        return false;
    GL20.glUniform4f(loc, x, y, z, w);
    return true;
}

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

License:Apache License

/**
 * Pass an LWJGL Vector4f to the active shader. The shader to which the value will be passed must be bound.
 * /*from ww  w . ja  v  a 2s.c o  m*/
 * @param varName  Name of the variable that is in the shader program. Must be an exact match.
 * @param v
 */
public void putVector4f(String varName, Vector4f v) throws NullPointerException {
    if (v == null) {
        throw new NullPointerException("Vector4f passed is null.");
    }
    if (activeShader != null) {
        int location = GL20.glGetUniformLocation(activeShader.shaderProgram, varName);
        GL20.glUniform4f(location, v.x, v.y, v.z, v.w);
    }
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void uniform4f(int location, float v0, float v1, float v2, float v3) {
    GL20.glUniform4f(location, v0, v1, v2, v3);
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLConfigurableMaterial.java

License:Open Source License

private void uploadUniforms(GLScene.DrawModifier drawModifier) {
    drawModifier.apply(shader);/*from w w w  .j  a v a2  s .c om*/

    GL20.glUniform4f(shader.getUniformColorAmbient(), ambient.r, ambient.g, ambient.b, ambient.a);
    GL20.glUniform4f(shader.getUniformColorDiffuse(), diffuse.r, diffuse.g, diffuse.b, diffuse.a);
    GL20.glUniform4f(shader.getUniformColorSpecular(), specular.r, specular.g, specular.b, specular.a);

    GL20.glUniform1f(shader.getUniformValueSpecularCoefficient(), specularCoeff);
    // bind texture
    if (hasDiffuseTexture)
        diffuseTexture.use(shader.getTextureImageUnitDiffuse());
}

From source file:fr.ign.cogit.geoxygene.util.gl.GLProgram.java

License:Open Source License

/**
 * @param value/*from www  . jav  a  2s  . c om*/
 * @param uniformLocation
 */
private void setUniform4f(int uniformLocation, float... values) {
    GL20.glUniform4f(uniformLocation, values[0], values[1], values[2], values[3]);
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static void glUniform4f(int location, float x, float y, float z, float w) {
    GL20.glUniform4f(location, x, y, z, w);
}

From source file:itdelatrisu.opsu.render.CurveRenderState.java

License:Open Source License

/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve//from w ww .  ja v  a 2 s.c o  m
 * @param borderColor the curve border color
 * @param curve the points along the curve
 */
private void draw_curve(Color color, Color borderColor, Vec2f[] curve) {
    staticState.initGradient();
    RenderState state = startRender();
    int vtx_buf;
    // the size is: floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone)
    FloatBuffer buff = BufferUtils
            .createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2))
            .asFloatBuffer();
    staticState.initShaderProgram();
    vtx_buf = GL15.glGenBuffers();
    for (int i = 0; i < curve.length; ++i) {
        float x = curve[i].x;
        float y = curve[i].y;
        //if (i == 0 || i == curve.length - 1){
        fillCone(buff, x, y, NewCurveStyleState.DIVIDES);
        if (i != 0) {
            float last_x = curve[i - 1].x;
            float last_y = curve[i - 1].y;
            double diff_x = x - last_x;
            double diff_y = y - last_y;
            x = (float) (x - diff_x / 2);
            y = (float) (y - diff_y / 2);
            fillCone(buff, x, y, NewCurveStyleState.DIVIDES);
        }
    }
    buff.flip();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
    GL20.glUseProgram(staticState.program);
    GL20.glEnableVertexAttribArray(staticState.attribLoc);
    GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
    GL20.glUniform1i(staticState.texLoc, 0);
    GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
    GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
    //stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
    //2*4 is for skipping the first 2 floats (u,v)
    GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
    GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
    for (int i = 0; i < curve.length * 2 - 1; ++i)
        GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2),
                NewCurveStyleState.DIVIDES + 2);
    GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
    GL20.glDisableVertexAttribArray(staticState.attribLoc);
    GL15.glDeleteBuffers(vtx_buf);
    endRender(state);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public void setUniform4(int id, float[] values) {
    GL20.glUniform4f(id, values[0], values[1], values[2], values[3]);
}

From source file:kubex.gui.FinalDrawManager.java

License:Creative Commons License

/**
 * Uploads to the deferred shader the uniforms it needs. For it, consults the shader capabilities.
 *///from w  w w .j  av a  2  s.  c  om
protected void uploadToShader(DeferredShaderProgram DSP, Matrix4f viewMatrix, Matrix4f projectionMatrix,
        float xres, float yres) {
    //Those uniforms are universal for all deferred shaders, they will be uploaded for each one of them
    MatrixHelper.uploadMatrix(viewMatrix, glGetUniformLocation(DSP.getID(), "viewMatrix"));
    MatrixHelper.uploadMatrix(projectionMatrix, glGetUniformLocation(DSP.getID(), "projectionMatrix"));
    glUniform1i(glGetUniformLocation(DSP.getID(), "colorTex"), DSP.colorTexLocation()); //The color texture of the shader can vary
    glUniform1i(glGetUniformLocation(DSP.getID(), "liquidLayersTex"), KubexGame.LIQUIDLAYERS_TEXTURE_LOCATION);
    glUniform1i(glGetUniformLocation(DSP.getID(), "baseFboDepthTex"), KubexGame.BASEFBO_DEPTH_TEXTURE_LOCATION);
    glUniform1i(glGetUniformLocation(DSP.getID(), "brightnessNormalTex"),
            KubexGame.BASEFBO_NORMALS_BRIGHTNESS_TEXTURE_LOCATION);
    glUniform1i(glGetUniformLocation(DSP.getID(), "liquidLayersTexLength"), this.liquidRenderer.getNumLayers());
    if (DSP.miscTexLocation() != -1)
        glUniform1i(glGetUniformLocation(DSP.getID(), "miscTex"), DSP.miscTexLocation()); //Deferred shaders support up to 2 "misc" textures, if requested.
    if (DSP.miscTex2Location() != -1)
        glUniform1i(glGetUniformLocation(DSP.getID(), "miscTex2"), DSP.miscTex2Location()); //they are called misc to generalize them and upload them in different shaders
    //with different purposes each.
    glUniform1f(glGetUniformLocation(DSP.getID(), "cfar"), cfar);
    glUniform1f(glGetUniformLocation(DSP.getID(), "cnear"), cnear);
    glUniform1f(glGetUniformLocation(DSP.getID(), "cwidth"), xres);
    glUniform1f(glGetUniformLocation(DSP.getID(), "cheight"), yres);

    glUniform1f(glGetUniformLocation(DSP.getID(), "time"),
            (float) (System.currentTimeMillis() % 1000000) / 1000); //Uploads current time to the shaders, for them to do things like water flow.
    //The value can't grow forever as the float precission is moderate, so it will be truncated
    //to 1.000 sec maximum, moment in which the time will reset to 0 and the flow in the scene will blink
    //it will not be very noticeable and it will happen once each 20 min.
    //with one 0 more it will hapen once each 3 hours, but im scared of the float precision errors.

    GL20.glUniform1f(glGetUniformLocation(DSP.getID(), "daylightAmount"), this.world.getDaylightAmount());
    Vector3f sunNormal = this.sky.getSunNormal();
    GL20.glUniform3f(glGetUniformLocation(DSP.getID(), "sunNormal"), sunNormal.x, sunNormal.y, sunNormal.z);

    if (DSP.supportWorldPosition()) //If the shader needs to know the world position of the camera, upload it truncating it to a 500 val max, to avoid floating precision errors.
    {
        GL20.glUniform3f(glGetUniformLocation(DSP.getID(), "WorldPosition"),
                (float) (this.world.getCameraCenter().x % 500), (float) (this.world.getCameraCenter().y % 500),
                (float) (this.world.getCameraCenter().z % 500));
    }

    //if shadows supported, upload the needed uniforms
    if (DSP.supportShadows()) {
        GL20.glUniform1i(glGetUniformLocation(DSP.getID(), "shadowMap"), KubexGame.SHADOW_TEXTURE_LOCATION);

        float[] dsplits = this.shadowsManager.getSplitDistances();
        int splitDistances = glGetUniformLocation(DSP.getID(), "splitDistances");
        switch (this.shadowsManager.getNumberSplits()) {
        case 1:
            GL20.glUniform4f(splitDistances, dsplits[1], 0, 0, 0);
            break;
        case 2:
            GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], 0, 0);
            break;
        case 3:
            GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], dsplits[3], 0);
            break;
        case 4:
            GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], dsplits[3], dsplits[4]);
            break;
        }

        int shadowMatrixes = glGetUniformLocation(DSP.getID(), "shadowMatrixes");
        for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) {
            MatrixHelper.uploadMatrix(this.shadowsManager.getOrthoProjectionForSplitScreenAdjusted(i),
                    shadowMatrixes + (i));
        }
    }

    if (DSP.supportSkyParameters()) //if sky supported, upload all sky parameters
    {
        this.sky.uploadToShader(DSP);
    }
    if (DSP.supportPlayerLighting()) //If player lighting supported, upload players average lighting surrounding him.
    {
        int currentLightLoc = glGetUniformLocation(DSP.getID(), "currentLight");
        GL20.glUniform1f(currentLightLoc, this.world.getAverageLightExposed());
    }
}