Example usage for android.opengl GLES20 glDrawArrays

List of usage examples for android.opengl GLES20 glDrawArrays

Introduction

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

Prototype

public static native void glDrawArrays(int mode, int first, int count);

Source Link

Usage

From source file:Triangle.java

public void draw() {
    GLES20.glUseProgram(mProgram);/*from w  w w.  jav a  2  s .co  m*/
    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);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}

From source file:Triangle.java

public void draw(float[] mvpMatrix) {
    GLES20.glUseProgram(mProgram);/*from   w  ww  .  j a v  a 2 s  .  co  m*/
    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 w  w.j a v  a2s  .  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

/**
 * Issue the correct draw call for the ParticleGroup that is passed in.
 *///from   w  w  w.j a v a  2s. c  om
private void drawParticleGroup(ParticleGroup pg) {
    // Get the buffer offsets
    int particleCount = pg.getParticleCount();
    int instanceOffset = pg.getBufferIndex();

    // Draw!
    GLES20.glDrawArrays(GLES20.GL_POINTS, instanceOffset, particleCount);
}

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

/**
 * Encapsulates the OpenGL ES instructions for drawing this page.
 *
 * @param perspective//from w w w. ja v a  2  s . co  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.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 . j a  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.//w  w  w .  j  av  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./*  w  ww  .j a v  a  2s.  c  o  m*/
 */
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 w  w . j a  va  2 s  .  co  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 . j ava  2  s. c  o  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");
}