onsdag 28 november 2012

OpenGL ES 2.0 with Android and something about Virtual Buffer Objects (VBO)

Feels great to go back to university studies after a summer hiatus! In this post I'm playing around with OpenGL or more specific OpenGL ES 2.0 which is a subset of OpenGL for embedded systems. OpenGL and computer graphics is a quite daunting topic to delve into, but I'm dissecting it bit for bit...

I did put together this demo Android application just to see some basic stuff like translating, scaling and rotating in action.

OpenGL ES Demo




















How to create and use Virtual Buffer Objects (VBOs) under Android.

Beginning with Android 2.2 (API Level 8), the framework supports the OpenGL ES 2.0 API specification according to the documentation but API Level 8 seems to be missing some functions in order to use VBOs so make sure that you are using at least API Level 9.


initialize phase

float[] data = {...};
FloatBuffer dataBuffer = FloatBuffer.wrap(data);

// create the buffer object and get a handle to it
IntBuffer buffer = IntBuffer.allocate(1);
GLES20.glGenBuffers(1, buffer);
int bufferObject = buffer.get(0);

// bind bufferObject to the GL_ARRAY_BUFFER
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferObject);
// allocates memory and copy data over to OpenGL memory 
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, data.length * 4, dataBuffer, GLES20.GL_STATIC_DRAW);
// cleanup 
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);


rendering phase


GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferObject);

GLES20.glEnableVertexAttribArray(...);

GLES20.glVertexAttribPointer(...);

GLES20.glDrawArrays(...);


onsdag 7 november 2012

Fridge

A small prototype app I made for a course project. I kinda let you manage your food items in your refrigerator with an expiration date and food quality warning system.