Example usage for org.lwjgl.opengl GL20 glUniform3f

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:glvis.renderers.NeatSymmetrical.java

@Override
public void render() {
    if (initial) {
        GL11.glClear(16384);//  w  w w .  j  a  v a 2 s.c  om
        initial = false;
    }

    int LIGHT_POINTS = 288 * 2; // 1152
    //        LIGHT_POINTS = 2;
    //        int LIGHT_POINTS = 1152; // 1152
    float LIGHT_POINT_SEPARATION = 4.42f;

    float LIGHT_Y = 256f;
    float LIGHT_X = 0f;

    short raw = 0;
    float fraw = 0;
    float calc = 0;

    float distx = 0;
    float disty = 0;
    boolean swch = false;
    int hak = 0;

    short rraw = 0;

    float vdist = 0f;

    boolean chswch = false;

    GL11.glEnable(GL11.GL_BLEND); //Enable blending.
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    if (initial) {
        initial = false;
        GL11.glColor4f(0f, 0f, 0f, 1f);
    } else
        GL11.glColor4f(0f, 0f, 0f, 0.1f);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(0, 0);
    GL11.glVertex2f(1280, 0);
    GL11.glVertex2f(1280, 720);
    GL11.glVertex2f(0, 720);
    GL11.glEnd();
    GL11.glDisable(GL11.GL_BLEND); //Enable blending.
    GL11.glColor4f(1f, 1f, 1f, 1f);
    //        GL11.glPolygonMode( GL11.GL_FRONT_AND_BACK, GL11.GL_LINE );
    short[] samp = provider.getCurrentSample();
    int samplen = provider.getCurrentSampleLength();

    for (int ie = 0; ie < LIGHT_POINTS; ie++) {
        //GL11.glColor4f(((float)ie)/LIGHT_POINTS,((float)ie)/LIGHT_POINTS,((float)ie)/LIGHT_POINTS,1f);

        //            itra ++;
        //            itra %= Player.samplen;
        //            raw = Player.samp[itra];
        //            rraw = Player.samp[Player.samplen-(itra+1)];

        itra++;
        itra %= samplen;
        raw = samp[itra];
        rraw = samp[samplen - (itra + 1)];
        itra++;
        itra %= samplen;
        raw += samp[itra];
        rraw += samp[samplen - (itra + 1)];
        raw /= 2;
        rraw /= 2;

        //            
        phys_x[ie] /= 2f;
        phys_y[ie] /= 2f;

        distx = -loc_x[ie];
        disty = -loc_y[ie];
        //            phys_x[ie] += distx + raw/64f;
        //            phys_y[ie] += disty + rraw/64f;
        phys_x[ie] += distx + raw / 64f;
        phys_y[ie] += disty + rraw / 64f;

        loc_x[ie] += phys_x[ie] / 16f;
        loc_y[ie] += phys_y[ie] / 16f;
        LIGHT_X = loc_x[ie] * 2 + 1280 / 2;
        LIGHT_Y = loc_y[ie] * 2 + 720 / 2;

        GL11.glColorMask(true, true, true, true);
        GL20.glUseProgram(this.shaderProgram);
        GL20.glUniform2f(GL20.glGetUniformLocation(this.shaderProgram, (CharSequence) "location"), LIGHT_X,
                720.0F - LIGHT_Y);
        GL20.glUniform3f(GL20.glGetUniformLocation(this.shaderProgram, (CharSequence) "colour"), R[ie] / 14,
                G[ie] / 14, B[ie] / 14);
        GL11.glEnable(3042);
        GL11.glBlendFunc(1, 1);
        GL11.glBegin(7);
        GL11.glVertex2f(0.0F, 0.0F);
        GL11.glVertex2f(0.0F, 720.0F);
        GL11.glVertex2f(1280.0F, 720.0F);
        GL11.glVertex2f(1280.0F, 0.0F);
        GL11.glEnd();
        GL11.glDisable(3042);
        GL20.glUseProgram(0);

    }

    for (int ie = 0; ie < LIGHT_POINTS; ie++) {
        LIGHT_X = loc_x[ie] * 4 + 1280 / 2;
        LIGHT_Y = loc_y[ie] * 4 + 720 / 2;

        vdist = Math.abs(distx) + Math.abs(disty);
        vdist /= 4f;

        R[ie] /= 1.08;
        G[ie] /= 1.08;
        B[ie] /= 1.08;
        R[ie] += ((Math.abs(loc_y[ie] % 2f) + Math.abs(loc_x[ie] % 2f)) * vdist) / 512f;
        G[ie] += ((loc_x[ie] % 2f + Math.abs(loc_y[ie] % 2f)) * vdist) / 256f;
        B[ie] += ((Math.abs(loc_x[ie] % 2f) + loc_y[ie] % 2f) * vdist) / 256f;
        LIGHT_X = loc_x[ie] * 2 + 1280 / 2;
        LIGHT_Y = loc_y[ie] * 2 + 720 / 2;
        //            GL11.glColor3f(lR9[ie], lG9[ie], lB9[ie]);
        //            GL11.glVertex2f(lastx9[ie], lasty9[ie]);
        //            GL11.glColor3f(lR8[ie], lG8[ie], lB8[ie]);
        //            GL11.glVertex2f(lastx8[ie], lasty8[ie]);
        //            GL11.glColor3f(lR7[ie], lG7[ie], lB7[ie]);
        //            GL11.glVertex2f(lastx7[ie], lasty7[ie]);
        GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

        GL11.glColor3f(lR6[ie], lG6[ie], lB6[ie]);
        GL11.glVertex2f(lastx6[ie], lasty6[ie]);
        GL11.glColor3f(lR5[ie], lG5[ie], lB5[ie]);
        GL11.glVertex2f(lastx5[ie], lasty5[ie]);
        GL11.glColor3f(lR4[ie], lG4[ie], lB4[ie]);
        GL11.glVertex2f(lastx4[ie], lasty4[ie]);
        GL11.glColor3f(lR3[ie], lG3[ie], lB3[ie]);
        GL11.glVertex2f(lastx3[ie], lasty3[ie]);
        GL11.glColor3f(lR2[ie], lG2[ie], lB2[ie]);
        GL11.glVertex2f(lastx2[ie], lasty2[ie]);
        GL11.glColor3f(lR[ie], lG[ie], lB[ie]);
        GL11.glVertex2f(lastx[ie], lasty[ie]);
        GL11.glColor3f(R[ie] * 2, G[ie] * 2, B[ie] * 2);
        GL11.glVertex2f(LIGHT_X, LIGHT_Y);

        lastx9[ie] = lastx8[ie];
        lasty9[ie] = lasty8[ie];
        lastx8[ie] = lastx7[ie];
        lasty8[ie] = lasty7[ie];
        lastx7[ie] = lastx6[ie];
        lasty7[ie] = lasty6[ie];

        lastx6[ie] = lastx5[ie];
        lasty6[ie] = lasty5[ie];
        lastx5[ie] = lastx4[ie];
        lasty5[ie] = lasty4[ie];
        lastx4[ie] = lastx3[ie];
        lasty4[ie] = lasty3[ie];
        lastx3[ie] = lastx2[ie];
        lasty3[ie] = lasty2[ie];
        lastx2[ie] = lastx[ie];
        lasty2[ie] = lasty[ie];
        //            lastx[ie] = LIGHT_X;
        //            lasty[ie] = LIGHT_Y;
        lastx[ie] = LIGHT_X;
        lasty[ie] = LIGHT_Y;

        lR9[ie] = lR8[ie];
        lG9[ie] = lG8[ie];
        lB9[ie] = lB8[ie];
        lR8[ie] = lR7[ie];
        lG8[ie] = lG7[ie];
        lB8[ie] = lB7[ie];
        lR7[ie] = lR6[ie];
        lG7[ie] = lG6[ie];
        lB7[ie] = lB6[ie];

        lR6[ie] = lR5[ie] / 1.2f;
        lG6[ie] = lG5[ie] / 1.2f;
        lB6[ie] = lB5[ie] / 1.2f;
        lR5[ie] = lR4[ie] / 1.2f;
        lG5[ie] = lG4[ie] / 1.2f;
        lB5[ie] = lB4[ie] / 1.2f;
        lR4[ie] = lR3[ie] / 1.2f;
        lG4[ie] = lG3[ie] / 1.2f;
        lB4[ie] = lB3[ie] / 1.2f;
        lR3[ie] = lR2[ie] / 1.2f;
        lG3[ie] = lG2[ie] / 1.2f;
        lB3[ie] = lB2[ie] / 1.2f;
        lR2[ie] = lR[ie] / 1.2f;
        lG2[ie] = lG[ie] / 1.2f;
        lB2[ie] = lB[ie] / 1.2f;
        lR[ie] = R[ie] * 2;
        lG[ie] = G[ie] * 2;
        lB[ie] = B[ie] * 2;
        GL11.glEnd();

    }
    //
}

From source file:glvis.renderers.NeatSymmetricalTwo.java

@Override
public void render() {
    Display.sync(60);/*from  ww  w.  j  a  v  a 2 s  . c om*/
    if (initial) {
        GL11.glClear(16384);
        initial = false;
    }

    int LIGHT_POINTS = 288; // 1152
    //        LIGHT_POINTS = 2;
    //        int LIGHT_POINTS = 1152; // 1152
    float LIGHT_POINT_SEPARATION = 4.42f;

    float LIGHT_Y = 256f;
    float LIGHT_X = 0f;

    short raw = 0;
    float fraw = 0;
    float calc = 0;

    float distx = 0;
    float disty = 0;
    boolean swch = false;
    int hak = 0;

    short rraw = 0;

    float vdist = 0f;

    boolean chswch = false;

    GL11.glEnable(GL11.GL_BLEND); //Enable blending.
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    if (initial) {
        initial = false;
        GL11.glColor4f(0f, 0f, 0f, 1f);
    } else
        GL11.glColor4f(0f, 0f, 0f, 0.1f);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(0, 0);
    GL11.glVertex2f(1280, 0);
    GL11.glVertex2f(1280, 720);
    GL11.glVertex2f(0, 720);
    GL11.glEnd();
    short[] samp = provider.getCurrentSample();
    int samplen = provider.getCurrentSampleLength();
    GL11.glColor4f(1f, 1f, 1f, 1f);
    //        GL11.glPolygonMode( GL11.GL_FRONT_AND_BACK, GL11.GL_LINE );
    float a1 = 0f, a2 = 0f, a3 = 0f, a4 = 0f, a5 = 0f, a6 = 0f, a7 = 0f, a8 = 0f, a9 = 0f;
    for (int ie = 0; ie < LIGHT_POINTS; ie++) {
        //GL11.glColor4f(((float)ie)/LIGHT_POINTS,((float)ie)/LIGHT_POINTS,((float)ie)/LIGHT_POINTS,1f);
        //            this.skip = false;
        itra++;
        itra %= samplen;
        raw = samp[itra];
        rraw = samp[samplen - (itra + 1)];

        //            itra ++;
        //            itra %= samplen;
        //            raw = samp[itra];
        //            rraw = samp[samplen-(itra+1)];
        //            itra ++;
        //            itra %= samplen;
        //            raw += samp[itra];
        //            rraw += samp[samplen-(itra+1)];
        //            raw/=2;
        //            rraw/=2;

        //            
        phys_x[ie] /= 2f;
        phys_y[ie] /= 2f;

        distx = -loc_x[ie];
        disty = -loc_y[ie];
        //            phys_x[ie] += distx + raw/64f;
        //            phys_y[ie] += disty + rraw/64f;
        phys_x[ie] += distx + raw / 64f;
        phys_y[ie] += disty + rraw / 64f;

        loc_x[ie] += phys_x[ie] / 16f;
        loc_y[ie] += phys_y[ie] / 16f;
        vdist = Math.abs(distx) + Math.abs(disty);
        vdist /= 4f;

        R[ie] /= 1.08;
        G[ie] /= 1.08;
        B[ie] /= 1.08;
        R[ie] += ((Math.abs(loc_y[ie] % 2f) + Math.abs(loc_x[ie] % 2f)) * vdist) / 1024f;
        G[ie] += ((loc_x[ie] % 2f + Math.abs(loc_y[ie] % 2f)) * vdist) / 512f;
        B[ie] += ((Math.abs(loc_x[ie] % 2f) + loc_y[ie] % 2f) * vdist) / 512f;
        LIGHT_X = loc_x[ie] * 2 + 1280 / 2;
        LIGHT_Y = loc_y[ie] * 2 + 720 / 2;
        GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

        a1 = (R[ie] + G[ie] + B[ie]) / 3f;
        a2 = (lR[ie] + lG[ie] + lB[ie]) / 3f;
        a3 = (lR2[ie] + lG2[ie] + lB2[ie]) / 3f;
        a4 = (lR3[ie] + lG3[ie] + lB3[ie]) / 3f;
        a5 = (lR4[ie] + lG4[ie] + lB4[ie]) / 3f;
        a6 = (lR5[ie] + lG5[ie] + lB5[ie]) / 3f;
        a7 = (lR6[ie] + lG6[ie] + lB6[ie]) / 3f;

        GL11.glColor4f(lR6[ie], lG6[ie], lB6[ie], a7);
        GL11.glVertex2f(lastx6[ie], lasty6[ie]);
        GL11.glColor4f(lR5[ie], lG5[ie], lB5[ie], a6);
        GL11.glVertex2f(lastx5[ie], lasty5[ie]);
        GL11.glColor4f(lR4[ie], lG4[ie], lB4[ie], a5);
        GL11.glVertex2f(lastx4[ie], lasty4[ie]);
        GL11.glColor4f(lR3[ie], lG3[ie], lB3[ie], a4);
        GL11.glVertex2f(lastx3[ie], lasty3[ie]);
        GL11.glColor4f(lR2[ie], lG2[ie], lB2[ie], a3);
        GL11.glVertex2f(lastx2[ie], lasty2[ie]);
        GL11.glColor4f(lR[ie], lG[ie], lB[ie], a2);
        GL11.glVertex2f(lastx[ie], lasty[ie]);
        GL11.glColor4f(R[ie] * 2, G[ie] * 2, B[ie] * 2, a1);
        GL11.glVertex2f(LIGHT_X, LIGHT_Y);

        lastx9[ie] = lastx8[ie];
        lasty9[ie] = lasty8[ie];
        lastx8[ie] = lastx7[ie];
        lasty8[ie] = lasty7[ie];
        lastx7[ie] = lastx6[ie];
        lasty7[ie] = lasty6[ie];

        lastx6[ie] = lastx5[ie];
        lasty6[ie] = lasty5[ie];
        lastx5[ie] = lastx4[ie];
        lasty5[ie] = lasty4[ie];
        lastx4[ie] = lastx3[ie];
        lasty4[ie] = lasty3[ie];
        lastx3[ie] = lastx2[ie];
        lasty3[ie] = lasty2[ie];
        lastx2[ie] = lastx[ie];
        lasty2[ie] = lasty[ie];
        //            lastx[ie] = LIGHT_X;
        //            lasty[ie] = LIGHT_Y;
        lastx[ie] = LIGHT_X;
        lasty[ie] = LIGHT_Y;

        lR9[ie] = lR8[ie];
        lG9[ie] = lG8[ie];
        lB9[ie] = lB8[ie];
        lR8[ie] = lR7[ie];
        lG8[ie] = lG7[ie];
        lB8[ie] = lB7[ie];
        lR7[ie] = lR6[ie];
        lG7[ie] = lG6[ie];
        lB7[ie] = lB6[ie];

        lR6[ie] = lR5[ie] / 1.2f;
        lG6[ie] = lG5[ie] / 1.2f;
        lB6[ie] = lB5[ie] / 1.2f;
        lR5[ie] = lR4[ie] / 1.2f;
        lG5[ie] = lG4[ie] / 1.2f;
        lB5[ie] = lB4[ie] / 1.2f;
        lR4[ie] = lR3[ie] / 1.2f;
        lG4[ie] = lG3[ie] / 1.2f;
        lB4[ie] = lB3[ie] / 1.2f;
        lR3[ie] = lR2[ie] / 1.2f;
        lG3[ie] = lG2[ie] / 1.2f;
        lB3[ie] = lB2[ie] / 1.2f;
        lR2[ie] = lR[ie] / 1.2f;
        lG2[ie] = lG[ie] / 1.2f;
        lB2[ie] = lB[ie] / 1.2f;
        lR[ie] = R[ie] * 2;
        lG[ie] = G[ie] * 2;
        lB[ie] = B[ie] * 2;
        GL11.glEnd();

    }
    GL11.glDisable(GL11.GL_BLEND); //Enable blending.
    for (int ie = 0; ie < LIGHT_POINTS; ie++) {
        //            LIGHT_X = loc_x[ie]*4+1280/2;
        //            LIGHT_Y = loc_y[ie]*4+720/2;

        LIGHT_X = loc_x[ie] * 2 + 1280 / 2;
        LIGHT_Y = loc_y[ie] * 2 + 720 / 2;

        GL11.glColorMask(true, true, true, true);
        GL20.glUseProgram(this.shaderProgram);
        GL20.glUniform2f(GL20.glGetUniformLocation(this.shaderProgram, (CharSequence) "location"), LIGHT_X,
                720.0F - LIGHT_Y);
        GL20.glUniform3f(GL20.glGetUniformLocation(this.shaderProgram, (CharSequence) "colour"), R[ie] / 5,
                G[ie] / 5, B[ie] / 5);
        GL11.glEnable(3042);
        GL11.glBlendFunc(1, 1);
        GL11.glBegin(7);
        GL11.glVertex2f(0.0F, 0.0F);
        GL11.glVertex2f(0.0F, 720.0F);
        GL11.glVertex2f(1280.0F, 720.0F);
        GL11.glVertex2f(1280.0F, 0.0F);
        GL11.glEnd();
        GL11.glDisable(3042);
        GL20.glUseProgram(0);
        //            GL11.glColor3f(lR9[ie], lG9[ie], lB9[ie]);
        //            GL11.glVertex2f(lastx9[ie], lasty9[ie]);
        //            GL11.glColor3f(lR8[ie], lG8[ie], lB8[ie]);
        //            GL11.glVertex2f(lastx8[ie], lasty8[ie]);
        //            GL11.glColor3f(lR7[ie], lG7[ie], lB7[ie]);
        //            GL11.glVertex2f(lastx7[ie], lasty7[ie]);

    }
    //

}

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

License:Apache License

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

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//  w w w  .  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:ivengine.view.MatrixHelper.java

License:Creative Commons License

/**
 * Uploads a vector <vec> to the graphics card (Into the uniform location <dest> ) 
 *//*from   ww  w.java  2s.  c o m*/
public static void uploadVector(Vector3f vec, int dest) {
    GL20.glUniform3f(dest, vec.x, vec.y, vec.z);
}

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

License:Open Source License

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

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   ww  w .  j  a v a 2  s. c  o  m
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());
    }
}

From source file:lessur.util.shader.ShaderManager.java

License:GNU General Public License

/**
 * //from www .  ja va2s.  com
 * @param program ID/index of the program
 * @param name Name of the variable
 * @param value Value to set the variable
 */
public void setUniformFloatArray(int program, String name, float values[]) {
    if (has_opengl2) {
        int loc = GL20.glGetUniformLocation(program, name);
        checkVariableLocation(loc, name);
        if (values.length == 1)
            GL20.glUniform1f(loc, values[0]);
        if (values.length == 2)
            GL20.glUniform2f(loc, values[0], values[1]);
        else if (values.length == 3)
            GL20.glUniform3f(loc, values[0], values[1], values[2]);
        else if (values.length == 4)
            GL20.glUniform4f(loc, values[0], values[1], values[2], values[3]);
    } else if (has_arb) {
        int loc = ARBShaderObjects.glGetUniformLocationARB(program, name);
        checkVariableLocation(loc, name);
        if (values.length == 1)
            ARBShaderObjects.glUniform1fARB(loc, values[0]);
        if (values.length == 2)
            ARBShaderObjects.glUniform2fARB(loc, values[0], values[1]);
        else if (values.length == 3)
            ARBShaderObjects.glUniform3fARB(loc, values[0], values[1], values[2]);
        else if (values.length == 4)
            ARBShaderObjects.glUniform4fARB(loc, values[0], values[1], values[2], values[3]);
    }
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java

License:Open Source License

@Override
public void setUniform(String name, Vector3 vec) {
    final int loc = uniforms.get(name);
    if (loc >= 0) {
        GL20.glUniform3f(loc, vec.getX(), vec.getY(), vec.getZ());
    }/*from   w w w  .  j  a v  a2  s  .  c  o  m*/
}

From source file:net.betabears.the2dlibrary.graphics.shader.Uniform3f.java

@Override
public void apply(int location) {
    GL20.glUniform3f(location, f0, f1, f2);
}