Skip to content
Archive of entries posted on October 2008

Utilizing multimedia keys on N95

I just took an example from forum nokia example. Currently it seems that, the example isn’t working. The volume keys are working just fine, but the program is unable to catch other media key events.

Therefore I downloaded Magic keys. The problem with Magic keys is that it requires “ALL -TCB” capabilities, so the platform security must be hacked to use it. I’m not telling how to do it in here, but you will find the instruction with google, if interested. I remapped the multimedia keys to buttons 1, 2, 3 and 4. So now I can control the Snes as I originally planned. I will probably also port this to the S60 5.0 with the touch UI, so I’m not going to implement my own key handler for multimedia keys, unless I get an example that really works.

I started to wonder how the magic keys are implemented, since it requires platform security hack. I’m quite sure, that the Magic keys application is a FEP (Front End Processor) for the window server. It will get all the key events from a window server first, and then it will forward the events into other applications. Implementing my own FEP also sounds like a nice idea, but I want to have my own app running without having to hack the phone.

Rendering frames with OpenGL ES

The OpenGL ES frameworks expect to have image size to be powers of two. Therefore we create 256×256 frame and then create our image into it as a sub frame.

Here is an example of opengl es init function.

#include "OpenGLES.h"
_LIT( KTESTDATASNES, "c:\\Data\\test_data\\test_565.mbm");
_LIT( KTESTDATA256x239, "c:\\Data\\test_data\\test_256x239.mbm");
static GLuint    texture;
static GLint format;
static GLint type;
static GLuint textures [2];
static EGLDisplay g_EglDisplay;
static EGLSurface g_EglSurface;

static CFbsBitmap* iBitmap;

void InitializeOpenGLES(EGLDisplay aDisplay, EGLSurface aSurface)
{    {
iBitmap = new (ELeave) CFbsBitmap();
TInt error = iBitmap->Load( KTESTDATA256x239, 0 );
TDisplayMode mode = iBitmap->DisplayMode();
if( mode == EColor64K )
// 64k maps to RGB565, which we will use as opengl es texture,
RDebug::Print(_L("Colour mode is correct"));

RDebug::Print(_L("ConstructL complete"));
g_EglDisplay = aDisplay;
g_EglSurface = aSurface;
glClearColor(0.0, 0.0, 0.0, 0.0); // set background to black
// Textures are initialized in OpenGL ES API by this function.
glGenTextures( 1, textures[0] );
//Bind the background texture to iTexturesID[0], set the texture environment.
glBindTexture( GL_TEXTURE_2D, textures[0] );

glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
256, 256, 0,

// Push on a new matrix so that we can just pop it off to go back to perspective mode
glDisable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE  );
// Reset the current matrix to our identify matrix
// Pass in our 2D ortho screen coordinates (left, right, bottom, top, near, far).
glOrthof( 0, 1, 0, 1, -1, 1 );
// Switch to model view so that we can render the texture
// Initialize the current model view matrix with the identity matrix
glMatrixMode( GL_PROJECTION );
//glEnable( GL_DEPTH_TEST );
//glEnable( GL_CULL_FACE  );

And then the DeInit function. Only texture is deleted in here. The Screen surface is handled elsewhere.

void DeInitOpenGLES()
glDeleteTextures(1, textures[0]);

And here is the putframe function. Currently there are

static const GLbyte bgverts[8] =
0, 0,
1, 0,
0, 1,
1, 1

static const GLubyte bgtex[8] =
0, 1,
1, 1,
0, 0,
1, 0
//Use rotated matrix for N95, since the phone should be turned upside down.
static const GLubyte rot180_bgtex[8] =
1, 0,
0, 0,
1, 1,
0, 1
static const GLbyte vertices[3 * 3] =
-1,    1,    0,
1,   -1,    0,
1,    1,    0

static const GLubyte colors[3 * 4] =
255,      0,    0,    255,
0,    255,    0,    255,
0,      0,  255,    255

void PutS9xFrame( int aWith, int aHeight )
TUint8 *data = (TUint8 *) iBitmap->DataAddress();
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 8, 256, 239,

//y-offset8, TODO: calculate this for each resolution
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 8, 256, 239,

// Enable vertex arrays.
glEnableClientState( GL_VERTEX_ARRAY );
// Set array pointers.
glVertexPointer( 2, GL_BYTE, 0, bgverts );
// Enable texture arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// Set texture coords
glTexCoordPointer( 2, GL_BYTE, 0, rot180_bgtex );
glBindTexture( GL_TEXTURE_2D, textures[0] );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

// Go back to model view matrix
glMatrixMode( GL_MODELVIEW );
eglSwapBuffers( g_EglDisplay, g_EglSurface);


Continue reading ‘Rendering frames with OpenGL ES’ »