Nick's .NET Travels

Continually looking for the yellow brick road so I can catch me a wizard....

OpenGL ES Wrapper: Your First Application

In my previous post on Getting Started with OpenGL on Windows Mobile I talked about taking the existing OpenGL ES wrapper by Koushik Dutta and extending it to make it easier to work with.  In this, and subsequent posts, I’ll show you how you can take this wrapper and start building out an application.

To get started create a new Smart Device project in Visual Studio 2008.

image image

Note that I’ve created this against the Windows Mobile 5 SDK – if you can find a legacy device still running WM5 which supports OpenGL then this application will still run. I only bother building against the later SDKs if I particularly need one of the few features that were added since WM5.

Next, copy the two OpenGL projects from the this link into your solution folder and add them to your solution within Visual Studio. Also, go ahead and add a project reference from your application to both OpenGL projects.

image

You won’t be needing the designer support for your form but you do need some of the initialization values set in the Form1.designer.cs file. It’s up to you whether you move the InitializeComponent method from your Form1.designer.cs file into your Form1.cs, and then delete Form1.designer.cs, or just leave the designer.cs file there and ignore it.

At this stage I’d recommend renaming Form1 to something more descriptive. In this case my application is only going to have a single form so I have used MainForm. In the MainForm.cs file I’ve modified the class to inherit from ApplicationForm, rather than just Form – this gives me all the OpenGL initialization I talked about previously, as well as some virtual methods that can be implemented to setup, draw and update the current scene:

public partial class MainForm : ApplicationForm
    {
        public MainForm()
        {
            InitializeComponent();
        }

        protected override void SetupScene()
        {
            base.SetupScene();
        }

        protected override void DrawScene()
        {
            base.DrawScene();
        }

        protected override void UpdateScene(float secondsSinceLastUpdate)
        {
            base.UpdateScene(secondsSinceLastUpdate);
        }
    }

In this case we’re going to simply implement Hello World by creating a Font and GlyphRun in the SetupScene method:

OpenGLFont font;
GlyphRun title;
protected override void SetupScene()
{
    base.SetupScene();

    font = new OpenGLFont(new Font(FontFamily.GenericSerif, 12, FontStyle.Regular));
    title = new GlyphRun(font, "Hello World!", new Size(int.MaxValue, int.MaxValue), OpenGLTextAlignment.Left, true);
}

Then to draw the text on the screen, simply update the Draw method:

protected override void DrawScene()
        {
            base.DrawScene();

            title.Draw();
        }

 

 

image

Not the worlds greatest demo, but surprisingly simple for an OpenGL application. In the next post we’ll start to investigate what you can really do with OpenGL that you can’t do easily with traditional Windows Forms application.

Note: In the InitializeOpenGL function within ApplicationForm you need to include the following call otherwise your text will appear as a solid white rectangle:

gl.BlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);

Comments (4) -

  • Adam Ciszewski

    6/10/2010 8:43:00 AM |

    Great tutorial...!
    thank you very much for updating images and wrapper ...

    looking forward to new posts about OpenGL in Windows Mobile @ Your blog :)

  • nick

    6/10/2010 1:05:51 PM |

    Adam

    Unfortunately my attention has shifted to Windows Phone 7 so I doubt that I'll do many more posts on OpenGL. If there is something specific that you're interested in, please feel free to contact me and I can see what I can do.

    Thanks again for the feedback

  • Binary Options

    8/12/2010 12:46:09 AM |

    Hey very nice blog!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also...

  • android app for conferences

    11/2/2010 4:23:23 AM |

    first of all I want to say, Your site look and feel is awesome and really let each and everyone... comment over here...
    well its not only cool in looks but also informative... :)

  • guaranteed personal loans

    3/5/2011 5:31:32 AM |

    This is my subject field for my next coming  session project and I don’t familiar how I can say my thanks for much  kind of help oneself you did for building up my project  incredibley. My name is ketty and I  am trying to exploring on  concerning matter for a effective documentation and obtained your internet  site on top page of google .You have a  nice and  soft user interface along with  good stuffs on your website .I  too  manage a personal web site and  at present you are in my beloved site listing . thanks for the  super service.have a beautiful day.

  • auto insurance ottawa

    5/21/2011 8:08:22 PM |

    I have been exploring for a little for any high quality articles or blog posts on this sort of house . Exploring in Yahoo I ultimately stumbled upon this web site. Studying this info So i am happy to show that I've an incredibly just right uncanny feeling I discovered exactly what I needed. I most indisputably will make sure to don¡¦t overlook this web site and provides it a glance a continuing.

  • Rex Farrand

    5/22/2011 2:56:04 AM |

    Even you will find several running for years, when you begin your barefoot managing training the very first thing you should know is that you will have to cut way back on your typical routine, and commence as though you were only getting started going.

Comments are closed