ARTICLE

Create OpenGL Mono For Android Application

Posted by Amit Prabhu Articles | Android Programming February 09, 2012
In this article I will demonstrate how to create an OpenGL Mono For Android application.
Reader Level:

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 following folders and files.

Please see below to understand the use of each and every file.

androidopengl3.gif

Main.axml

Need to add controls in the following format to get it to display on your screen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</
LinearLayout>

Strings.xml

Need to add a string with a unique name and value.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <
string name="Hello">Hello World, Click Me!</string>
    <string name="ApplicationName">OpenGLApplication1</string>
</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.

namespace OpenGLApplication1
{      
    public partial class
Resource
    {             
         public partial class
Attribute
         {
                private Attribute()
                {
                }
         }
             
         public partial class
Drawable
      
  {
               
// aapt resource value: 0x7f020000
                public const int Icon = 2130837504;
                    
                private Drawable()
                {
                }
         }
             
         public partial class
Layout
         {
               
// aapt resource value: 0x7f030000
                public const int Main = 2130903040;
                    
                private Layout()
                {
                }
         }
             
         public partial class
String
         {
               
// aapt resource value: 0x7f040001
                public const int ApplicationName = 2130968577;
                  
               
// aapt resource value: 0x7f040000
                public const int Hello = 2130968576;
                    
                private String()
                {
                }
          }
    
}
}

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.

using System; 
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
 
namespace OpenGLApplication1
{
    [Activity(Label = "OpenGLApplication1", MainLauncher = true, Icon = "@drawable/icon")]

    public class Activity1 : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
 
           
// Create our OpenGL view, and display it
            GLView1 view = new GLView1(this);
            SetContentView(view);
        }
    }
}


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.

Login to add your contents and source code to this article
post comment
     

this is a good article but i could't install android with .Net. Please help me. My Email is-- ragh.pal199@gmail.com

Posted by Raghavendra Pal May 07, 2012

It is well explained and a worth reading really...

Posted by Jessica Stephen Feb 10, 2012

very nice article...keep it up...

Posted by Sumita Jain Feb 10, 2012

Great what an article. I will surely try to implement this.

Posted by Adora Krause Feb 09, 2012

Nice explanation.

Posted by Abhi Kumar Feb 09, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts