随笔 - 249  文章 - 1  评论 - 1207  阅读 - 61万

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)

posted on   施炯  阅读(2831)  评论(9编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2010年3月 >
28 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
4 5 6 7 8 9 10

点击右上角即可分享
微信分享提示