Archive for 'Color Buffer'

Simple OpenGL ES Application in Android

The following is a simple OpenGL ES Implementation in Android.This program clears the screen to black on each frame load. This is a pure OpenGL application, that correctly implements the Android activity life-cycle. It pauses rendering when the activity is paused, and resumes it when the activity is resumed. GLSurfaceView is a good base for building an application that uses OpenGL ES for part or all of its rendering. A 2D or 3D action game would be a good candidate, as would a 2D or 3D data visualization application.

Java Code:

package com.schogini.EGLExample;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;
import android.os.Bundle;

public class ClearActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        mGLView = new GLSurfaceView(this);
        mGLView.setRenderer(new ClearRenderer());

    protected void onPause() {

    protected void onResume() {

    private GLSurfaceView mGLView;

class ClearRenderer implements GLSurfaceView.Renderer {
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // Do nothing special.

    public void onSurfaceChanged(GL10 gl, int w, int h) {
        gl.glViewport(0, 0, w, h);

    public void onDrawFrame(GL10 gl) {

Initializing the EAGLView in cocos2d

For Initializing the EAGLView the followings are required

Color Buffer

The default color buffer is RGB565. It is a 16-bit buffer, without alpha. In order to use an RGBA8 color buffer, you need to create initialize the EAGLView with:

EAGLView *glView = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8];

    kEAGLColorFormatRGBA8: Creates an RGBA8 color buffer (32-bit)
    kEAGLColorFormatRGB565: Creates an RGB565 color buffer (16-bit). Faster, but without alpha (default)

Depth Buffer

By default, cocos2d doesn’t use a depth buffer, but you can create one when you initialize the EAGLView with a 16-bit or 24-bit depth buffer. eg:

EAGLView *glView = [EAGLView viewWithFrame:[window bounds]

    GL_DEPTH_COMPONENT24_OES: 24-bit depth buffer
    GL_DEPTH_COMPONENT16_OES: 16-bit depth buffer
    0: No depth buffer will be created

High Res

Since v0.99.4, the Director can set the color render buffer in High Res mode:


// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if ([UIScreen instancesRespondToSelector:@selector(scale)])
[director setContentScaleFactor:[[UIScreen mainScreen] scale]];

Since v0.99.5, the suggested way to enable Retina display is:

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@”Retina Display Not supported”);

How does it work:

If you have an iPhone4, the screen resolution will be 960×640

MultiSampling, or Full Screen Anti-Aliasing

Multi sampling works on all devices, but on MBX devices the performance impact is severe.

How to enable it:

Don’t use the CC_DIRECTOR_INIT() macro, but use the code from the sample below.

Incoming search terms:

  • created a EAGLView
We Can Build Your App for You. Lets Get Started !