前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OpenGL ES Wrapper on Windows Mobile

OpenGL ES Wrapper on Windows Mobile

作者头像
ShiJiong
发布2018-01-10 17:35:00
7790
发布2018-01-10 17:35:00
举报

写在最前

    关于在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
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
Screen03

图2

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

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

image_thumb_1
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
Screen07
Screen05
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)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010-03-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档