更改示例中的 OpenGL 顶点属性

发布于 2024-11-10 01:48:45 字数 958 浏览 0 评论 0原文

我正在使用本教程/示例 在 iPhone 上进行一些基本的对象跟踪。一切工作正常,我什至对性能进行了很多调整,但我仍然遇到一个问题。

基本问题是我对 OpenGL 的理解不够好,我应该因为可耻地获取示例代码并将其变成适合我的东西而受到惩罚。事实上,我正在受到惩罚;

该示例展示了如何将 iPhone 的相机渲染(使用着色器)到屏幕外纹理中,以便能够对其进行处理并将其显示在屏幕上。现在我发现它使用一系列顶点属性来绘制纹理/图层(尽管我进行了谷歌搜索,但我几乎不明白这一原理)。

顶点数组如下:

static const GLfloat squareVertices[] = {
        -1.0f, -1.0f,
        1.0f, -1.0f,
        -1.0f,  1.0f,
        1.0f,  1.0f,
};

static const GLfloat textureVertices[] = {
        1.0f, 1.0f,
        1.0f, 0.0f,
        0.0f,  1.0f,
        0.0f,  0.0f,
};

我还发现这些顶点属性可以改变绘制纹理的方向。纹理现在以纵向绘制,这意味着如果我将 iPhone 保持横向(这是我想要的),并让视图旋转,我在屏幕上看到的所有内容都是 90 度角的相机。

我认为我将问题范围缩小到足以归咎于这些顶点,并且我一直在某种程度上弄乱它们的值,但没有任何可接受的结果。

有谁可以帮我画风景中的纹理吗?

PS:如果我反转 'squareVerticles' 的值,我可以获得 180 度旋转的图片。但我希望纹理旋转 90 度,而不是 180 度。

I am using this tutorial / sample to do some basic object tracking on the iPhone. Everything works fine, I even tweaked the performance a whole lot, but I am still stuck with one problem.

The basic problem is that I do not understand OpenGL well enough and I should be punished for shamefully taking sample code and turning it into something that works for me. As a matter of fact I am being punished;

The sample shows how to render (with shaders) the iPhone's camera into an offscreen texture in order to be able to process it and show it on screen. Now I have figured out that it draws the texture/layer using an array of vertex attributes (a principle I barely understand, despite my Google searches).

The vertex array's are as follows:

static const GLfloat squareVertices[] = {
        -1.0f, -1.0f,
        1.0f, -1.0f,
        -1.0f,  1.0f,
        1.0f,  1.0f,
};

static const GLfloat textureVertices[] = {
        1.0f, 1.0f,
        1.0f, 0.0f,
        0.0f,  1.0f,
        0.0f,  0.0f,
};

I have also figured out that these vertex attributes can alter the orientation of the drawn texture. The texture is now drawn in portrait, which means that if I keep my iPhone in landscape (which I desire), and let the views rotate along, everything I see on the screen is a camera with a 90 degree angle.

I think I narrowed the problem down enough to blame these vertexes and I have been messing around with their values somewhat but without any acceptable result.

Is there anybody out there who can help me draw the texture in landscape?

P.S: if I inverse the values of 'squareVerticles' I am able to get a 180 degree rotated picture. But I want the texture to be rotated 90 degrees, not 180.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2024-11-17 01:48:45

想象一下,您的屏幕具有从 -1.0,-1.0(左、下)到 1.0, 1.0 的标准化坐标。第一个数组指定正方形顶点的坐标(大概是三角形带,因为它们以“Z”方式给出)。

第二个数组指定纹理坐标。同样的事情,只不过它们在 0.0, 1.0 范围内。

因此,顺时针旋转 90 度:

1.0f, 0.0f
0.0f, 0.0f
1.0f, 1.0f
0.0f, 1.0f

逆时针:

0.0f, 1.0f
1.0f, 1.0f
0.0f, 0.0f
1.0f, 0.0f

我希望这可行!

Imagine that your screen has normalized coordinates that go from -1.0,-1.0 (left, bottom) to 1.0, 1.0. The first array specifies the coordinates of the vertices of a square (presumably as a triangle strip, because they are given in a "Z" fashion).

The second array specifies the texture coordinates. Same thing, except that they are in the 0.0, 1.0 range.

So, to rotate 90 degrees clockwise:

1.0f, 0.0f
0.0f, 0.0f
1.0f, 1.0f
0.0f, 1.0f

anticlockwise:

0.0f, 1.0f
1.0f, 1.0f
0.0f, 0.0f
1.0f, 0.0f

I hope that works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文