Java Code Examples for com.google.ar.core.Frame#transformDisplayUvCoords()

The following examples show how to use com.google.ar.core.Frame#transformDisplayUvCoords() . 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: BackgroundRenderer.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link Camera#getViewMatrix(float[], int)} and
 * {@link Camera#getProjectionMatrix(float[], int, float, float)} will accurately follow
 * static physical objects.  This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
    // We need to re-query the uv coordinates for the screen rect, as they may have
    // changed as well.
    frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);

    // No need to test or write depth, the screen quad has arbitrary depth, and is expected
    // to be drawn first.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

    // 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, mQuadTexCoordTransformed);

    // 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);

    // Restore the depth state for further drawing.
    GLES20.glDepthMask(true);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 2
Source File: BackgroundRenderer.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
void draw(Frame frame) {
	// If display rotation changed (also includes view size change), we need to re-query the uv
	// coordinates for the screen rect, as they may have changed as well.
	if (frame.hasDisplayGeometryChanged()) {
		frame.transformDisplayUvCoords(quadTexCoord, quadTexCoordTransformed);
	}

	GLES20.glDisable(GLES20.GL_DEPTH_TEST);
	GLES20.glDepthMask(false);

	GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

	GLES20.glUseProgram(quadProgram);

	GLES20.glVertexAttribPointer(
			quadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, quadVertices);

	GLES20.glVertexAttribPointer(
			quadTexCoordParam,
			TEXCOORDS_PER_VERTEX,
			GLES20.GL_FLOAT,
			false,
			0,
			quadTexCoordTransformed);

	GLES20.glEnableVertexAttribArray(quadPositionParam);
	GLES20.glEnableVertexAttribArray(quadTexCoordParam);

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

	GLES20.glDisableVertexAttribArray(quadPositionParam);
	GLES20.glDisableVertexAttribArray(quadTexCoordParam);

	GLES20.glDepthMask(true);
	GLES20.glEnable(GLES20.GL_DEPTH_TEST);
}
 
Example 3
Source File: BackgroundRenderer.java    From amazon-sumerian-arcore-starter-app with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)}
 * and {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects.
 * This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
    // If display rotation changed (also includes view size change), we need to re-query the uv
    // coordinates for the screen rect, as they may have changed as well.
    if (frame.hasDisplayGeometryChanged()) {
        frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
    }

    // No need to test or write depth, the screen quad has arbitrary depth, and is expected
    // to be drawn first.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

    // 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, mQuadTexCoordTransformed);

    // 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);

    // Restore the depth state for further drawing.
    GLES20.glDepthMask(true);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 4
Source File: BackgroundRenderer.java    From react-native-arcore with MIT License 4 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)}
 * and {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects.
 * This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
    // If display rotation changed (also includes view size change), we need to re-query the uv
    // coordinates for the screen rect, as they may have changed as well.
    if (frame.hasDisplayGeometryChanged()) {
        frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
    }

    // No need to test or write depth, the screen quad has arbitrary depth, and is expected
    // to be drawn first.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

    // 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, mQuadTexCoordTransformed);

    // 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);

    // Restore the depth state for further drawing.
    GLES20.glDepthMask(true);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 5
Source File: BackgroundRenderer.java    From poly-sample-android with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image. The image will be drawn such that virtual content rendered with
 * the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)} and
 * {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects. This must be called <b>before</b> drawing virtual
 * content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
  // If display rotation changed (also includes view size change), we need to re-query the uv
  // coordinates for the screen rect, as they may have changed as well.
  if (frame.hasDisplayGeometryChanged()) {
    frame.transformDisplayUvCoords(quadTexCoord, quadTexCoordTransformed);
  }

  // No need to test or write depth, the screen quad has arbitrary depth, and is expected
  // to be drawn first.
  GLES20.glDisable(GLES20.GL_DEPTH_TEST);
  GLES20.glDepthMask(false);

  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

  GLES20.glUseProgram(quadProgram);

  // Set the vertex positions.
  GLES20.glVertexAttribPointer(
      quadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, quadVertices);

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

  // Enable vertex arrays
  GLES20.glEnableVertexAttribArray(quadPositionParam);
  GLES20.glEnableVertexAttribArray(quadTexCoordParam);

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

  // Disable vertex arrays
  GLES20.glDisableVertexAttribArray(quadPositionParam);
  GLES20.glDisableVertexAttribArray(quadTexCoordParam);

  // Restore the depth state for further drawing.
  GLES20.glDepthMask(true);
  GLES20.glEnable(GLES20.GL_DEPTH_TEST);

  ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 6
Source File: BackgroundRenderer.java    From ar-drawing-java with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image.  The image will be drawn such that virtual content rendered
 * with the matrices provided by {@link Frame#getViewMatrix(float[], int)} and
 * {@link Session#getProjectionMatrix(float[], int, float, float)} will accurately follow
 * static physical objects.  This must be called <b>before</b> drawing virtual content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {

    if (frame == null) {
        return;
    }

    // If display rotation changed (also includes view size change), we need to re-query the uv
    // coordinates for the screen rect, as they may have changed as well.
    if (frame.hasDisplayGeometryChanged()) {
        frame.transformDisplayUvCoords(mQuadTexCoord, mQuadTexCoordTransformed);
    }

    // No need to test or write depth, the screen quad has arbitrary depth, and is expected
    // to be drawn first.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);

    GLES20.glUseProgram(mQuadProgram);

    // 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, mQuadTexCoordTransformed);

    // 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);

    // Restore the depth state for further drawing.
    GLES20.glDepthMask(true);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    ShaderUtil.checkGLError(TAG, "Draw");
}
 
Example 7
Source File: BackgroundRenderer.java    From augmentedreality with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the AR background image. The image will be drawn such that virtual content rendered with
 * the matrices provided by {@link com.google.ar.core.Camera#getViewMatrix(float[], int)} and
 * {@link com.google.ar.core.Camera#getProjectionMatrix(float[], int, float, float)} will
 * accurately follow static physical objects. This must be called <b>before</b> drawing virtual
 * content.
 *
 * @param frame The last {@code Frame} returned by {@link Session#update()}.
 */
public void draw(Frame frame) {
  // If display rotation changed (also includes view size change), we need to re-query the uv
  // coordinates for the screen rect, as they may have changed as well.
  if (frame.hasDisplayGeometryChanged()) {
    frame.transformDisplayUvCoords(quadTexCoord, quadTexCoordTransformed);
  }

  // No need to test or write depth, the screen quad has arbitrary depth, and is expected
  // to be drawn first.
  GLES20.glDisable(GLES20.GL_DEPTH_TEST);
  GLES20.glDepthMask(false);

  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);

  GLES20.glUseProgram(quadProgram);

  // Set the vertex positions.
  GLES20.glVertexAttribPointer(
      quadPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, quadVertices);

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

  // Enable vertex arrays
  GLES20.glEnableVertexAttribArray(quadPositionParam);
  GLES20.glEnableVertexAttribArray(quadTexCoordParam);

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

  // Disable vertex arrays
  GLES20.glDisableVertexAttribArray(quadPositionParam);
  GLES20.glDisableVertexAttribArray(quadTexCoordParam);

  // Restore the depth state for further drawing.
  GLES20.glDepthMask(true);
  GLES20.glEnable(GLES20.GL_DEPTH_TEST);

  ShaderUtil.checkGLError(TAG, "Draw");
}