Example usage for android.opengl GLES20 glUseProgram

List of usage examples for android.opengl GLES20 glUseProgram

Introduction

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

Prototype

public static native void glUseProgram(int program);

Source Link

Usage

From source file:Triangle.java

public void draw() {
    GLES20.glUseProgram(mProgram);
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
            vertexBuffer);/*from w  ww  . j  a v  a2s .c o  m*/
    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);
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
            vertexBuffer);//  w w  w  .jav a  2s .  c o m
    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.kentdisplays.synccardboarddemo.MainActivity.java

/**
 * Prepares OpenGL ES before we draw a frame.
 * @param headTransform The head transformation in the new frame.
 *//*from  ww w. ja  v  a2s  .com*/
@Override
public void onNewFrame(HeadTransform headTransform) {
    GLES20.glUseProgram(mGlProgram);
    GLES20.glClearColor(0f, 0f, 0f, 1.0f); // Dark background so text shows up well

    mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
    mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos");
    mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");
    mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
    mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");

    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(mHeadView, 0);

    checkGLError("onReadyToDraw");
}

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

/**
 * Creates the buffers we use to store information about the 3D world.
 *
 * <p>OpenGL doesn't use Java arrays, but rather needs data in a format it can understand.
 * Hence we use ByteBuffers.//from   w  w w.  java  2 s  .co  m
 *
 * @param config The EGL configuration used when creating the surface.
 */
@Override
public void onSurfaceCreated(EGLConfig config) {
    Log.i(TAG, "onSurfaceCreated");
    GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); // Dark background so text shows up well.

    ByteBuffer bbVertices = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_COORDS.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    cubeVertices = bbVertices.asFloatBuffer();
    cubeVertices.put(WorldLayoutData.CUBE_COORDS);
    cubeVertices.position(0);

    ByteBuffer bbColors = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_COLORS.length * 4);
    bbColors.order(ByteOrder.nativeOrder());
    cubeColors = bbColors.asFloatBuffer();
    cubeColors.put(WorldLayoutData.CUBE_COLORS);
    cubeColors.position(0);

    ByteBuffer bbFoundColors = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_FOUND_COLORS.length * 4);
    bbFoundColors.order(ByteOrder.nativeOrder());
    cubeFoundColors = bbFoundColors.asFloatBuffer();
    cubeFoundColors.put(WorldLayoutData.CUBE_FOUND_COLORS);
    cubeFoundColors.position(0);

    ByteBuffer bbNormals = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_NORMALS.length * 4);
    bbNormals.order(ByteOrder.nativeOrder());
    cubeNormals = bbNormals.asFloatBuffer();
    cubeNormals.put(WorldLayoutData.CUBE_NORMALS);
    cubeNormals.position(0);

    ByteBuffer mcbbVertices = ByteBuffer.allocateDirect(WorldLayoutData.MINI_CUBE_COORDS.length * 4);
    mcbbVertices.order(ByteOrder.nativeOrder());
    miniCubeVertices = mcbbVertices.asFloatBuffer();
    miniCubeVertices.put(WorldLayoutData.MINI_CUBE_COORDS);
    miniCubeVertices.position(0);

    ByteBuffer mcbbColors = ByteBuffer.allocateDirect(WorldLayoutData.MINI_CUBE_COLORS.length * 4);
    mcbbColors.order(ByteOrder.nativeOrder());
    miniCubeColors = mcbbColors.asFloatBuffer();
    miniCubeColors.put(WorldLayoutData.MINI_CUBE_COLORS);
    miniCubeColors.position(0);

    ByteBuffer mcbbNormals = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_NORMALS.length * 4);
    mcbbNormals.order(ByteOrder.nativeOrder());
    miniCubeNormals = mcbbNormals.asFloatBuffer();
    miniCubeNormals.put(WorldLayoutData.CUBE_NORMALS);
    miniCubeNormals.position(0);

    // make a floor
    ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COORDS.length * 4);
    bbFloorVertices.order(ByteOrder.nativeOrder());
    floorVertices = bbFloorVertices.asFloatBuffer();
    floorVertices.put(WorldLayoutData.FLOOR_COORDS);
    floorVertices.position(0);

    ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_NORMALS.length * 4);
    bbFloorNormals.order(ByteOrder.nativeOrder());
    floorNormals = bbFloorNormals.asFloatBuffer();
    floorNormals.put(WorldLayoutData.FLOOR_NORMALS);
    floorNormals.position(0);

    ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COLORS.length * 4);
    bbFloorColors.order(ByteOrder.nativeOrder());
    floorColors = bbFloorColors.asFloatBuffer();
    floorColors.put(WorldLayoutData.FLOOR_COLORS);
    floorColors.position(0);

    int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, R.raw.light_vertex);
    int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.grid_fragment);
    int passthroughShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.passthrough_fragment);

    cubeProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(cubeProgram, vertexShader);
    GLES20.glAttachShader(cubeProgram, passthroughShader);
    GLES20.glLinkProgram(cubeProgram);
    GLES20.glUseProgram(cubeProgram);

    checkGLError("Cube program");

    cubePositionParam = GLES20.glGetAttribLocation(cubeProgram, "a_Position");
    cubeNormalParam = GLES20.glGetAttribLocation(cubeProgram, "a_Normal");
    cubeColorParam = GLES20.glGetAttribLocation(cubeProgram, "a_Color");

    cubeModelParam = GLES20.glGetUniformLocation(cubeProgram, "u_Model");
    cubeModelViewParam = GLES20.glGetUniformLocation(cubeProgram, "u_MVMatrix");
    cubeModelViewProjectionParam = GLES20.glGetUniformLocation(cubeProgram, "u_MVP");
    cubeLightPosParam = GLES20.glGetUniformLocation(cubeProgram, "u_LightPos");

    GLES20.glEnableVertexAttribArray(cubePositionParam);
    GLES20.glEnableVertexAttribArray(cubeNormalParam);
    GLES20.glEnableVertexAttribArray(cubeColorParam);

    checkGLError("Cube program params");

    //Minicube
    miniCubeProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(miniCubeProgram, vertexShader);
    GLES20.glAttachShader(miniCubeProgram, passthroughShader);
    GLES20.glLinkProgram(miniCubeProgram);
    GLES20.glUseProgram(miniCubeProgram);

    checkGLError("Cube program");

    miniCubePositionParam = GLES20.glGetAttribLocation(miniCubeProgram, "a_Position");
    miniCubeNormalParam = GLES20.glGetAttribLocation(miniCubeProgram, "a_Normal");
    miniCubeColorParam = GLES20.glGetAttribLocation(miniCubeProgram, "a_Color");

    miniCubeModelParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_Model");
    miniCubeModelViewParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_MVMatrix");
    miniCubeModelViewProjectionParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_MVP");
    miniCubeLightPosParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_LightPos");

    GLES20.glEnableVertexAttribArray(miniCubePositionParam);
    GLES20.glEnableVertexAttribArray(miniCubeNormalParam);
    GLES20.glEnableVertexAttribArray(miniCubeColorParam);

    checkGLError("Cube program params");

    floorProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(floorProgram, vertexShader);
    GLES20.glAttachShader(floorProgram, gridShader);
    GLES20.glLinkProgram(floorProgram);
    GLES20.glUseProgram(floorProgram);

    checkGLError("Floor program");

    floorModelParam = GLES20.glGetUniformLocation(floorProgram, "u_Model");
    floorModelViewParam = GLES20.glGetUniformLocation(floorProgram, "u_MVMatrix");
    floorModelViewProjectionParam = GLES20.glGetUniformLocation(floorProgram, "u_MVP");
    floorLightPosParam = GLES20.glGetUniformLocation(floorProgram, "u_LightPos");

    floorPositionParam = GLES20.glGetAttribLocation(floorProgram, "a_Position");
    floorNormalParam = GLES20.glGetAttribLocation(floorProgram, "a_Normal");
    floorColorParam = GLES20.glGetAttribLocation(floorProgram, "a_Color");

    GLES20.glEnableVertexAttribArray(floorPositionParam);
    GLES20.glEnableVertexAttribArray(floorNormalParam);
    GLES20.glEnableVertexAttribArray(floorColorParam);

    checkGLError("Floor program params");

    Matrix.setIdentityM(modelFloor, 0);
    Matrix.translateM(modelFloor, 0, 0, -floorDepth, 0); // Floor appears below user.

    // Avoid any delays during start-up due to decoding of sound files.
    new Thread(new Runnable() {
        public void run() {
            // Start spatial audio playback of SOUND_FILE at the model postion. The returned
            //soundId handle is stored and allows for repositioning the sound object whenever
            // the cube position changes.
            cardboardAudioEngine.preloadSoundFile(SOUND_FILE);
            soundId = cardboardAudioEngine.createSoundObject(SOUND_FILE);
            cardboardAudioEngine.setSoundObjectPosition(soundId, modelPosition[0], modelPosition[1],
                    modelPosition[2]);
            cardboardAudioEngine.playSound(soundId, true /* looped playback */);
        }
    }).start();

    updateModelPosition();

    checkGLError("onSurfaceCreated");
}

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

/**
 * Prepares OpenGL ES before we draw a frame.
 *
 * @param headTransform The head transformation in the new frame.
 *//*  w  ww .  j  av  a  2s.c  o m*/
@Override
public void onNewFrame(HeadTransform headTransform) {
    GLES20.glUseProgram(mGlProgram);

    mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
    mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos");
    mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");
    mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
    mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
    mRectTextureUniformParam = GLES20.glGetUniformLocation(mGlProgram, "u_Texture");

    // load gif updates into OpenGL
    synchronized (mUpdatingPhotoTextures) {
        while (!mUpdatingPhotoTextures.isEmpty()) {
            PhotoTexture texture = mUpdatingPhotoTextures.remove();
            updateTexture(texture.texIndex, texture.bitmap);
        }
    }

    // load new photos into OpenGL
    synchronized (mWaitingPhotoTextures) {
        // load downloaded photos into OpenGL
        while (!mWaitingPhotoTextures.isEmpty()) {
            PhotoTexture texture = mWaitingPhotoTextures.remove();
            loadTextureInternal(texture.texIndex, texture.bitmap, texture.recycle);

            if (texture.texIndex >= NUM_IMAGES_STATIC) {
                // First image that loads shows up in the "theater!"
                if (mSelectedTexIndex < 0) {
                    mSelectedTexIndex = texture.texIndex;
                    selectPhoto(texture.texIndex - NUM_IMAGES_STATIC);
                } else {
                    // Put image in the right spot
                    unselectPhoto(texture.texIndex - NUM_IMAGES_STATIC);
                }
            } else if (texture.texIndex == STATIC_TEXTURE_ID_REFRESH) {
                placePhoto(mModelRect, mImageRect, texture.texIndex, 1, 180, 30, SPHERE_RADIUS / 2);
            } else if (texture.texIndex == STATIC_TEXTURE_ID_PLAY) {
                placePhoto(mModelRect, mImageRect, texture.texIndex, 1, 210, 30, SPHERE_RADIUS / 2);
            } else if (texture.texIndex == STATIC_TEXTURE_ID_PAUSE) {
                placePhoto(mModelRect, mImageRect, texture.texIndex, 1, 150, 30, SPHERE_RADIUS / 2);
            }
        }
    }

    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(mHeadView, 0);

    checkGLError("onReadyToDraw");
}

From source file:com.aimfire.gallery.cardboard.PhotoActivity.java

@Override
public void onSurfaceCreated(EGLConfig config) {
    if (BuildConfig.DEBUG)
        Log.i(TAG, "onSurfaceCreated");

    /*//from  ww  w  . j a  v a2  s  .co  m
     *  Dark background so text shows up well.
     */
    GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f);

    ByteBuffer bbElements = ByteBuffer.allocateDirect(drawOrder.length * 2);
    bbElements.order(ByteOrder.nativeOrder());
    mPicElements = bbElements.asShortBuffer();
    mPicElements.put(drawOrder);
    mPicElements.position(0);

    int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mPicProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(mPicProgram, vertexShader);
    GLES20.glAttachShader(mPicProgram, fragmentShader);
    GLES20.glLinkProgram(mPicProgram);
    GLES20.glUseProgram(mPicProgram);

    checkGLError("Pic program");

    mDimRatioParam = GLES20.glGetUniformLocation(mPicProgram, "u_dimRatio");
    mZoomParam = GLES20.glGetUniformLocation(mPicProgram, "u_zoom");
    mParallaxParam = GLES20.glGetUniformLocation(mPicProgram, "u_parallax");

    mPicPositionParam = GLES20.glGetAttribLocation(mPicProgram, "a_position");

    GLES20.glEnableVertexAttribArray(mPicPositionParam);
    checkGLError("Pic program params");

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    checkGLError("onSurfaceCreated");

    /*
     * initializes a few textures (current, previous and next). we have to do this
     * here (as opposed to onCreate) as gl context is only available here
     */
    initTextures();

    /*
     * so onDrawEye will know to draw
     */
    mAssetChangedLeft = mAssetChangedRight = true;
}

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

/**
 * Draw the cube.//from  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.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 ww w  . j a  va  2s .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.sveder.cardboardpassthrough.MainActivity.java

/**
 * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as
 * a parameter.// w  ww . j  a v  a 2s. c  o  m
 * @param transform The transformations to apply to render this eye.
 */
@Override
public void onDrawEye(EyeTransform transform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);

    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
            vertexBuffer);

    mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate");
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);
    GLES20.glVertexAttribPointer(mTextureCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
            textureVerticesBuffer);

    mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture");

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordHandle);

    Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);

    //        mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    //        mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    //        mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
    //
    //        GLES20.glEnableVertexAttribArray(mPositionParam);
    //        GLES20.glEnableVertexAttribArray(mNormalParam);
    //        GLES20.glEnableVertexAttribArray(mColorParam);
    //        checkGLError("mColorParam");
    //
    //        // Apply the eye transformation to the camera.
    //        Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
    //
    //        // Set the position of the light
    //        Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0);
    //        GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1],
    //                mLightPosInEyeSpace[2]);
    //
    //        // Build the ModelView and ModelViewProjection matrices
    //        // for calculating cube position and light.
    //        Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0);
    //        Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0);
    //        drawCube();
    //
    //        // Set mModelView for the floor, so we draw floor in the correct location
    //        Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
    //        Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0,
    //            mModelView, 0);
    //        drawFloor(transform.getPerspective());
}

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

/**
 * Draw the floor.//from w w  w . j  a v a2s.  co  m
 *
 * <p>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.
 */
public void drawFloor() {
    GLES20.glUseProgram(floorProgram);

    // Set ModelView, MVP, position, normals, and color.
    GLES20.glUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0);
    GLES20.glUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0);
    GLES20.glUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0);
    GLES20.glUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0);
    GLES20.glVertexAttribPointer(floorPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0,
            floorVertices);
    GLES20.glVertexAttribPointer(floorNormalParam, 3, GLES20.GL_FLOAT, false, 0, floorNormals);
    GLES20.glVertexAttribPointer(floorColorParam, 4, GLES20.GL_FLOAT, false, 0, floorColors);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);

    checkGLError("drawing floor");
}