Introduction
Let us understand how to create an OpenGL application for Android phone from Visual Studio 2010.
System Requirements
- Android SDK
- Mono
- Visual Studio 2010
Background
Using the Code
As you click New Project, if all required software are properly installed, then you are able to see Mono for Android in your Visual Studio, or else install it.

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

namespace OpenGLApplication1
{
public partial class Resource
{
public partial class Attribute
{
private Attribute()
{
}
}
public partial class Drawable
{
public const int Icon = 2130837504;
private Drawable()
{
}
}
public partial class Layout
{
public const int Main = 2130903040;
private Layout()
{
}
}
public partial class String
{
public const int ApplicationName = 2130968577;
public const int Hello = 2130968576;
private String()
{
}
}
}
}
Activity1.cs
This class is standing 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);
GLView1 view = new GLView1(this);
SetContentView(view);
}
}
}
GLView1.cs
using System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.ES11;
using OpenTK.Platform;
using OpenTK.Platform.Android;
using Android.Views;
using Android.Content;
namespace OpenGLApplication1
{
class GLView1 : AndroidGameView
{
public GLView1(Context context)
: base(context)
{
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Run();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
MakeCurrent();
GL.MatrixMode(All.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
GL.MatrixMode(All.Modelview);
GL.Rotate(3.0f, 0.0f, 0.0f, 1.0f);
GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f);
GL.Clear((uint)All.ColorBufferBit);
GL.VertexPointer(2, All.Float, 0, square_vertices);
GL.EnableClientState(All.VertexArray);
GL.ColorPointer(4, All.UnsignedByte, 0, square_colors);
GL.EnableClientState(All.ColorArray);
GL.DrawArrays(All.TriangleStrip, 0, 4);
SwapBuffers();
}
float[] square_vertices = {
-0.5f, -0.5f,
0.5f, -0.5f, -0.5f, 0.5f,
0.5f, 0.5f, };
byte[] square_colors = {
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
};
}
}

Then select any emulator and press OK.
Then the execution process gets started and the package is created. As the process of execution completes, you are able to see the screen of Android phone with rotating rectangle as per the code.

History
- 21st February, 2012: Initial version
Name : Amit Prabhu.
IT Exp: 8 yrs.
Lang : C#, Asp.Net, Mono - Android
Loc : Pune.