SIGN UP MEMBER LOGIN:    
ARTICLE

Create OpenGL Mono For Android Application

Posted by Amit Prabhu Articles | Android Programming February 05, 2012
In this article we are going to create an OpenGL Mono for Android application using Visual Studio 2010.
Reader Level:
Download Files:
 

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 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 string with 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 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 standing First in 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

opengl1.gif
opengl2.gif

As you finish the coding then build the application. And then execute the application.

androidopengl4.gif

When you are able to see the above screen then press Start emulator Image then you are able to see the following screen.

androidopengl5.gif

Then Select any emulator and press ok.

androidopengl6.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.

androidopengl7.gif

This way you can create any graphical application.

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

Very useful article. Thanks for sharing.

Posted by Alok Pandey Feb 05, 2012

This article will help many android application developer

Posted by Akash Ahlawat Feb 05, 2012

Good start, Welcome to the C# Corner.

Posted by Dinesh Beniwal Feb 05, 2012

Its a very useful and good article. Thanks.

Posted by Monika Arora Feb 05, 2012

Really very valuable article thanks for sharing

Posted by Arjun Panwar Feb 05, 2012
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor