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. public partial class Drawable
  12. {
  13. // aapt resource value: 0x7f020000
  14. public const int Icon = 2130837504;
  15. private Drawable()
  16. {
  17. }
  18. }
  19. public partial class Layout
  20. {
  21. // aapt resource value: 0x7f030000
  22. public const int Main = 2130903040;
  23. private Layout()
  24. {
  25. }
  26. }
  27. public partial class String
  28. {
  29. // aapt resource value: 0x7f040001
  30. public const int ApplicationName = 2130968577;
  31. // aapt resource value: 0x7f040000
  32. public const int Hello = 2130968576;
  33. private String()
  34. {
  35. }
  36. }
  37. }
  38. }
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.
  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. namespace OpenGLApplication1
  9. {
  10. [Activity(Label = "OpenGLApplication1", MainLauncher = true, Icon = "@drawable/icon")]
  11. public class Activity1 : Activity
  12. {
  13. protected override void OnCreate(Bundle bundle)
  14. {
  15. base.OnCreate(bundle);
  16. // Create our OpenGL view, and display it
  17. GLView1 view = new GLView1(this);
  18. SetContentView(view);
  19. }
  20. }
  21. }
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.