Saturday, October 16, 2010

Silicon Valley Code Camp 2010

Last weekend, I enjoyed lots of technical discussions on various new technologies including Android, Google APIs, HTML 5, Sencha Touch from some of the smartest people in the industry, together with free food and drinks and lots of swags from sponsors. Yes, this was Silicon valley code camp 2010.
It was a two day event, with 9 different tracks and over 190 sessions. The best part was it was totally FREE :) No, the best part was the learning, sharing, discussing, contemplating, questioning ... Did I mention free food? It was a huge success with close to 2000 attendees. It's a big deal because it's entirely run by volunteers.

Today I want to spend a moment to thank all those people who made this code camp a great experience for me. Special thanks to Peter Kellner for the endless hours he put in to make this possible.

I started my Day 1 with Introducing Google APIs Part-I (A-Z & Geo) session. It was quite informative given the vast variety of Google APIs. I found FusionTables very interesting and its integration with Google Maps APIs along with KMLLayer can result in some useful applications.
Then I head over to 'Android: Beyond Basics' session. Well, I was expecting to hear about some advanced topics, he covered the basic building blocks of Android except Activitiy which he had discussed in his first session, Android Basics. After lunch, I was in dilemma whether to attend Dancing with iOS or Sencha Touch. I am glad I chose Sencha Touch. David Kaneda described the Sencha Touch application framework that enables mobile web apps that look and feel native on iPhone and Android touch devices using primarily HTML5, CSS3 & JavaScript. It was like a roller coaster trip through Sencha framework. He touched so many things, it was hard to digest for a beginner like me. But I will mention few things here. David explained Syntactically Awesome Stylesheets (SASS) and the Compass framework and they together lead to more fun with style sheets. He also recommended, use of PhoneGap to prepare the Sencha Touch apps for both Android and iPhone.

Then I attended two more sessions from Google track - Google App Engine and Google Chrome / HTML 5. Both talks were equally engaging. I personally enjoyed Chrome session partly because I am currently working on Chrome OS and I could totally relate to what they were discussing. I was looking forward to day 2 for more talks on HTML 5.

I wanted to attend Do you Mapreduce? but it was clashing with 'Fun with HTML5, CSS3 and JavaScript'. This was really fun. Tab Alkins Jr (Google) coded a game live in front of audience. He covered only Canvas element so my thrust for HTML 5 was not yet satisfied and I went on to yet another HTML5 session - Mobile HTML 5 by Michael Galpin. I have read his articles on developerWorks so it was a nice opportunity to listen to his talk where he gave an detailed overview of HTML5 features. During lunch, there was a raffle with many exciting prizes including xbox which was fun (for those who won).

The session on Building Video Applications with YouTube API by Jarek Wilkiewicz was interesting because I never knew anything about it before. Some amazing statistics: YouTube gets
* 2B views/day
* 150m mobile views/day
* 24 hours of video uploaded/minute

The last session I attended was 'Mapping On The Phone' by Mano Marks from Google. It was an hands on session where he showed how to use GeoLocation feature of HTML5 together with Google Maps APIs.

It was a time for clean-up and I happily volunteered for this activity together with 10 other people. I was a nice feeling. I totally love my SVCC volunteer t-shirt :) My favorite moment was talking with Michael Galpin on video tag acceleration and application catch.

One of the side effects of attending this event is that I ended up opening my twitter account because almost everyone promised to tweet their ppt links!

Sunday, October 3, 2010

OpenGL For Android - GLSurfaceView

One of the fascinating features of Android platform is its support for OpenGL. OpenGL is a cross-platform 2D and 3D rendering graphics library. An industry consortium, called Khronos Group maintains the OpenGL specification.

OpenGL uses C-based flat APIs and hence we need to have a Java language binding to be able to use it with Android Application framework. Java ME has already defined this binding with JSR 231. (Java binding for OpenGL 1.5). What that means for you is - 
import javax.microedition.khronos.opengles.GL10;

Let's get started with the code. 
The main class we use is GLSurfaceView which extends from SurfaceView class. GLSurfaceView
  • Provides a Surface onto which we can render OpenGL scenes
  • Binds with customized Renderer which performs the actual drawing
  • Manages EGL display 
  • Uses a dedicated GUI thread, decouples the main application thread for user interactions
We need to call one method on its object i.e setRenderer() which registers a user specified Renderer object that knows how to draw the desired shapes. 
Activity's onCreate() will look like this - 
    public void onCreate(Bundle savedInstanceState) {
   GLSurfaceView view = new GLSurfaceView(this);
     view.setRenderer(new SimpleRenderer());
The next thing we need is SimpleRenderer which will be responsible for actual OpenGL rendering. It implements GLSurfaceView.Renderer interface and defines its three methods.

public abstract void onSurfaceCreated (GL10 gl, EGLConfig config)

This method is called at the very beginning e.g when a Surface is created or recreated ( when phone awakes after sleep), it's a good place for all initialization code. 

A typical initialization sequence - 
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  // Set the background color to black (RGBA).
  gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
                // enable smooth shading
         // set up depth buffer and enable depth testing
  // use nice perspective calculations.

public abstract void onSurfaceChanged (GL10 gl, int width, int height)

This method is called when the Surface size changes. The size (width, height) affects the aspect ratio so this function should contain the code that depends upon aspect ratio such as GLU.gluPerspective() . A sample code - 
 public void onSurfaceChanged(GL10 gl, int width, int height) {  
  gl.glViewport(0, 0, width, height);
  GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,

public abstract void onDrawFrame (GL10 gl)

This method is called when the current frame is being drawn on the Surface and thus actual drawing code goes here. e.g 

 public void onDrawFrame(GL10 gl) {
  // Clears the color and depth buffer. -- clears the framebuffer
                gl.glTranslatef(0, 0, -5); 
  // Draw our square.
  /* square.draw() */
This code will create a blank frame with black color. We will see the actual drawing code in the part 2. So stay tuned!