Example usage for android.opengl GLES20 glUniformMatrix4fv

List of usage examples for android.opengl GLES20 glUniformMatrix4fv

Introduction

In this page you can find the example usage for android.opengl GLES20 glUniformMatrix4fv.

Prototype

public static native void glUniformMatrix4fv(int location, int count, boolean transpose, float[] value,
            int offset);

Source Link

Usage

From source file:Triangle.java

public void draw(float[] mvpMatrix) {
    GLES20.glUseProgram(mProgram);//from  ww  w.ja  va  2  s  .  c  om
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
            vertexBuffer);
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}

From source file:com.google.fpl.liquidfunpaint.renderer.ScreenRenderer.java

/**
 * Draw function for the geometry that this class owns.
 *///from  w  ww  .  j  a va  2s . c  o m
public void draw(float[] transformFromTexture) {
    RenderHelper.SCREEN_QUAD_VERTEX_BUFFER.rewind();

    mMaterial.beginRender();

    // Set attribute arrays
    mMaterial.setVertexAttributeBuffer("aPosition", RenderHelper.SCREEN_QUAD_VERTEX_BUFFER, 0);
    mMaterial.setVertexAttributeBuffer("aTexCoord", RenderHelper.SCREEN_QUAD_VERTEX_BUFFER, 3);

    // Set per draw uniforms
    GLES20.glUniformMatrix4fv(mMaterial.getUniformLocation("uMvpTransform"), 1, false, transformFromTexture, 0);
    GLES20.glUniform1f(mMaterial.getUniformLocation("uAlphaThreshold"), mAlphaThreshold);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4);

    mMaterial.endRender();
}

From source file:com.google.fpl.liquidfunpaint.ParticleRenderer.java

/**
 * Draw all the water particles, and save all the other particle groups
 * into a list. We draw these to temp mRenderSurface[0].
 *//*from   w w w .  j  ava2 s. co  m*/
private void drawWaterParticles() {
    // Draw all water particles to temp render surface 0
    mRenderSurface[0].beginRender(GLES20.GL_COLOR_BUFFER_BIT);

    mWaterParticleMaterial.beginRender();

    // Set attribute arrays
    mWaterParticleMaterial.setVertexAttributeBuffer("aPosition", mParticlePositionBuffer, 0);
    mWaterParticleMaterial.setVertexAttributeBuffer("aColor", mParticleColorBuffer, 0);
    mWaterParticleMaterial.setVertexAttributeBuffer("aWeight", mParticleWeightBuffer, 0);

    // Set uniforms
    GLES20.glUniformMatrix4fv(mWaterParticleMaterial.getUniformLocation("uTransform"), 1, false,
            mTransformFromWorld, 0);

    // Go through each particle group
    ParticleSystem ps = Renderer.getInstance().acquireParticleSystem();
    try {
        ParticleGroup currGroup = ps.getParticleGroupList();

        while (currGroup != null) {
            // Only draw water particles in this pass; queue other groups
            if (currGroup.getGroupFlags() == Tool.getTool(Tool.ToolType.WATER).getParticleGroupFlags()) {
                drawParticleGroup(currGroup);
            } else {
                mParticleRenderList.add(currGroup);
            }

            currGroup = currGroup.getNext();
        }
    } finally {
        Renderer.getInstance().releaseParticleSystem();
    }

    mWaterParticleMaterial.endRender();

    mRenderSurface[0].endRender();

    mBlurRenderer.draw(mRenderSurface[0].getTexture(), mRenderSurface[0]);
}

From source file:com.kentdisplays.synccardboarddemo.Page.java

/**
 * Encapsulates the OpenGL ES instructions for drawing this page.
 *
 * @param perspective/* w w w  .j  ava 2  s.  c  o m*/
 * @param view
 */
public void draw(float[] perspective, float[] view) {
    mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
    mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
    mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
    mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
    mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");

    // This is not the floor!
    GLES20.glUniform1f(mIsFloorParam, 0f);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModel, 0);

    // Build the ModelView and ModelViewProjection matrices
    // for calculating cube position and light.
    float[] modelView = new float[16];
    float[] modelViewProjection = new float[16];
    Matrix.multiplyMM(modelView, 0, view, 0, mModel, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, modelView, 0);

    // Set the position of the cube
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mPageVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, modelViewProjection, 0);

    // Set the normal positions of the cube, again for shading
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mPageNormals);

    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mPageColors);

    // Animate over all the paths every 30 seconds.
    long time = SystemClock.uptimeMillis() % 30000L;
    int numberOfPathsToDraw = Math.round(mNumberOfPaths / 30000.0f * time);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, numberOfPathsToDraw * 6);
}

From source file:com.google.fpl.liquidfunpaint.ParticleRenderer.java

/**
 * Draw all saved ParticleGroups to temp mRenderSurface[1].
 *//*from  ww  w. j av  a2  s  .c om*/
private void drawNonWaterParticles() {
    // Draw all non-water particles to temp render surface 1
    mRenderSurface[1].beginRender(GLES20.GL_COLOR_BUFFER_BIT);

    mParticleMaterial.beginRender();

    // Set attribute arrays
    mParticleMaterial.setVertexAttributeBuffer("aPosition", mParticlePositionBuffer, 0);
    mParticleMaterial.setVertexAttributeBuffer("aColor", mParticleColorBuffer, 0);

    // Set uniforms
    GLES20.glUniformMatrix4fv(mParticleMaterial.getUniformLocation("uTransform"), 1, false, mTransformFromWorld,
            0);

    ParticleSystem ps = Renderer.getInstance().acquireParticleSystem();
    try {
        // Go through all the particleGroups in the render list
        for (ParticleGroup currGroup : mParticleRenderList) {
            drawParticleGroup(currGroup);
        }
    } finally {
        Renderer.getInstance().releaseParticleSystem();
    }

    mParticleMaterial.endRender();

    mRenderSurface[1].endRender();
    mBlurRenderer.draw(mRenderSurface[1].getTexture(), mRenderSurface[1]);
}

From source file:com.kentdisplays.synccardboarddemo.MainActivity.java

/**
 * Draw the floor. This feeds in data for the floor into the shader. Note that this doesn't
 * feed in data about position of the light, so if we rewrite our code to draw the floor first,
 * the lighting might look strange./*from  ww  w  .  ja  va  2s  .c o  m*/
 */
public void drawFloor(float[] perspective) {
    // This is the floor!
    GLES20.glUniform1f(mIsFloorParam, 1f);

    // Set ModelView, MVP, position, normals, and color
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelFloor, 0);
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mFloorVertices);
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mFloorNormals);
    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mFloorColors);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);

    checkGLError("drawing floor");
}

From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java

/**
 * Draw the cube./*from  www. j a v a 2 s  .  c  o  m*/
 *
 * <p>We've set all of our transformation matrices. Now we simply pass them into the shader.
 */
public void drawCube() {
    GLES20.glUseProgram(cubeProgram);

    GLES20.glUniform3fv(cubeLightPosParam, 1, lightPosInEyeSpace, 0);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(cubeModelParam, 1, false, modelCube, 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(cubeModelViewParam, 1, false, modelView, 0);

    // Set the position of the cube
    GLES20.glVertexAttribPointer(cubePositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, cubeVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(cubeModelViewProjectionParam, 1, false, modelViewProjection, 0);

    // Set the normal positions of the cube, again for shading
    GLES20.glVertexAttribPointer(cubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, cubeNormals);
    GLES20.glVertexAttribPointer(cubeColorParam, 4, GLES20.GL_FLOAT, false, 0,
            isLookingAtObject() ? cubeFoundColors : cubeColors);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
    checkGLError("Drawing cube");
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

/**
 * Draw the rect. We've set all of our transformation matrices. Now we simply pass them into
 * the shader./*from w  w w  .ja va  2  s  . c  om*/
 */
public void drawRect(int texIndex) {
    if (mRectTextureIds[texIndex] < INVALID_TEXTURE) {
        // can't draw this rectangle
        return;
    }

    // This is not the floor!
    GLES20.glUniform1f(mIsFloorParam, 0f);

    // Set the active texture unit
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texIndex);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mRectTextureIds[texIndex]);

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
    GLES20.glUniform1i(mRectTextureUniformParam, texIndex);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelRect[texIndex], 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);

    // Set the position of the rect
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mRectVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);

    // Set the normal positions of the rect, again for shading
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mRectNormals);

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(mRectTextureCoordinateParam, 2, GLES20.GL_FLOAT, false, 0, mRectTexCoords);

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(mRectTextureCoordinateParam);

    if (texIndex == mSelectedTexIndex || isLookingAtObject(texIndex)) {
        GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mRectFoundColors);
    } else {
        GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mRectColors);
    }
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, WorldLayoutData.RECT_COORDS.length / 3); // 3 b/c triangles
    checkGLError("Drawing rect");
}

From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java

public void drawMiniCube() {
    GLES20.glUseProgram(miniCubeProgram);

    GLES20.glUniform3fv(miniCubeLightPosParam, 1, lightPosInEyeSpace, 0);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(miniCubeModelParam, 1, false, modelMiniCube, 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(miniCubeModelViewParam, 1, false, modelView, 0);

    // Set the position of the miniCube
    GLES20.glVertexAttribPointer(miniCubePositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0,
            miniCubeVertices);/*from   w  ww  .j a  va2  s .c  o m*/

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(miniCubeModelViewProjectionParam, 1, false, modelViewProjection, 0);

    // Set the normal positions of the miniCube, again for shading
    GLES20.glVertexAttribPointer(miniCubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, miniCubeNormals);
    GLES20.glVertexAttribPointer(miniCubeColorParam, 4, GLES20.GL_FLOAT, false, 0, miniCubeColors);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
    checkGLError("Drawing miniCube");
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

/**
 * Draw the floor. This feeds in data for the floor into the shader. Note that this doesn't
 * feed in data about position of the light, so if we rewrite our code to draw the floor first,
 * the lighting might look strange./*from w  w  w  .java 2  s. co  m*/
 */
@SuppressWarnings("UnusedParameters")
public void drawFloor(float[] perspective) {
    // This is the floor!
    GLES20.glUniform1f(mIsFloorParam, 1f);

    // Set ModelView, MVP, position, normals, and color
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelFloor, 0);
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mFloorVertices);
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mFloorNormals);
    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mFloorColors);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);

    checkGLError("drawing floor");
}