Click here to Skip to main content
11,705,052 members (53,915 online)
Click here to Skip to main content

Create OpenGL Mono For Android Application

, 21 Feb 2012 CPOL 18.4K 798 15
Rate this:
Please Sign up or sign in to vote.
Create OpenGL Application in Visual Studio


Let us understand how to create an OpenGL application for Android phone from Visual Studio 2010.

System Requirements

  • Android SDK
  • Mono
  • Visual Studio 2010


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
            // 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()


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)

            // Create our OpenGL view, and display it
            GLView1 view = new GLView1(this);


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)

        // This gets called when the drawing surface is ready
        protected override void OnLoad(EventArgs e)

            // Run the render loop

        // This gets called on each frame render
        protected override void OnRenderFrame(FrameEventArgs e)
            GL.Ortho(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
            GL.Rotate(3.0f, 0.0f, 0.0f, 1.0f);

            GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f);

            GL.VertexPointer(2, All.Float, 0, square_vertices);
            GL.ColorPointer(4, All.UnsignedByte, 0, square_colors);
            GL.DrawArrays(All.TriangleStrip, 0, 4);


        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.


  • 21st February, 2012: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
India India
Name : Amit Prabhu.
IT Exp: 8 yrs.
Lang : C#, Asp.Net, Mono - Android
Loc : Pune.

You may also be interested in...

Comments and Discussions

QuestionThanks, it's work fine, but i can't set this as live wallpaper Pin
Member 93733145-Jan-13 1:26
memberMember 93733145-Jan-13 1:26 
Thanks, it's work fine, but i can't set this as live wallpaper
AnswerRe: Thanks, it's work fine, but i can't set this as live wallpaper Pin
cjb11010-Mar-14 21:46
membercjb11010-Mar-14 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 21 Feb 2012
Article Copyright 2012 by amitprabhu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid