Search Projects

Friday, July 31, 2015

How to check if Android Device Supports OpenGL ES 2.0

OpenGL ES stands for OpenGL for Embedded Systems also called as GLES. It is subset of OpenGL Computer graphics API for rendering 2D and 3D computer graphics particularly focusing on Hardware Accelerated using GPU. It is used in embedded systems like Smartphones (iPhone, Android Phones), Tablets (iPad, Android Tablets), Video game Consoles (Xbox, Play Station) and PDA (Personal Digital Assistant). Due to it openness and cross platform support, it is quite popular as well as most used graphics API in Smartphone and Tablets.

In this post we are going to know programically if Android Device Supports OpenGL ES 2.0. This is tutorial for OpenGL ES Android Programming . To check if Android Device Supports OpenGL ES 2.0 or not we are going to use very simple code. Let’s get started with it.

Prerequisite

For this our OpenGL ES Android tutorial it is assumed that you basic level of Java and Android Programming. It is also assumed that you are familiar with OpenGL as well. We are going to need some software installed on your computer to begin with our OpenGL ES Android tutorial. We need the following tools –
  • Android Studio (or Eclipse with ADT Plugin)
  • Android SDK

Android Studio is official IDE for Android Development so here I will show the tutorial in it, but you are free to use Eclipse (But why?).

Creating the Project

11.  First Step is to create a new project in Android Studio. Open Android Studio and create a new project but don’t create any activity for this as we are not going to need. You should choose “Add No Activity”. If required for further programming you can create Activity then.

22. Next Step is to create a class “MainActivity.java” (Right click on your package name under java -> new ->class). In this activity class just create the “onCreate” method. In the method we will use the logic to identify OpenGL 2.0. In a condtion we will check the status of OpenGL ES2.0 and toast  the result. Check the code below.

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);      
ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
Boolean supportes2 = (info.reqGlEsVersion>= 0x20000);
Boolean supportes2 = (info.reqGlEsVersion>= 0x20000);
      
if(supportes2){
Toast.makeText(getApplicationContext(),"Your Device Support OpenGL ES2",Toast.LENGTH_LONG).show();
        }
        else{
Toast.makeText(getApplicationContext(),"Your Device doesn’t  Support OpenGL ES2",Toast.LENGTH_LONG).show();          
Log.d("OpenGL ES2", "Your Device doesn't  Support ES2. ("+info.reqGlEsVersion+")");
        }
    }

Explanation

First we created ActitivtyManager object to access or interact with the system services. Now we created ConfigurationInfo object and retrieve the hardware configuration of the device. This object will help us know the GLES version used.  Next we created the variable  supportes2. With reqGlEsVersion we checked the version from the condition we used and stored  result in our Boolean variable. We have used the condition with “0x20000” which represent the GLES version upper 16 bits for major version while lower 16 bits for minor version.

33.  Final Step is to run and check if Android Device Supports OpenGL ES 2.0. Go to Run menu and select “Run ‘app’” or use shortcut shift+f10. Check which toast is called.

Final Thought

Google added support for OpenGL ES 2.0 in Android 2.0 through NDK and Android 2.2 through Java. Today’s Modern Phone almost support the OpenGL ES 2.0 so if you wonder to check higher version like OpenGL ES 3.0 replace  0x20000 with 0x30000 in “Boolean supportes2 = (info.reqGlEsVersion>= 0x20000);” which is supported from Android 4.3.

Please comment below how you liked this tutorial. Give us feedback so we can improve on our OpenGL ES Android tutorial. Stay tune for more tutorials.

Reference



No comments:

Post a Comment