Java Code Examples for android.opengl.Matrix#multiplyMM()

The following examples show how to use android.opengl.Matrix#multiplyMM() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlaneRenderer.java    From react-native-arcore with MIT License 6 votes vote down vote up
private void draw(float[] cameraView, float[] cameraPerspective) {
    // Build the ModelView and ModelViewProjection matrices
    // for calculating cube position and light.
    Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0);
    Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0);

    // Set the position of the plane
    mVertexBuffer.rewind();
    GLES20.glVertexAttribPointer(
        mPlaneXZPositionAlphaAttribute, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
        BYTES_PER_FLOAT * COORDS_PER_VERTEX, mVertexBuffer);

    // Set the Model and ModelViewProjection matrices in the shader.
    GLES20.glUniformMatrix4fv(mPlaneModelUniform, 1, false, mModelMatrix, 0);
    GLES20.glUniformMatrix4fv(
        mPlaneModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0);

    mIndexBuffer.rewind();
    GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, mIndexBuffer.limit(),
        GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
    ShaderUtil.checkGLError(TAG, "Drawing plane");
}
 
Example 2
Source File: SphereReflector.java    From Fatigue-Detection with MIT License 6 votes vote down vote up
@Override
public void onDrawFrame(int textureId) {
    super.onDrawFrame(textureId);
    glSphereProgram.use();
    sphere.uploadTexCoordinateBuffer(glSphereProgram.getTextureCoordinateHandle());
    sphere.uploadVerticesBuffer(glSphereProgram.getPositionHandle());

    Matrix.perspectiveM(projectionMatrix, 0, 90, ratio, 1f, 500f);

    Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0);
    Matrix.multiplyMM(mMVPMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0);

    GLES20.glUniformMatrix4fv(glSphereProgram.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0);

    TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSphereProgram.getTextureSamplerHandle(),0);

    sphere.draw();
}
 
Example 3
Source File: PointCloudRenderer.java    From justaline-android with Apache License 2.0 6 votes vote down vote up
/**
     * Renders the point cloud. ArCore point cloud is given in world space.
     *
     * @param cameraView        the camera view matrix for this frame, typically from {@link
     *                          com.google.ar.core.Camera#getViewMatrix(float[], int)}.
     * @param cameraPerspective the camera projection matrix for this frame, typically from {@link
     *                          com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)}.
     */
    public void draw(float[] cameraView, float[] cameraPerspective) {
        float[] modelViewProjection = new float[16];
        Matrix.multiplyMM(modelViewProjection, 0, cameraPerspective, 0, cameraView, 0);

        ShaderUtil.checkGLError(TAG, "Before draw");
        GLES20.glUseProgram(programName);
        GLES20.glEnableVertexAttribArray(positionAttribute);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
        GLES20.glVertexAttribPointer(positionAttribute, 4, GLES20.GL_FLOAT, false, BYTES_PER_POINT, 0);
//    GLES20.glUniform4f(colorUniform, 31.0f / 255.0f, 188.0f / 255.0f, 210.0f / 255.0f, 1.0f);
        GLES20.glUniform4f(colorUniform, 1.0f, 1.0f, 1.0f, 1.0f);
        GLES20.glUniformMatrix4fv(modelViewProjectionUniform, 1, false, modelViewProjection, 0);
        GLES20.glUniform1f(pointSizeUniform, 8.0f);

        GLES20.glDrawArrays(GLES20.GL_POINTS, 0, numPoints);
        GLES20.glDisableVertexAttribArray(positionAttribute);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

        ShaderUtil.checkGLError(TAG, "Draw");
    }
 
Example 4
Source File: DisplayTransformManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the composition of all current color matrices, or {@code null} if there are none.
 */
@GuardedBy("mColorMatrix")
private float[] computeColorMatrixLocked() {
    final int count = mColorMatrix.size();
    if (count == 0) {
        return null;
    }

    final float[][] result = mTempColorMatrix;
    Matrix.setIdentityM(result[0], 0);
    for (int i = 0; i < count; i++) {
        float[] rhs = mColorMatrix.valueAt(i);
        Matrix.multiplyMM(result[(i + 1) % 2], 0, result[i % 2], 0, rhs, 0);
    }
    return result[count % 2];
}
 
Example 5
Source File: MyGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    float[] scratch = new float[16];

    // Draw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

    // Draw square
    mSquare.draw(mMVPMatrix);

    // Create a rotation for the triangle

    // Use the following code to generate constant rotation.
    // Leave this code out when using TouchEvents.
    // long time = SystemClock.uptimeMillis() % 4000L;
    // float angle = 0.090f * ((int) time);

    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, 1.0f);

    // Combine the rotation matrix with the projection and camera view
    // Note that the mMVPMatrix factor *must be first* in order
    // for the matrix multiplication product to be correct.
    Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0);

    // Draw triangle
    mTriangle.draw(scratch);
}
 
Example 6
Source File: GLESCamera.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
public static void updateFrustum(float[] projectionMatrix,
		float[] viewMatrix) {
	float[] projectionViewMatrix = new float[16];
	float[] invertPVMatrix = new float[16];
	Matrix.multiplyMM(projectionViewMatrix, 0, projectionMatrix, 0,
			viewMatrix, 0);
	Matrix.invertM(invertPVMatrix, 0, projectionViewMatrix, 0);

	for (int i = 0; i < 8; i++) {
		float[] point = Arrays.copyOf(clipSpace[i], 3);

		float rw = point[0] * invertPVMatrix[3] + point[1]
				* invertPVMatrix[7] + point[2] * invertPVMatrix[11]
				+ invertPVMatrix[15];

		planePoints[i] = clipSpace[i];

		float[] newPlanePoints = new float[3];
		newPlanePoints[0] = (point[0] * invertPVMatrix[0] + point[1]
				* invertPVMatrix[4] + point[2] * invertPVMatrix[8] + invertPVMatrix[12])
				/ rw;
		newPlanePoints[1] = (point[0] * invertPVMatrix[1] + point[1]
				* invertPVMatrix[5] + point[2] * invertPVMatrix[9] + invertPVMatrix[13])
				/ rw;
		newPlanePoints[2] = (point[0] * invertPVMatrix[2] + point[1]
				* invertPVMatrix[6] + point[2] * invertPVMatrix[10] + invertPVMatrix[14])
				/ rw;
		planePoints[i] = newPlanePoints;
	}

	frustumPlanes[0].set(planePoints[1], planePoints[0], planePoints[2]);
	frustumPlanes[1].set(planePoints[4], planePoints[5], planePoints[7]);
	frustumPlanes[2].set(planePoints[0], planePoints[4], planePoints[3]);
	frustumPlanes[3].set(planePoints[5], planePoints[1], planePoints[6]);
	frustumPlanes[4].set(planePoints[2], planePoints[3], planePoints[6]);
	frustumPlanes[5].set(planePoints[4], planePoints[0], planePoints[1]);
}
 
Example 7
Source File: Sprite2d.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the rectangle with the supplied program and projection matrix.
 */
public void draw(FlatShadedProgram program, float[] projectionMatrix) {
    // Compute model/view/projection matrix.
    Matrix.multiplyMM(mScratchMatrix, 0, projectionMatrix, 0, getModelViewMatrix(), 0);

    program.draw(mScratchMatrix, mColor, mDrawable.getVertexArray(), 0,
            mDrawable.getVertexCount(), mDrawable.getCoordsPerVertex(),
            mDrawable.getVertexStride());
}
 
Example 8
Source File: ImageRenderer.java    From ARCore-Location with MIT License 5 votes vote down vote up
public void draw(float[] cameraView, float[] cameraPerspective) {
    ShaderUtil.checkGLError(TAG, "Before draw");
    Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0);
    Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0);

    GLES20.glUseProgram(mQuadProgram);

    // Attach the object texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
    GLES20.glUniform1i(mTextureUniform, 0);
    GLES20.glUniformMatrix4fv(mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0);
    // Set the vertex positions.
    GLES20.glVertexAttribPointer(
            mQuadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mQuadVertices);

    // Set the texture coordinates.
    GLES20.glVertexAttribPointer(
            mQuadTexCoordParam, TEXCOORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mQuadTexCoord);

    // Enable vertex arrays
    GLES20.glEnableVertexAttribArray(mQuadPositionParam);
    GLES20.glEnableVertexAttribArray(mQuadTexCoordParam);

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

    // Disable vertex arrays
    GLES20.glDisableVertexAttribArray(mQuadPositionParam);
    GLES20.glDisableVertexAttribArray(mQuadTexCoordParam);

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    ShaderUtil.checkGLError(TAG, "After draw");
}
 
Example 9
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rotate(float angle, float x, float y, float z) {
    if (angle == 0f) {
        return;
    }
    float[] temp = mTempMatrix;
    Matrix.setRotateM(temp, 0, angle, x, y, z);
    float[] matrix = mMatrices;
    int index = mCurrentMatrixIndex;
    Matrix.multiplyMM(temp, MATRIX_SIZE, matrix, index, temp, 0);
    System.arraycopy(temp, MATRIX_SIZE, matrix, index, MATRIX_SIZE);
}
 
Example 10
Source File: GLES20Canvas.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public void multiplyMatrix(float[] matrix, int offset) {
    float[] temp = mTempMatrix;
    float[] currentMatrix = mMatrices;
    int index = mCurrentMatrixIndex;
    Matrix.multiplyMM(temp, 0, currentMatrix, index, matrix, offset);
    System.arraycopy(temp, 0, currentMatrix, index, 16);
}
 
Example 11
Source File: MainActivity.java    From Cardboard with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as
 * a parameter.
 * @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);

    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());
}
 
Example 12
Source File: Sprite2d.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the rectangle with the supplied program and projection matrix.
 */
public void draw(Texture2dProgram program, float[] projectionMatrix) {
    // Compute model/view/projection matrix.
    Matrix.multiplyMM(mScratchMatrix, 0, projectionMatrix, 0, getModelViewMatrix(), 0);

    program.draw(mScratchMatrix, mDrawable.getVertexArray(), 0,
            mDrawable.getVertexCount(), mDrawable.getCoordsPerVertex(),
            mDrawable.getVertexStride(), GlUtil.IDENTITY_MATRIX, mDrawable.getTexCoordArray(),
            mTextureId, mDrawable.getTexCoordStride());
}
 
Example 13
Source File: MatrixUtils.java    From ZGDanmaku with Apache License 2.0 5 votes vote down vote up
/**
 * 获取具体物体的总变换矩阵
 *
 * @return
 */
public static float[] getFinalMatrix() {
    mFinalMatrix = new float[16];
    Matrix.multiplyMM(mFinalMatrix, 0, mCameraMatrix, 0, mTranslateMatrix, 0);
    Matrix.multiplyMM(mFinalMatrix, 0, mProjectMatrix, 0, mFinalMatrix, 0);
    return mFinalMatrix;
}
 
Example 14
Source File: DebugMeshShaderRenderer.java    From justaline-android with Apache License 2.0 4 votes vote down vote up
/**
     * This method takes in the current CameraView Matrix and the Camera's Projection Matrix, the
     * current position and pose of the device, uses those to calculate the ModelViewMatrix and
     * ModelViewProjectionMatrix.  It binds the VBO, enables the custom attribute locations,
     * binds and uploads the shader uniforms, calls our single DrawArray call, and finally disables
     * and unbinds the shader attributes and VBO.
     */
    public void draw(float[] cameraView, float[] cameraPerspective, float screenWidth, float screenHeight, float nearClip, float farClip) {


        Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0);
        Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0);

        ShaderUtil.checkGLError(TAG, "Before draw");

        GLES20.glUseProgram(mProgramName);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);
        GLES20.glVertexAttribPointer(
                mPositionAttribute, FLOATS_PER_POINT, GLES20.GL_FLOAT, false, BYTES_PER_POINT, mPositionAddress);
        GLES20.glVertexAttribPointer(
                mPreviousAttribute, FLOATS_PER_POINT, GLES20.GL_FLOAT, false, BYTES_PER_POINT, mPreviousAddress);
        GLES20.glVertexAttribPointer(
                mNextAttribute, FLOATS_PER_POINT, GLES20.GL_FLOAT, false, BYTES_PER_POINT, mNextAddress);
        GLES20.glVertexAttribPointer(
                mSideAttribute, 1, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT, mSideAddress);
        GLES20.glVertexAttribPointer(
                mWidthAttribte, 1, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT, mWidthAddress);
        GLES20.glVertexAttribPointer(
                mCountersAttribute, 1, GLES20.GL_FLOAT, false, BYTES_PER_FLOAT, mCounterAddress);
        GLES20.glUniformMatrix4fv(
                mModelViewUniform, 1, false, mModelViewMatrix, 0);
        GLES20.glUniformMatrix4fv(
                mProjectionUniform, 1, false, cameraPerspective, 0);

        GLES20.glUniform2f(mResolutionUniform, screenWidth, screenHeight);
        GLES20.glUniform3f(mColorUniform, mColor.x, mColor.y, mColor.z);
        GLES20.glUniform1f(mOpacityUniform, 1.0f);
        GLES20.glUniform1f(mNearUniform, nearClip);
        GLES20.glUniform1f(mFarUniform, farClip);
        GLES20.glUniform1f(mSizeAttenuationUniform, 1.0f);
        GLES20.glUniform1f(mVisibility, 1.0f);
        GLES20.glUniform1f(mAlphaTest, 1.0f);
        GLES20.glUniform1f(mDrawModeUniform, mDrawMode ? 1.0f : 0.0f);
        GLES20.glUniform1f(mNearCutoffUniform, mDrawDistance - 0.0075f);
        GLES20.glUniform1f(mFarCutoffUniform, mDrawDistance + 0.0075f);
        GLES20.glUniform1f(mLineDepthScaleUniform, mLineDepthScale);

        GLES20.glEnableVertexAttribArray(mPositionAttribute);
        GLES20.glEnableVertexAttribArray(mPreviousAttribute);
        GLES20.glEnableVertexAttribArray(mNextAttribute);
        GLES20.glEnableVertexAttribArray(mSideAttribute);
        GLES20.glEnableVertexAttribArray(mWidthAttribte);
        GLES20.glEnableVertexAttribArray(mCountersAttribute);

//        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mNumBytes);
        GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, mNumBytes);


        GLES20.glDisableVertexAttribArray(mCountersAttribute);
        GLES20.glDisableVertexAttribArray(mWidthAttribte);
        GLES20.glDisableVertexAttribArray(mSideAttribute);
        GLES20.glDisableVertexAttribArray(mNextAttribute);
        GLES20.glDisableVertexAttribArray(mPreviousAttribute);
        GLES20.glDisableVertexAttribArray(mPositionAttribute);


        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    }
 
Example 15
Source File: OrientationView.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
@Override
public final void onDrawFrame(GL10 unused) {
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
  GLES20.glUseProgram(program);

  // Set up camera.
  Matrix.setIdentityM(tmpMatrix1, 0);

  // Convert world space to head space.
  Matrix.translateM(tmpMatrix1, 0, 0, 0, -VIEW_SIZE);
  Matrix.multiplyMM(tmpMatrix2, 0, tmpMatrix1, 0, phoneInWorldSpaceMatrix, 0);

  // Phone's Z faces up. We need it to face toward the user.
  Matrix.rotateM(tmpMatrix2, 0, 90, 1, 0, 0);

  if (startFromSensorTransformation != null) {
    // Compensate for the yaw by rotating in the other direction.
    Matrix.rotateM(tmpMatrix2, 0, -startFromSensorTransformation[0], 0, 1, 0);
  } // Else we're in a transient state between a resetYaw call and an onSensorChanged call.

  // Convert object space to world space.
  if (controller != null) {
    controller.update();
    controller.orientation.toRotationMatrix(controllerInStartSpaceMatrix);
  }
  Matrix.multiplyMM(tmpMatrix1, 0, tmpMatrix2, 0, controllerInStartSpaceMatrix, 0);

  // Set mvpMatrix.
  int mvp = GLES20.glGetUniformLocation(program, "uMvpMatrix");
  Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, tmpMatrix1, 0);
  GLES20.glUniformMatrix4fv(mvp, 1, false, mvpMatrix, 0);

  // Draw.
  int position = GLES20.glGetAttribLocation(program, "aPosition");
  GLES20.glVertexAttribPointer(position, 3, GLES20.GL_FLOAT, false, 0, boxVertices);
  GLES20.glEnableVertexAttribArray(position);

  int color = GLES20.glGetAttribLocation(program, "aColor");
  GLES20.glVertexAttribPointer(color, 4, GLES20.GL_FLOAT, false, 0, boxColors);
  GLES20.glEnableVertexAttribArray(color);

  GLES20.glDrawArrays(GLES20.GL_LINES, 0, vertexCount);
  GLES20.glDisableVertexAttribArray(position);
  GLES20.glDisableVertexAttribArray(color);
}
 
Example 16
Source File: GlPreviewRenderer.java    From CameraRecorder-android with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GLES20FramebufferObject fbo) {

    // ここのタイミングで以前指定したscaleを
    if (drawScale != gestureScale) {

        float tempScale = 1 / drawScale;
        Matrix.scaleM(MMatrix, 0, tempScale, tempScale, 1);
        drawScale = gestureScale;
        Matrix.scaleM(MMatrix, 0, drawScale, drawScale, 1);
    }

    synchronized (this) {
        if (updateTexImageCompare != updateTexImageCounter) {
            // loop and call updateTexImage() for each time the onFrameAvailable() method was called below.
            while (updateTexImageCompare != updateTexImageCounter) {

                previewTexture.updateTexImage();
                previewTexture.getTransformMatrix(STMatrix);
                updateTexImageCompare++;  // increment the compare value until it's the same as _updateTexImageCounter
            }
        }

    }

    if (isNewShader) {
        if (glFilter != null) {
            glFilter.setup();
            glFilter.setFrameSize(fbo.getWidth(), fbo.getHeight());
        }
        isNewShader = false;
    }

    if (glFilter != null) {
        filterFramebufferObject.enable();
    }

    GLES20.glClear(GL_COLOR_BUFFER_BIT);

    Matrix.multiplyMM(MVPMatrix, 0, VMatrix, 0, MMatrix, 0);
    Matrix.multiplyMM(MVPMatrix, 0, ProjMatrix, 0, MVPMatrix, 0);

    previewShader.draw(texName, MVPMatrix, STMatrix, aspectRatio);


    if (glFilter != null) {
        fbo.enable();
        GLES20.glClear(GL_COLOR_BUFFER_BIT);
        glFilter.draw(filterFramebufferObject.getTexName(), fbo);
    }

    synchronized (this) {
        if (videoEncoder != null) {
            // notify to capturing thread that the camera frame is available.
            videoEncoder.frameAvailableSoon(texName, STMatrix, MVPMatrix, aspectRatio);
        }
    }

}
 
Example 17
Source File: MatrixStack.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
public void glRotatef(float angle, float x, float y, float z) {
    Matrix.setRotateM(mTemp, 0, angle, x, y, z);
    System.arraycopy(mMatrix, mTop, mTemp, MATRIX_SIZE, MATRIX_SIZE);
    Matrix.multiplyMM(mMatrix, mTop, mTemp, MATRIX_SIZE, mTemp, 0);
}
 
Example 18
Source File: GLMatrixStack.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void glSkewf(final float pSkewX, final float pSkewY) {
	GLMatrixStack.setSkewM(this.mTemp, 0, pSkewX, pSkewY);
	System.arraycopy(this.mMatrixStack, this.mMatrixStackOffset, this.mTemp, GLMatrixStack.GLMATRIX_SIZE, GLMatrixStack.GLMATRIX_SIZE);
	Matrix.multiplyMM(this.mMatrixStack, this.mMatrixStackOffset, this.mTemp, GLMatrixStack.GLMATRIX_SIZE, this.mTemp, 0);
}
 
Example 19
Source File: GLState.java    From tilt-game-android with MIT License 4 votes vote down vote up
public float[] getModelViewProjectionGLMatrix() {
	Matrix.multiplyMM(this.mModelViewProjectionGLMatrix, 0, this.mProjectionGLMatrixStack.mMatrixStack, this.mProjectionGLMatrixStack.mMatrixStackOffset, this.mModelViewGLMatrixStack.mMatrixStack, this.mModelViewGLMatrixStack.mMatrixStackOffset);
	return this.mModelViewProjectionGLMatrix;
}
 
Example 20
Source File: GLLabel.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context)
{
  Data data = dataProvider.get();
  Vector3 color = data.colorCoefficients;
  ShaderLabel shader = (ShaderLabel)Shader.getCurrent();

  // get dynamic resources
  Geometry geometryData = GameContext.resources.getGeometry(new LabelGeometrySource(data.value, data.mode, data.charWidth, data.charHeight));

  // build result matrix
  Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1);

  // set buffer or reset if dynamic
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  switch (geometryData.getMode())
  {
  case Static:
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8);
    break;

  case Dynamic:
    FloatBuffer buffer = geometryData.getData();
    buffer.position(0);
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    buffer.position(2);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    break;
  }

  // enable arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);

  // release dynamic resources
  GameContext.resources.release(geometryData);
}