Peekaboo

Just for fun, let's make the cube partially transparent. Add this to GLRenderer.onSurfaceCreated():

Download OpenGL/src/org/example/opengl/GLRenderer.java

gl.glDisable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_BLEND);

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);

This turns off depth testing, because we want to see obscured objects as well as foreground ones. It also turns on a blending mode that lets the opacity of objects be based on their alpha (transparency) channel. The net effect is that the back faces of the cube will appear through the front faces. For the final result, see Figure 10.7, on the preceding page.

I'll leave it to you to implement an option to turn that on and off. Try playing around with different blend modes to get cool effects.

0 0

Post a comment