Code sample: Determining OpenGL ES support

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.opengles.*;
import javax.microedition.khronos.egl.*;
import javax.microedition.khronos.opengles.*;

public class OpenGLSupport extends UiApplication
{  
    public static void main( String[] args )
    {
        OpenGLSupport app = new OpenGLSupport();
        app.enterEventDispatcher();
    }
    
    public OpenGLSupport()
    {
        pushScreen(new InfoScreen());
    }
    
}

class InfoScreen extends MainScreen
{
    private LabelField labelSupportMsg;
    private LabelField labelVendor;
    private LabelField labelRenderer;
    private LabelField labelVersion;
    private LabelField labelExtensions;
    
    private EGL11 _egl;
    private EGLDisplay _eglDisplay;
    private EGLSurface _eglSurface;
    private EGLConfig _eglConfig;
    private EGLContext _eglContext;
    private GL10 _gl;

    public InfoScreen()
    {
        if(GLUtils.isSupported())
        {
            labelSupportMsg = new LabelField("OpenGL ES is supported.");
            
            _egl = (EGL11)EGLContext.getEGL();
            _eglDisplay = _egl.eglGetDisplay(EGL11.EGL_DEFAULT_DISPLAY);
            int[] versionInfo = new int[2];
            _egl.eglInitialize(_eglDisplay, versionInfo);

            EGLConfig[] configs = new EGLConfig[1];
            int[] numConfigs = new int[1];
            int[] attrs =
            {
                EGL11.EGL_RED_SIZE,   5,
                EGL11.EGL_GREEN_SIZE, 6,
                EGL11.EGL_BLUE_SIZE,  5,
                EGL11.EGL_NONE
            };
            _egl.eglChooseConfig(_eglDisplay, attrs, configs, 1, numConfigs);
            _eglConfig = configs[0];
            
            _eglContext = _egl.eglCreateContext(_eglDisplay,
              _eglConfig, EGL10.EGL_NO_CONTEXT, null);
            
            _eglSurface = _egl.eglCreateWindowSurface(_eglDisplay,
              _eglConfig, this, null);
            
            _egl.eglMakeCurrent(_eglDisplay,_eglSurface,_eglSurface,_eglContext);
            _gl = (GL10)_eglContext.getGL();
            
            labelVendor     = new LabelField("Vendor: " + 
                                             _gl.glGetString(GL10.GL_VENDOR));
            labelRenderer   = new LabelField("Renderer: " + 
                                             _gl.glGetString(GL10.GL_RENDERER));
            labelVersion    = new LabelField("Version: " + 
                                             _gl.glGetString(GL10.GL_VERSION));
            labelExtensions = new LabelField("Extensions:\n" + 
                                             _gl.glGetString(GL10.GL_EXTENSIONS));
            
            add(labelSupportMsg);
            add(labelVendor);
            add(labelRenderer);
            add(labelVersion);
            add(labelExtensions);
        }
        else
        {
            labelSupportMsg = new LabelField("OpenGL ES is not supported.");
            add(labelSupportMsg);
        }
        
        
    }
    
}
Previous topic: OpenGL ES code samples

Was this information helpful? Send us your comments.