Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

Create OpenGL Mono For Android Application

, 21 Feb 2012 CPOL
Create OpenGL Application in Visual Studio
OpenGLApplication1.zip
OpenGLApplication1
OpenGLApplication1.suo
OpenGLApplication1
Assets
bin
Debug
OpenGLApplication1.dll
OpenGLApplication1.dll.mdb
OpenGLApplication1.OpenGLApplication1.apk
OpenGLApplication1.OpenGLApplication1-Signed.apk
Properties
Resources
Drawable
Icon.png
Layout
Main.axml
Values
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)
        {
            base.OnLoad(e);

            // Run the render loop
            Run();
        }

        // This gets called on each frame render
        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,
		};
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

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

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