Wednesday, September 2, 2009

A simple and nice way to video background without OpenGL ES texturing on the iPhone : Another tip

When I upgraded the Oolong Engine to the version supporting OpenGL ES 2.0, my trick for video background did not work. The GL view's background is cleared (0,0,0), but the video preview view was occluded by the GL view. Clearly, glClear(0,0,0,0) didn't work at that stage.

I tried to find why this happens and I found a solution after all. The reason why glClear do not work was that the color format of the GL view was set to RGB565, which seems not to provide alpha in the scene So I changed the color format from RGB565 to RGBA8 like this and I can see the background video and rendered scene now.

original code in delegate.m was :

_glView = [[EAGLView2 alloc] initWithFrame:rect pixelFormat:GL_RGB565 depthFormat:GL_DEPTH_COMPONENT16 preserveBackbuffer:NO];

What I chanaged for solving the problem is :

_glView = [[EAGLView2 alloc] initWithFrame:rect pixelFormat:GL_RGBA8_OES depthFormat:GL_DEPTH_COMPONENT16 preserveBackbuffer:NO];

Actually, you can see the initWithFrame method initializes the color format either RGB565 or RGBA8. Please look the implementation of initWithFrame method in the file EAGLView2.m. You may see this code.

eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:

[NSNumber numberWithBool:YES],


(format == GL_RGB565) ? kEAGLColorFormatRGB565 : kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];


  1. Excellent. Can't wait go go home and try it.



  2. That's great hint. Thank you very much. You save me a lot of time