List of usage examples for android.opengl GLES20 GL_DEPTH_TEST
int GL_DEPTH_TEST
To view the source code for android.opengl GLES20 GL_DEPTH_TEST.
Click Source Link
From source file:com.dmitrybrant.android.cardboardmpo.MainActivity.java
@Override public void onDrawEye(Eye eye) { GLES20.glDisable(GLES20.GL_DEPTH_TEST); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // Apply the eye transformation to the camera. Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0); // TODO: Do something with the head transform (e.g. pan the photo around) // For now, just reset the view matrix, so that the photo is in the center at all times. Matrix.setIdentityM(view, 0);/* w w w .j a v a 2 s .com*/ float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR); if (eye.getType() == 1) { Matrix.multiplyMM(modelView, 0, view, 0, rectLeftEye.getModelMatrix(), 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); rectLeftEye.draw(modelViewProjection); } else { Matrix.multiplyMM(modelView, 0, view, 0, rectRightEye.getModelMatrix(), 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); rectRightEye.draw(modelViewProjection); } }
From source file:com.kentdisplays.synccardboarddemo.MainActivity.java
/** * Creates the buffers we use to store information about the 3D world. OpenGL doesn't use Java * arrays, but rather needs data in a format it can understand. Hence we use ByteBuffers. * @param config The EGL configuration used when creating the surface. *///w ww.j av a 2 s. c om @Override public void onSurfaceCreated(EGLConfig config) { Log.i(TAG, "onSurfaceCreated"); // make a floor ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(DATA.FLOOR_COORDS.length * 4); bbFloorVertices.order(ByteOrder.nativeOrder()); mFloorVertices = bbFloorVertices.asFloatBuffer(); mFloorVertices.put(DATA.FLOOR_COORDS); mFloorVertices.position(0); ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(DATA.FLOOR_NORMALS.length * 4); bbFloorNormals.order(ByteOrder.nativeOrder()); mFloorNormals = bbFloorNormals.asFloatBuffer(); mFloorNormals.put(DATA.FLOOR_NORMALS); mFloorNormals.position(0); ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(DATA.FLOOR_COLORS.length * 4); bbFloorColors.order(ByteOrder.nativeOrder()); mFloorColors = bbFloorColors.asFloatBuffer(); mFloorColors.put(DATA.FLOOR_COLORS); mFloorColors.position(0); int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, R.raw.light_vertex); int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.grid_fragment); mGlProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(mGlProgram, vertexShader); GLES20.glAttachShader(mGlProgram, gridShader); GLES20.glLinkProgram(mGlProgram); GLES20.glEnable(GLES20.GL_DEPTH_TEST); Matrix.setIdentityM(mModelFloor, 0); Matrix.translateM(mModelFloor, 0, 0, -mFloorDepth, 0); // Floor appears below user // Create the placeholder pages. mPages = new Page[4]; mPages[0] = new Page(getResources().openRawResource(R.raw.boogie_board), mGlProgram, 0); mPages[1] = new Page(getResources().openRawResource(R.raw.house), mGlProgram, 1); mPages[2] = new Page(getResources().openRawResource(R.raw.placeholder), mGlProgram, 2); mPages[3] = new Page(getResources().openRawResource(R.raw.cylinder), mGlProgram, 3); checkGLError("onSurfaceCreated"); }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
/** * Creates the buffers we use to store information about the 3D world. OpenGL doesn't use Java * arrays, but rather needs data in a format it can understand. Hence we use ByteBuffers. * * @param config The EGL configuration used when creating the surface. *///w w w. j ava 2 s.c o m @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.RECT_COORDS.length * 4); bbVertices.order(ByteOrder.nativeOrder()); mRectVertices = bbVertices.asFloatBuffer(); mRectVertices.put(WorldLayoutData.RECT_COORDS); mRectVertices.position(0); ByteBuffer bbColors = ByteBuffer.allocateDirect(WorldLayoutData.RECT_COLORS.length * 4); bbColors.order(ByteOrder.nativeOrder()); mRectColors = bbColors.asFloatBuffer(); mRectColors.put(WorldLayoutData.RECT_COLORS); mRectColors.position(0); ByteBuffer bbFoundColors = ByteBuffer.allocateDirect(WorldLayoutData.RECT_FOUND_COLORS.length * 4); bbFoundColors.order(ByteOrder.nativeOrder()); mRectFoundColors = bbFoundColors.asFloatBuffer(); mRectFoundColors.put(WorldLayoutData.RECT_FOUND_COLORS); mRectFoundColors.position(0); ByteBuffer bbNormals = ByteBuffer.allocateDirect(WorldLayoutData.RECT_NORMALS.length * 4); bbNormals.order(ByteOrder.nativeOrder()); mRectNormals = bbNormals.asFloatBuffer(); mRectNormals.put(WorldLayoutData.RECT_NORMALS); mRectNormals.position(0); ByteBuffer bbTextureCoordinates = ByteBuffer.allocateDirect(WorldLayoutData.RECT_TEX_COORDS.length * 4); bbTextureCoordinates.order(ByteOrder.nativeOrder()); mRectTexCoords = bbTextureCoordinates.asFloatBuffer(); mRectTexCoords.put(WorldLayoutData.RECT_TEX_COORDS); mRectTexCoords.position(0); // make a floor ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COORDS.length * 4); bbFloorVertices.order(ByteOrder.nativeOrder()); mFloorVertices = bbFloorVertices.asFloatBuffer(); mFloorVertices.put(WorldLayoutData.FLOOR_COORDS); mFloorVertices.position(0); ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_NORMALS.length * 4); bbFloorNormals.order(ByteOrder.nativeOrder()); mFloorNormals = bbFloorNormals.asFloatBuffer(); mFloorNormals.put(WorldLayoutData.FLOOR_NORMALS); mFloorNormals.position(0); ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COLORS.length * 4); bbFloorColors.order(ByteOrder.nativeOrder()); mFloorColors = bbFloorColors.asFloatBuffer(); mFloorColors.put(WorldLayoutData.FLOOR_COLORS); mFloorColors.position(0); int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, R.raw.light_vertex); int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.flat_fragment); mGlProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(mGlProgram, vertexShader); GLES20.glAttachShader(mGlProgram, gridShader); GLES20.glLinkProgram(mGlProgram); GLES20.glEnable(GLES20.GL_DEPTH_TEST); Matrix.setIdentityM(mModelFloor, 0); Matrix.translateM(mModelFloor, 0, 0, -FLOOR_DEPTH, 0); // Floor appears below user checkGLError("onSurfaceCreated"); }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Draws a frame for an eye./*from w ww . j a v a 2 s.c o m*/ * * @param eye The eye to render. Includes all required transformations. */ @Override public void onDrawEye(Eye eye) { GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); checkGLError("colorParam"); // Apply the eye transformation to the camera. Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0); // Set the position of the light Matrix.multiplyMV(lightPosInEyeSpace, 0, view, 0, LIGHT_POS_IN_WORLD_SPACE, 0); // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR); Matrix.multiplyMM(modelView, 0, view, 0, modelCube, 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); drawCube(); float[] mRotationCube = new float[16]; //Not sure if we can just reuse modelView like this Matrix.multiplyMM(modelView, 0, view, 0, modelMiniCube, 0); //Matrix.multiplyMM(mRotationCube, 0, view, 0, modelView, 0); //Not working //float[] ident = new Matrix(eye.getPerspective(Z_NEAR, Z_FAR)); //Matrix.setIdentityM(ident, 0); //Cheating so that we have relative hand movement //end not working Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); //Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, mRotationCube, 0); //doesn't work :( //Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelMiniCube, 0); drawMiniCube(); // Set modelView for the floor, so we draw floor in the correct location Matrix.multiplyMM(modelView, 0, view, 0, modelFloor, 0); Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0); drawFloor(); }
From source file:com.aimfire.gallery.cardboard.PhotoActivity.java
@Override public void onSurfaceCreated(EGLConfig config) { if (BuildConfig.DEBUG) Log.i(TAG, "onSurfaceCreated"); /*/* w ww . j av a 2 s .c o 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; }