Begin android game-Chapter 7(opengl es:a gentle introduction)的翻译

 今天开始对begin android game后面一段opengl进行翻译和学习,本人英语一般,opengel超白菜,所以高手绕过,菜鸟稍微望一望!

首先本书非常好,推荐大大好好看下,因为入门非常ok。长话短说~~

Mr. Nom was a great success. Due to our good initial design and the game framework
we wrote, actually implementing Mr. Nom was a breeze. Best of all, the game runs
smoothly even on low-end devices. Of course, Mr. Nom is not a very complex or
graphically intense game, so using the Canvas API for rendering was a good idea.
However, once you want to do something more complex—say, something like Replica
Island—you will hit a wall: Canvas just can’t keep up with the visual complexity of such a
game. And if you want to go fancy-pants 3D, Canvas won’t help you either. So what can
we do?
This is where OpenGL ES comes to the rescue. In this chapter we’ll first briefly look at
what OpenGL ES actually is and does. We’ll then focus on using OpenGL ES for 2D
graphics, without having to dive into the more mathematically complex realms of using
the API for 3D graphics (we’ll get to that in a later chapter). We’ll take baby steps at first,
as OpenGL ES can get quite involved. So, let’s get to know OpenGL ES.

1,nom蛇很成功,这多亏我们最初良好的设计和游戏框架,事实上运行nom蛇也如浴春风,游戏在低配置的机器也运行得很流畅,当然,nom蛇不是一个非常复杂和有强烈图片视觉效应的游戏。所以用画布的api去渲染是不个不错的idea。然而,一旦你想要更复杂的图片处理,就是说,像Replica Island游戏,你会触礁,因为画面不能跟上一个视觉复杂性的游戏,和如果你想要做3d游戏,画布同样帮不了你,所以我们该怎么办?

这就是为什么出现opengl es,在这章我们将会简单的望下opengles 是什么和能做什么,我们会把关注点放在opengle es对2d图像的操作上,去掉复杂用3d函数时涉及的数学知识部分(下章会学到),我们会迈出婴儿的第一步,随着慢慢的学习。所以,我们开始吧。

 

What Is OpenGL ES and Why Should I Care?
OpenGL ES is an industry standard for (3D) graphics programming. It is especially
targeted at mobile and embedded devices. It is maintained by the Khronos Group,
which is a conglomerate of companies including ATI, NVIDIA, and Intel, who together
define and extend the standard.
Speaking of standards, there are currently three incremental versions of OpenGL ES: 1.0,
1.1, and 2.0. The first two are the ones we are concerned with in this book. All Android
devices support OpenGL ES 1.0, and most also support 1.1, which adds some new
features to the 1.0 specification. OpenGL ES 2.0, however, breaks compatibility with the
1.x versions. You can use either 1.x or 2.0, but not both at the same time. The reason for
this is that the 1.x versions use a programming model called fixed-function pipeline, while
2.0 lets you programmatically define parts of the rendering pipeline via so-called shaders.

Many of the second-generation devices already support OpenGL ES 2.0; however, the
Java bindings are currently not in a usable state (unless you target the new Android 2.3).
OpenGL ES 1.x is more than good enough for most games, though, so we will stick to it
here.

 什么是opengl es和为什么我们要关注它?

opengl es是一个为3d图形编程的行业标准,特别是用在移动手机和嵌入设备上。它是由Khronos Group集团所维持着, 这是一个由ATI,NVIDA和INTEL公司组成的集团

致力于一起定义和扩展这个标准。

标准来说,现在有1.0,1.1,2.0,3个版本,前两个是我们这本书所关心的。所有的anroid设备都支持1.0版本和大多都支持1.1版本。1.1版本是在1.0基础上扩展很多特性出来的。opengl es2.0,就不是,它打破和1.X的兼容性。你只能用其中之一,而不能同时使用。这就是为什么1.x版本用的一个编程模型叫fix4d-fouction管道和2.2版本让你能过所谓的着色器管道编写自定义部分。

很多第二你设备也都支持2.0,但是java binding还不是这个范畴(除了android2.3外),opengl es1.x对于大多数游戏来说已经够用了,所以我们现在将坚持学他。

OpenGL ES is an API that comes in the form of a set of C header files provided by the
Khronos group, along with a very detailed specification of how the API defined in those
headers should behave. This includes things such as how pixels and lines have to be
rendered. Hardware manufacturers then take this specification and implement it for their
GPU on top of the GPU driver. The quality of these implementations varies a little; some
companies strictly adhere to the standard (PowerVR) while others seem to have difficulty
sticking to the standard. This can sometimes result in GPU-dependent bugs in the
implementation that have nothing to do with Android itself, but with the hardware drivers
provided by the manufacturers. I’ll point out any device-specific issues along our way
into OpenGL ES land.

opengl es 是一系列由Khronos集团提供的c语言头文件组成的api,连同一个很详细说明这些api怎么用。然后硬件厂商用这个说明去实现这个接口用在gpu和gpu驱动。不过有少许不同的是一些公司坚持(PowerVR) 的标准,但一些不是。这有时会导致依赖gpu的一些错误,这个android也一点办法也没有。但同时各个厂商提供硬件驱动

我会指出一些特别的设备的文档随着不断深入学习opnegles.

The Programming Model: An Analogy
OpenGL ES is in general a 3D graphics programming API. As such it has a pretty nice
and (hopefully) easy-to-understand programming model that we can illustrate with a
simple analogy.
Think of OpenGL ES as working like a camera. To take a picture you have to first go to
the scene you want to photograph. Your scene is composed of objects—say, a table
with more objects on it. They all have a position and orientation relative to your camera,
as well as different materials and textures. Glass is translucent and a little reflective, a
table is probably made out of wood, a magazine has the latest photo of some politician
on it, and so on. Some of the objects might even move around (e.g., a fruit fly you can’t
get rid of). Your camera also has some properties, such as focal length, field of view,
image resolution and size the photo will be taken at, and its own position and orientation
within the world (relative to some origin). Even if both objects and the camera are
moving, when you press the button to take the photo you catch a still image of the
scene (for now we’ll neglect the shutter speed, which might cause a blurry image). For
that infinitely small moment everything stands still and is well defined, and the picture
reflects exactly all those configurations of positions, orientations, textures, materials,
and lighting. Figure 7–1 shows an abstract scene with a camera, a light, and three
objects with different materials.

opengl es通常来说是一个3d图像编程的api,因为像它那样容易懂的编程模型可以被我们加以说明为简单的类推。

想想opengl es工作像个照样机。为了照一张照片你第一步要到场景里去获得图片,你的场景是由各个物体组成的,就是说,一张桌子和其它一些东西。它们相对于相机都有自己位置和方向,不同的材质和纹理也是一样。玻璃是透明的 和一点反射,桌子大多是木头做的,杂志有最新的相片和一些政治在上面等。一些物体可能还走来走去的。 (如一个个会飞的水果)你的相机同时也有一些属性,如焦距的长度可视度有多宽,图像分辨率和相片的大小,我们都会接触到的。虽然物体和相机都在移动,当你按下快门拍下相片时你还是捕捉到的静止的相片的在那个场景里(忽略快门速度引起的模糊相片),因为小到无穷小的时刻,第个物体都可以看作是静止的, 这样图片精确反映出所有这些信息,以上是一个抽象的场景里有一

                                                                                                                                                                                                                                                                               

Each object has a position and orientation relative to the scene’s origin. The camera,
indicated by the eye, also has a position in relation to the scene’s origin. The pyramid in
Figure 7–1 is the so-called view volume or view frustum, which shows how much of the
scene the camera captures and how the camera is oriented. The little white ball with the
rays is our light source in the scene, which also has a position relative to the origin. 
We can directly map this scene to OpenGL ES, but to do so we need to define a couple
of thingS

每个物体都有坐标和方向相对于整个场景的原点。通过眼睛看到,摄像头也有自己的坐标相对于场景。金字塔形的在上图被称为物体的集合,为我们展示了多少物体被捕捉到和摄像头所在,白色的带着光线的小球是场景里的光源,同样有自己的坐标相对场景的原点。我们可以直接通过opengl绘出这个场景,不过我们需要定义上面一第列的物体。

Profectoin投影图

This 2D mapping is done via something called projection. We already mentioned that
OpenGL ES is mainly concerned with triangles. A single triangle has three points define
in 3D space. To render such a triangle to the framebuffer, OpenGL ES needs to know
the coordinates of these 3D points within the pixel-based coordinate system of the
framebuffer. Once it knows those three corner-point coordinates, it can simply draw the
pixels in the framebuffer that are inside the triangle. We could even write our own little
OpenGL ES implementation by projecting 3D points to 2D, and simply draw lines
between them via the Canvas.
There are two kinds of projections that are commonly used in 3D graphics. :
Parallel, or orthographic, projection: If you have ever played with a
CAD application you might already know about these. A parallel
projection doesn’t care how far an object is away from the camera; the
object will always have the same size in the final image. This type of
projection is typically used for rendering 2D graphics in OpenGL ES.
Perspective projections: These are what we are used to when using
our eyes. Objects further away from us will appear smaller on our
retina. This type of projection is typically used when we do 3D
graphics with OpenGL ES.
In both cases we need something called a projection plane. This is nearly exactly the
same as the retina of our eyes. It’s where the light is actually registered to form the final
image. While a mathematical plane is infinite, our retina is limited in area. Our OpenGL

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值