Create OpenGL Mono For Android Application

Introduction

 
Let us understand how to create an OpenGL application for Android phones from Visual Studio 2010.
 
System Requirement
  • Android SDK
  • Mono
  • Visual Studio 2010
Step 1: First open the Visual Studio 2010
 
Step 2: Click New Project
 
androidopengl1.gif
 
If all the required software is properly installed then you are able to see Mono for Android in your Visual Studio, else install it.
 
androidopengl2.gif
 
Step 2: For creating an OpenGL Android application first select the project OpenGL Mono for Android Application. Then in Solution Explorer, you are able to see the following folders and files.
 
Please see below to understand the use of each and every file.
 
androidopengl3.gif
  
Main.axml
You need to add controls in the following format to get it to display on your screen. 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent">  
  6. </LinearLayout> 
Strings.xml
 
We need to add a string with a unique name and value.
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="Hello">Hello World, Click Me!</string>  
  4.     <string name="ApplicationName">OpenGLApplication1</string>  
  5. </resources>
Resource.Designer.cs
 
For every control and string variable, there is a corresponding unique resource and for every resource, there is a unique id created.
  1. namespace OpenGLApplication1  
  2. {        
  3.     public partial class Resource  
  4.     {               
  5.          public partial class Attribute  
  6.          {  
  7.                 private Attribute()  
  8.                 {  
  9.                 }  
  10.          }  
  11.                
  12.          public partial class Drawable  
  13.          {  
  14.                 // aapt resource value: 0x7f020000  
  15.                 public const int Icon = 2130837504;  
  16.                       
  17.                 private Drawable()  
  18.                 {  
  19.                 }  
  20.          }  
  21.                
  22.          public partial class Layout  
  23.          {  
  24.                 // aapt resource value: 0x7f030000  
  25.                 public const int Main = 2130903040;  
  26.                       
  27.                 private Layout()  
  28.                 {  
  29.                 }  
  30.          }  
  31.                
  32.          public partial class String  
  33.          {  
  34.                 // aapt resource value: 0x7f040001  
  35.                 public const int ApplicationName = 2130968577;  
  36.                     
  37.                 // aapt resource value: 0x7f040000  
  38.                 public const int Hello = 2130968576;  
  39.                       
  40.                 private String()  
  41.                 {  
  42.                 }  
  43.           }  
  44.      }  
Activity1.cs
 
This class is the First in the hierarchy of execution. It is because of the attribute.
 
And from this call, the event is executed.
  1. using System;   
  2. using Android.App;  
  3. using Android.Content;  
  4. using Android.Runtime;  
  5. using Android.Views;  
  6. using Android.Widget;  
  7. using Android.OS;  
  8.    
  9. namespace OpenGLApplication1  
  10. {  
  11.     [Activity(Label = "OpenGLApplication1", MainLauncher = true, Icon = "@drawable/icon")]  
  12.   
  13.     public class Activity1 : Activity  
  14.     {  
  15.         protected override void OnCreate(Bundle bundle)  
  16.         {  
  17.             base.OnCreate(bundle);  
  18.    
  19.             // Create our OpenGL view, and display it  
  20.             GLView1 view = new GLView1(this);  
  21.             SetContentView(view);  
  22.         }  
  23.     }  
GLView1.cs
androidopengl4.gif
 
opengl2.gif
 
When you finish the coding, build the application. And then execute the application.
 
androidopengl5.gif
 
When you are able to see the above screen then press the Start emulator Image then you are able to see the following screen.
 
androidopengl6.gif
 
Then Select any emulator and press ok.
 
androidopengl7.gif
 
Then execution begins and the package is created. As the process of execution finishes you are able to see the screen of the Android phone with a rotating rectangle as per the code.
 
androidopengl8.gif
 
This way you can create any graphical application.


Similar Articles