Android Tutorials

The following contains a set of tutorial ports and tutorials of me regarding the Android development.

Apron Android Ports

Stencil Shadows

This tutorial port introduces something important for every 3D application: Shadows. With the help of the stencil buffer you get to draw the shadow of a cube, illuminate by a dynamic light source on a textured floor.
The tutorial source code resembles the structure laid out in the NeHe Ports. Therefore, if you know these you will easily understand the structure and find the changes. The Cube, Light and the Floor classes are just object representations and nearly the same to the NeHe ports. The interesting things are in the StencilShadow class, especially in the OpenGL drawing function and below. In the drawing function you will find the procedures enabling to only draw to the stencil buffer and back. By enabling and drawing the objects to it we draw shadows. How the shadow has to look like is given in the function beneath. It calculates the shadow matrix to draw from the light source.
Changes regarding the original: The changes to the original are that this is a merged tutorial of the Apron with the NeHe basic class structure. Basically the port resembles NeHe, but the drawing logic is taken from Apron into the StencilShadow class.
Controls: The controls are similar to the NeHe ones but converted from the original tutorial to the Touchscreen. What you can do is alter the light source position all by moving on the touchscreen. The directions to move the light source (x, y and z) are represented by areas on the screen. The controls are:

  • Upper Touchscreen: Move the light on the x-axis (left and right)
  • Left Touchscreen: Move the light on the z-axis (back and forth)
  • Rest of the Touchscreen: Move the light on the y-axis (up and down)

Original Stencil Shadows

…more to come…

I hope some of the things posted here can help you during development. If you like it, have questions, are mad at me or you have ideas for improvement, please let me know. The comments are open!

4 thoughts on “Android Tutorials”

  1. Hi,

    Nice tutorials…

    On this one just a remark: on Android the stencil size is 0 by default, so the shadow is not limited by the floor.
    You can see it, if you use white as background color. Then you can define a shadow which overflows the floor.

    With the HTC Magic you have to choose a configuration which enables stencil. With your code I had to put the following line in the StencilShadow constructor (before setRenderer( ) method call) :
    this.setEGLConfigChooser(5, 6, 5, 0, 16, 4);

    PS: with the SDK emulator, none of the EGL configurations are suitable to enable stencil. So no luck for using stencil on the emulator.

  2. Hi

    First of all thank you for the nice and correct remark. But actually, I have it running on my emulator and on my HTC Magic without the EGL configuration. Therefore, maybe there are additional reasons.


  3. Thanks, nice work!

    Next step though, how to cast shadows on objects? I’m trying to draw a city out of white boxes…

  4. Hey man I used some of your code and it’s great! Everything works like a charm. And are you going to be tutoring “Hologram”?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

The Imagination Enhancer