在OpenGL中,我怎样才能获得像素和gl.gltranslatef关系(floatx,Y,Z)?像素、关系、OpenGL、gl

2023-09-06 06:11:05 作者:不浪不人生

我想了解在Android上的OpenGL的东西。在gl.gltranslatef(X,Y,Z)的调用,我在一些单位转移我的纹理+已经x方向。但我无法找到的像素数就1个单位的x属于哪一种?

I am trying to learn opengl stuff on Android. In the gl.gltranslatef(x,y,z) call, I am shifting my texture by some units in the +ve x direction. But I am unable to find the number of pixels does 1 unit of x belong to?

下面是我在做什么:我叫gl.glviewport(0,0,宽,高); //这将设置我的矩形为0,0角落lowerleft,然后扩展它容纳的宽度和高度。

Here is what I am doing: I call gl.glviewport(0,0,width,height); // This will set my rectangle with 0,0 as lowerleft corner and then extend it to accommodate width and height.

然后我打电话给gl.glfrustrum(-5,5,-7,7,3,7); //我有点糊涂了这一呼吁是如何使用我gl.glviewport设定的尺寸。

Then I call to gl.glfrustrum(-5,5,-7,7,3,7); // I am little confused how this call is using the dimensions I set in gl.glviewport.

如何将-5到5个单位从左至右在上面的调用,转换为像素Android的屏幕上?

How will -5 to 5 units from left to right in the above call, translate to pixels on the screen of android?

我的意思是如果width = 320和height = 533像素,那会是怎样占据了屏幕上的像素数量,由于gl.glfrustrum电话吗?

I mean if width = 320 and height = 533 pixels, then what will be the number of pixels occupied on the screen due to the gl.glfrustrum call?

我在gl.gltranslatef调用指定XSHIFT为5.0的实验,但它并没有转化为正确的或在屏幕的左上角的位图,当我把它提高到6,它的一部分仍然在可见屏幕。

I am experimenting in the gl.gltranslatef call by specifying xshift as 5.0, but it does not translate the bitmap at the right or left corner of the screen, when I increase it to 6, part of it is still visible on the screen.

谢谢Siddhesh

Thanks Siddhesh

总之,我正在寻找的的最大数量(在X而言),这将重新我的Andr​​oid手机屏幕present极端的角落。

推荐答案

glViewpoint告诉它什么矩形(像素),你的OpenGL输出应该显示出来。

glViewpoint tells it what rectangle (in pixels) your OpenGL output should be displayed in.

glFrustum告诉它你的世界是什么单位的坐标应该映射到口中。

glFrustum tells it what coordinates in your "world" units should be mapped to that viewport.

这是很重要的一点:你的电话glFrustum不仅包括高度和宽度,又是一个深度。既然你指定一个截锥体,而不是一个立方体,这意味着一个Z坐标东西任何地方,但你的视锥的眼前会从观众的距离适当地缩小。

An important point: your glFrustum call includes not only a height and width, but also a depth. Since you are specifying a Frustum, not a cube, that means anything with a Z coordinate anywhere but the very front of your frustum will be scaled down appropriately for its distance from the viewer.

因此​​,当你到一个的glTranslatef ,其中特定对象将移动(以像素计)的距离将取决于从观众的距离。在进一步远离它是从观察者的更少的像素的特定侧向或向上/向下将转化为

As such, when you to a glTranslatef, the distance by which a particular object will move (in terms of pixels) will depend on its distance from the viewer. The further away it is from the viewer, the fewer pixels a particular sideways or up/down will translate to.

根据你在做什么其他,一个简单的方法来处理,这可能是使用 glOrtho 而不是 glFrustum glOrtho 给正交模式,这意味着没有透视比例从浏览器完成的,因此给定的X或Y的距离将转化为相同数量的像素,无论距离远近。

Depending on what else you're doing, one easy way to deal with this might be to use glOrtho instead of glFrustum. glOrtho gives orthographic mode, which means no perspective scaling is done, so a given X or Y distance will translate to the same number of pixels, regardless of distance from the viewer.

 
精彩推荐