2024年4月26日发(作者:)
Introduction
Over the last couple days, I have been
researching managed 2D graphics APIs for the
Windows Mobile platform. There are a lot of
choices out there. Strictly for 2D, we have GDI,
GAPI, DirectDraw, and the
GetRawFramebuffer function. On the 3D side,
we have OpenGL ES and Direct3D. Each of
介绍
在过去的几天我一直在研究Windows
Mobile 平台的托管2D图形api。有很多选
择。严格的 2D,我们有 GDI、 网、
DirectDraw,和 GetRawFramebuffer 函数。
在 3D 的方面我们有 OpenGL 和 Direct3D。
这些 api 的每个有其优点和缺点。
these APIs has its pros and cons.
OpenGL ES (Embedded Systems)
OpenGL ES is a lightweight subset of OpenGL
for small devices. There is no official managed
OpenGL ES wrapper, but Koushik Dutta has
created a managed wrapper which you can
download off his blog. In order to get decent
performance out of OpenGL ES, your
hardware needs drivers. There is a software
driver though.
Direct3D Mobile
Managed Direct3D has been in Compact
Framework since 2.0. If your target device
does not have hardware support with an
accompanying driver (htcclassaction), then
forget about Direct3D. The software driver is
incredibly slow and is not really good for
anything except debugging in the emulator.
You can use the code from this link to see if
your device has a Direct3D driver.
GDI
GDI stands for Graphic Device Interface and is
the primary API for 2D graphics in windows.
GAPI (Game API)
GAPI is an old API for CE that Microsoft
created to ease game development. You can
find a managed wrapper for GAPI on MSDN
here.
GAPI is officially deprecated. All
documentation has been removed from
MSDN (except GXInput). You will still find
on your phone though, and the
graphics related functions still exist. Microsoft
is going to remove it in a future version.
OpenGL ES(嵌入式系统)
OpenGL ES是OpenGL轻量级的子集小型设
备。没有正式托管的 OpenGL ES 包装。但
Koushik Dutta创建了一个托管封装,您可以
在他的博客中下载。为了在OpenGL ES之外
得到相当好的性能,您的硬件需要驱动程序。
虽然有软件驱动程序。
Direct3D Mobile
Direct3D托管程序从2.0版本开始已经集成
在Compact Framework中。如果您的目标设
备并没有硬件支持相应的驱动程序,就不能
使用Direct3D。软件驱动程序速度非常慢并
且不是很好,除了在仿真程序中进行调试。
您可以使用该链接的代码以确定您的设备
是否有 Direct3D 驱动程序。
GDI
GDI 代表图形设备接口,用于 2D 图形窗口
中的主 API。
GAPI (游戏API)
GAPI是CE的一个旧的API,是微软创建用
以纾缓游戏开发。您可以在MSDN 上找到
一个GAPI的托管封装。
GAPI官方不推荐使用,MSDN上的所有文件
都已被删除(GXInput除外)。虽然你会您的电
话上找到,与图形相关的功能仍然存
在。 微软将在未来的版本中删除它。
Using an API that was going away didn't jive
with me. The zombies sample application did
not run too fast on my phone either.
DirectDraw
DirectDraw is a 2D API from Microsoft.
DirectDraw gives us direct access to video
memory, hardware blting, and flipping.
Microsoft is pushing DirectDraw as the
recommended API for fast 2Dd graphics in CE
now that GAPI is being deprecated (see the
"Have you migrated to DirectDraw yet?" link
at the bottom of the page). Unfortunately,
there is no managed wrapper for DirectDraw
in the Compact Framework. Today, we will
create one.
DirectDraw wrapper
DirectDraw is implemented as a COM library.
The initial version of the Compact Framework
did not support COM interop, but it was
added in version 2.0. Using DirectDraw from
managed code should be extremely simple.
We should be able to run tlbimp to generate
the stubs we need for the interop, but
unfortunately, I had some issues, so I
manually wrote the interop code.
Initializing DirectDraw
The first thing we need to is create an
instance of the main DirectDraw object. We
will use the DirectDrawCreate method to
create this object. Even though DirectDraw is
implemented as a COM library, we need to
call this method to pass in the device ID that
we get using DirectDrawEnumerateEx, or pass
in null for the default device. We will also
need to pass in a pointer to a IDirectDraw
interface. The last argument is not used, and
we can ignore and pass in null.
[DllImport("", CallingConvention =
)]
public static extern uint
DirectDrawCreate(IntPtr lpGUID,
out IDirectDraw lplpDD,
IntPtr pUnkOuter);
使用API和我不是很合拍。示例应用程序在
我的电话上运行得也不是太快对
DirectDraw
DirectDraw是微软的2D API。DirectDraw能
使我们直接访问显存、硬件。DirectDraw作
为微软推荐的比较快速的CE的2D图形API
现在正在过时。不幸的是,在Compact
Framework中没有DirectDraw的托管封装。
今天,我们将创建一个。
DirectDraw 封装
DirectDraw作为一个COM库。Compact
Framework的最初版本不支持COM互操作,
但它是在版本2.0增加了。从托管代码使用
DirectDraw应该非常简单。我们应该能够运
行tlbimp生成存根我们需要互操作的,但不
幸地,我有些问题,因此我手工写了interop
代码。
初始化DirectDraw
我们首先要做的是创造DirectDraw对象的
实例。使用DirectDrawCreate方法来创造。
尽管DirectDraw已在COM库中实现,但
我们需要调用这个方法传递设备的ID,得到
引用DirectDrawEnumerateEx,或者默认为空
值。还需要一个指针传递IDirectDraw接口。
最后一个参数没有使用,我们可以忽略,并
传入空。
发布评论