Java Code Examples for android.opengl.GLES20#GL_TRUE

The following examples show how to use android.opengl.GLES20#GL_TRUE . 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: GlShader.java    From VideoCRE with MIT License 6 votes vote down vote up
private static int compileShader(int shaderType, String source) {
  final int shader = GLES20.glCreateShader(shaderType);
  if (shader == 0) {
    throw new RuntimeException("glCreateShader() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  int[] compileStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
  if (compileStatus[0] != GLES20.GL_TRUE) {
    Logging.e(
        TAG, "Could not compile shader " + shaderType + ":" + GLES20.glGetShaderInfoLog(shader));
    throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
  }
  GlUtil.checkNoGLES2Error("compileShader");
  return shader;
}
 
Example 2
Source File: EglElement.java    From Lassi-Android with MIT License 6 votes vote down vote up
protected static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) return 0;
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) return 0;

    int program = GLES20.glCreateProgram();
    check("glCreateProgram");
    if (program == 0) {
        LOG.e("Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    check("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    check("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        LOG.e("Could not link program:", GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 3
Source File: MyGLUtils.java    From poly-sample-android with Apache License 2.0 6 votes vote down vote up
public static int loadShader(int type, String shaderCode) {
  // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
  // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
  int shader = GLES20.glCreateShader(type);

  // add the source code to the shader and compile it
  GLES20.glShaderSource(shader, shaderCode);
  GLES20.glCompileShader(shader);
  MyGLUtils.checkGlError("compile shader");
  int[] status = new int[1];
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, status, 0);
  if (status[0] != GLES20.GL_TRUE) {
    Log.e(TAG, "Shader compile error!");
    Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
  }
  return shader;
}
 
Example 4
Source File: SurfaceTextureRenderer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        // TODO: handle this more gracefully
        throw new IllegalStateException("Could not link program");
    }
    return program;
}
 
Example 5
Source File: EglUtil.java    From media-for-mobile with Apache License 2.0 5 votes vote down vote up
private ShaderProgram createShaderProgram(String vertexSource, String fragmentSource) {
    ShaderProgram shaderProgram = new ShaderProgram(this);
    shaderProgram.create(vertexSource, fragmentSource);

    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(shaderProgram.getProgramHandle(), GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        GLES20.glDeleteProgram(shaderProgram.getProgramHandle());
    }
    return shaderProgram;
}
 
Example 6
Source File: TextureRenderer.java    From AndroidVideoSamples with Apache License 2.0 5 votes vote down vote up
private int createProgram( String vertexSource, String fragmentSource ) {
   int vertexShader = loadShader( GLES20.GL_VERTEX_SHADER, vertexSource );
   if ( vertexShader == 0 ) {
      return 0;
   }
   int pixelShader = loadShader( GLES20.GL_FRAGMENT_SHADER, fragmentSource );
   if ( pixelShader == 0 ) {
      return 0;
   }
   int program = GLES20.glCreateProgram();
   checkGlError( "glCreateProgram" );
   if ( program == 0 ) {
      Log.e( TAG, "Could not create program" );
   }
   GLES20.glAttachShader( program, vertexShader );
   checkGlError( "glAttachShader" );
   GLES20.glAttachShader( program, pixelShader );
   checkGlError( "glAttachShader" );
   GLES20.glLinkProgram( program );
   int[] linkStatus = new int[1];
   GLES20.glGetProgramiv( program, GLES20.GL_LINK_STATUS, linkStatus, 0 );
   if ( linkStatus[0] != GLES20.GL_TRUE ) {
      Log.e( TAG, "Could not link program: " );
      Log.e( TAG, GLES20.glGetProgramInfoLog( program ) );
      GLES20.glDeleteProgram( program );
      program = 0;
   }
   return program;
}
 
Example 7
Source File: GlShader.java    From VideoCRE with MIT License 5 votes vote down vote up
public GlShader(String vertexSource, String fragmentSource) {
  final int vertexShader = compileShader(GLES20.GL_VERTEX_SHADER, vertexSource);
  final int fragmentShader = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
  program = GLES20.glCreateProgram();
  if (program == 0) {
    throw new RuntimeException("glCreateProgram() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glAttachShader(program, vertexShader);
  GLES20.glAttachShader(program, fragmentShader);
  GLES20.glLinkProgram(program);
  int[] linkStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
  if (linkStatus[0] != GLES20.GL_TRUE) {
    Logging.e(TAG, "Could not link program: " + GLES20.glGetProgramInfoLog(program));
    throw new RuntimeException(GLES20.glGetProgramInfoLog(program));
  }
  // According to the documentation of glLinkProgram():
  // "After the link operation, applications are free to modify attached shader objects, compile
  // attached shader objects, detach shader objects, delete shader objects, and attach additional
  // shader objects. None of these operations affects the information log or the program that is
  // part of the program object."
  // But in practice, detaching shaders from the program seems to break some devices. Deleting the
  // shaders are fine however - it will delete them when they are no longer attached to a program.
  GLES20.glDeleteShader(vertexShader);
  GLES20.glDeleteShader(fragmentShader);
  GlUtil.checkNoGLES2Error("Creating GlShader");
}
 
Example 8
Source File: TextureRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = FilterShaders.loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = FilterShaders.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }
    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        return 0;
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 9
Source File: TextureRenderer.java    From SiliCompressor with Apache License 2.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }
    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        return 0;
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 10
Source File: TextureRenderer.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }
    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        return 0;
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 11
Source File: GLToolbox.java    From graphics-samples with Apache License 2.0 5 votes vote down vote up
public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program != 0) {
        GLES20.glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        GLES20.glAttachShader(program, pixelShader);
        checkGlError("glAttachShader");
        GLES20.glLinkProgram(program);
        int[] linkStatus = new int[1];
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus,
                0);
        if (linkStatus[0] != GLES20.GL_TRUE) {
            String info = GLES20.glGetProgramInfoLog(program);
            GLES20.glDeleteProgram(program);
            throw new RuntimeException("Could not link program: " + info);
        }
    }
    return program;
}
 
Example 12
Source File: TextureRenderer.java    From react-native-video-helper with MIT License 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }
    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        return 0;
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 13
Source File: GLToolbox.java    From android-MediaEffects with Apache License 2.0 5 votes vote down vote up
public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program != 0) {
        GLES20.glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        GLES20.glAttachShader(program, pixelShader);
        checkGlError("glAttachShader");
        GLES20.glLinkProgram(program);
        int[] linkStatus = new int[1];
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus,
                0);
        if (linkStatus[0] != GLES20.GL_TRUE) {
            String info = GLES20.glGetProgramInfoLog(program);
            GLES20.glDeleteProgram(program);
            throw new RuntimeException("Could not link program: " + info);
        }
    }
    return program;
}
 
Example 14
Source File: GlUtil.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new program from the supplied vertex and fragment shaders.
 *
 * @return A handle to the program, or 0 on failure.
 */
public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 15
Source File: GlUtil.java    From AndroidPlayground with MIT License 5 votes vote down vote up
/**
 * Creates a new program from the supplied vertex and fragment shaders.
 *
 * @return A handle to the program, or 0 on failure.
 */
public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 16
Source File: GlUtil.java    From FuAgoraDemoDroid with MIT License 5 votes vote down vote up
/**
 * Creates a new program from the supplied vertex and fragment shaders.
 *
 * @return A handle to the program, or 0 on failure.
 */
public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 17
Source File: GlUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static void addShader(int type, String source, int program) {
  int shader = GLES20.glCreateShader(type);
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);

  int[] result = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, result, 0);
  if (result[0] != GLES20.GL_TRUE) {
    throwGlError(GLES20.glGetShaderInfoLog(shader) + ", source: " + source);
  }

  GLES20.glAttachShader(program, shader);
  GLES20.glDeleteShader(shader);
  checkGlError();
}
 
Example 18
Source File: VideoRenderer.java    From alpha-movie with Apache License 2.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program != 0) {
        GLES20.glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        GLES20.glAttachShader(program, pixelShader);
        checkGlError("glAttachShader");
        GLES20.glLinkProgram(program);
        int[] linkStatus = new int[1];
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
        if (linkStatus[0] != GLES20.GL_TRUE) {
            Log.e(TAG, "Could not link program: ");
            Log.e(TAG, GLES20.glGetProgramInfoLog(program));
            GLES20.glDeleteProgram(program);
            program = 0;
        }
    }
    return program;
}
 
Example 19
Source File: ExtractMpegFramesTest_egl14.java    From Android-MediaCodec-Examples with Apache License 2.0 5 votes vote down vote up
private int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}
 
Example 20
Source File: OrientationView.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
@Override
public final void onSurfaceCreated(GL10 unused, EGLConfig config) {
  // Set up shaders
  int vertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
  GLES20.glShaderSource(vertexShader, vertexShaderCode);
  GLES20.glCompileShader(vertexShader);

  int fragmentShader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
  GLES20.glShaderSource(fragmentShader, fragmentShaderCode);
  GLES20.glCompileShader(fragmentShader);

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

  int[] linkStatus = new int[1];
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
  if (linkStatus[0] != GLES20.GL_TRUE) {
    throw new GLException(linkStatus[0],
        "Unable to create shader program: " + GLES20.glGetProgramInfoLog(program));
  }

  // Set up geometry
  // 16 lines * 2 points * XYZ
  float[] boxVertexData = {
      // X-aligned lines of length 4
      -2, -1, -3,  2, -1, -3,
      -2, -1,  3,  2, -1,  3,
      -2,  1, -3,  2,  1, -3,
      -2,  1,  3,  2,  1,  3,
      // Y-aligned lines of length 2
      -2, -1, -3, -2,  1, -3,
      -2, -1,  3, -2,  1,  3,
       2, -1, -3,  2,  1, -3,
       2, -1,  3,  2,  1,  3,
      // Z-aligned lines of length 6
      -2, -1, -3, -2, -1,  3,
      -2,  1, -3, -2,  1,  3,
       2, -1, -3,  2, -1,  3,
       2,  1, -3,  2,  1,  3,
      // Trackpad diamond
      -1,  1, -1,  0,  1,  0,
       0,  1,  0,  1,  1, -1,
       1,  1, -1,  0,  1, -3,
       0,  1, -3, -1,  1, -1,
  };

  ByteBuffer buffer = ByteBuffer.allocateDirect(boxVertexData.length * 4);
  buffer.order(ByteOrder.nativeOrder());
  boxVertices = buffer.asFloatBuffer();
  boxVertices.put(boxVertexData);
  boxVertices.position(0);

  // The XYZ lines are RGB in the positive direction and black in the negative direction.
  // 16 lines * 2 points * RGBA
  float[] boxColorData = {
      // X-aligned lines
      0, 0, 0, 1, 1, 0, 0, 1,
      0, 0, 0, 1, 1, 0, 0, 1,
      0, 0, 0, 1, 1, 0, 0, 1,
      0, 0, 0, 1, 1, 0, 0, 1,
      // Y-aligned lines
      0, 0, 0, 1, 0, 1, 0, 1,
      0, 0, 0, 1, 0, 1, 0, 1,
      0, 0, 0, 1, 0, 1, 0, 1,
      0, 0, 0, 1, 0, 1, 0, 1,
      // Z-aligned lines
      0, 0, 0, 1, 0, 0, 1, 1,
      0, 0, 0, 1, 0, 0, 1, 1,
      0, 0, 0, 1, 0, 0, 1, 1,
      0, 0, 0, 1, 0, 0, 1, 1,
      // Trackpad
      0, 1, 0, 1, 0, 1, 0, 1,
      0, 1, 0, 1, 0, 1, 0, 1,
      0, 1, 0, 1, 0, 1, 0, 1,
      0, 1, 0, 1, 0, 1, 0, 1,
  };
  buffer = ByteBuffer.allocateDirect(boxColorData.length * 4);
  buffer.order(ByteOrder.nativeOrder());
  boxColors = buffer.asFloatBuffer();
  boxColors.put(boxColorData);
  boxColors.position(0);
}