zoukankan      html  css  js  c++  java
  • OpenGL ES Wrapper on Windows Mobile

    写在最前

        关于在Windows Mobile上使用OpenGL ES,可以参考MVP的这篇文章《Getting Started with OpenGL on Windows Mobile》。另外,Jake也在《OpenGL ES for Windows Mobile》中给出了他的测试结果。我写这篇文章的目的,就是给打算在Windows Mobile上使用OpenGL ES的新手作为一个参考。写得不对的地方,还请大家多多包涵。

    关于OpenGL ES

        要在Windows Mobile上画3D图形,就需要使用DirectX和OpenGL ES。OpenGL ES (OpenGL for Embedded Systems) 是OpenGL的子集,主要针对手机、PDA等嵌入式设备而开发。

    一步一步教你在Windows Mobile上使用OpenGL ES

    1. 点击这里下载OpenGL ES

    2. 解压以后,发现里面包含两个文件夹,一个是OpenGLES,另外一个是OpenGLESUtilities。用Visual Studio新建一个智能设备应用程序,取名为OpenGLSample,把这两个文件中的内容添加到工程中(注:只需在工程中添加OpenGLES.csproj和OpenGLESUtilities.csproj这两个文件即可)。

    3. 在工程中添加对OpenGL ES的引用,“using OpenGLES”,然后就可以使用了。

    例子1:使用OpenGL ES画“Hello World!”

        首先声明OpenGLFont font和GlyphRun title,然后在SetupScene使用:

    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);
    }

        最后在DrawScene函数中调用:

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

                title.Draw();
            }

    在我的Cingular8125 (WM6.0 Professional)上,运行结果如下图1所示:

    Screen04图1

    如果要对文字进行旋转和尺度变化,我们需要加入gl.Rotate和gl.Translate方法:

    gl.Translatef(50.0f,50.0f,0);
    gl.Rotatef(40.0f,0,0,1.0f);
    title.Draw();

    运行结果如下图2所示:

    Screen03

    图2

     

    例子2:使用OpenGL ES画变换的三角形

        这里参考了一位MVP的程序《OpenGL ES绘制3D图形》。这里需要仔细了解一下OpenGL ES的初始化过程,可以参考图3(注:该图引自上面这篇文章)

    image_thumb_1

    图3

    初始化过程主要包含6个函数,分别是:

    (1) 获取Display ( EGLDisplay )

    egl.GetDisplay(new EGLNativeDisplayType(this));

    (2) 初始化 EGL

    egl.Initialize(myDisplay, out major, out minor);

    (3) 设置EGLConfig ( EGLConfig )

    egl.ChooseConfig(EGLDisplay myDisplay, const EGLint * attribList, EGLConfig * configs, EGLint config.Length, EGLint *numConfig)

    (4) 构造Surface ( EGLSurface )

    egl.CreateWindowSurface(myDisplay, config, Handle, null);

    (5) 创建Context ( EGLContext )

    egl.CreateContext(myDisplay, config, EGLContext.None, null);

    (6) 设置绘制环境Render Context

    egl.MakeCurrent(myDisplay, mySurface, mySurface, myContext);

    在进行绘制时,需要注意以下三个方面:

    (1) 初始化OpenGL ES:开始绘制前,需要将背景、深度测试等参数进行初始化,一般放在Form的初始化函数public Form1() 中。

    (2) 在事件OnPaint中进行绘图。

    (3) 推出应用程序时,释放OpenGL ES相关的资源。

    测试结果

        在Cingular8125 (WM6.0 Professional)上,三角形旋转流畅,并未出现停顿等情况。

    Screen07 Screen05

    图4

    相关链接:

    Getting Started with OpenGL on Windows Mobile

    OpenGL ES for Windows Mobile

    OpenGL ES绘制3D图形

     

    工程源代码可以点击这里下载:OpenGLSample.rar(Visual Studio 2008+WM6.0 Pro SDK)

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    如何进行Django单元测试
    django使用celery实现异步操作
    django 多并发,多线程。
    cookies设置时间
    Mysql实现企业级日志管理、备份与恢复
    Redis与Memcached的区别
    cookie 和session 的区别详解
    python内存泄露查找
    浙大月赛ZOJ Monthly, August 2014
    Vector
  • 原文地址:https://www.cnblogs.com/dearsj001/p/OpenGLESForWM.html
Copyright © 2011-2022 走看看