Main Menu Bar

header ads

Game development with OpenGL ES

Setting up OpenGL Environment.


1. Getting started.


Step 1. Create new project.

create new project in your favourite ide I'll use Sketchware, I assume you have already created a new project.

Step 2. Declare OpenGL in Manifest


In order to use OpenGL ES 2.0 API, you have to declare it in your manifest. 

 
<uses-feature android:glEsVersion="0x00020000" android:required="true" />  

In other IDEs you can directly add the above code in manifest like this 



But in Sketchware you have to use XML code block,
Set all parameters as shown in below screenshot and paste the code in asd (add source directly). If you can't see them correctly click on the image and zoom it a little bit.

You'll find them here in moreblocks section


If you don't see them there, maybe you haven't yet enabled them. So goto mod settings in developer options and enable them right away.




To draw graphics using OpenGl ES in Android Application you must create a view container for them. 

straight-forward way to do this for full screen or near fullscreen is to implement both a GLSurfaceView and a GLSurfaceView.Renderer

Developers who want to incorporate OpenGL ES graphics in a small portion of their layouts should take a look at TextureView or SurfaceView.

both have Thier limitations and benefits.







2. Create an activity for OpenGL ES graphics


We are making a game so we will go for GLSurfaceView along with GLSurfaceView.Renderer, because we want full screen experience and maximum capabilities. 


OpenGL apps in android have activities just like any other application. The main difference is what you put in the layout of your activity. in OpenGL ES you can use normal widgets like TextView, Button and Listview etc. but more importantly you can also use a GLSurfaceView.


here is a code example from develeopres.android.com that shows a minimal implementation of an activity that uses a GLSurfaceView as its primary view. 



 

public class OpenGLES20Activity extends Activity {

    private GLSurfaceView gLView;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        // Create a GLSurfaceView instance and set it

        // as the ContentView for this Activity.

        gLView = new MyGLSurfaceView(this);

        setContentView(gLView);

    }

}  


Post a Comment

0 Comments