@Override public void onSurfaceCreated(EGLConfig config){
  Log.i(TAG,"onSurfaceCreated");
  GLES20.glClearColor(0.1f,0.1f,0.1f,0.5f);
  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 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");
  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);
  updateModelPosition();
  mVideoRenderer=new VideoRenderer(this);
  mVideoRenderer.setup();
  mVideoRenderer.start();
  Matrix.setIdentityM(videoScreenModelMatrix,0);
  float screenSize=2;
  float aspectRatio=16f / 9f;
  Matrix.scaleM(videoScreenModelMatrix,0,screenSize,screenSize / aspectRatio,1);
  Matrix.translateM(videoScreenModelMatrix,0,0.0f,0.0f,-4.0f);
  checkGLError("onSurfaceCreated");
}

@ Override public void onSurfaceCreated ( EGLConfig config ) { Log . i ( TAG , "onSurfaceCreated" ) ; GLES20 . glClearColor ( 0.1f , 0.1f , 0.1f , 0.5f ) ; 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 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" ) ; 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 ) ; updateModelPosition ( ) ; mVideoRenderer = new VideoRenderer ( this ) ; mVideoRenderer . setup ( ) ; mVideoRenderer . start ( ) ; Matrix . setIdentityM ( videoScreenModelMatrix , 0 ) ; float screenSize = 2 ; float aspectRatio = 16f / 9f ; Matrix . scaleM ( videoScreenModelMatrix , 0 , screenSize , screenSize / aspectRatio , 1 ) ; Matrix . translateM ( videoScreenModelMatrix , 0 , 0.0f , 0.0f , - 4.0f ) ; checkGLError ( "onSurfaceCreated" ) ; }
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 .
