Faces are drawn in order they are defined. Now as cube is rotated their draw order is not changed. Some faces are drawn close to camera first. Then some face is drawn after that, but Z-test says that there already is a pixel closer to the camera so no drawing needs to be done.
Problem here is that OpenGL|ES 2.0 does not sort faces when they are rendered. Handling transparency and depth correctly remains as a real challenge in 3D programming, but for easy case like this, you can just sort the faces back to front. Drawing back to front is called "Painter's algorithm" and sorting is called "depth sorting" or "z-sorting".
Simple, definetly not best and surely inefficient way might work like this:
- Calculate center vertex of the face
by calculating average of three
vertices
- Project them to screen space by transforming them through camera (view+projection) and possible model-matrices
- Sort their Z-values by some sort algorithm
- Build vertex buffer with vertices in this order or just rewrite index buffer in new order (less stuff to move around if vertices are not changed)
- Render cube as usual
There are better ways to handle this problem and there all kinds of advanced optimizations out there. But I didn't found any tutorial to cover simple case like this. Perhaps I just didn't found right keywords.