(iOS) OpenGL ES (2.0) 应用程序,如何在Z方向移动对象?
我正在 XCode 中使用 OpenGL ES (2.0) 应用程序 (iOS) 源代码,并试图使彩色方块在 Z 坐标中移动,因此我尝试从
gl_Position.y += sin(translate) 更改着色器代码/2.0;
到
gl_Position.z += sin(翻译) / 2.0; 没有成功。
广场根本没有动。 它在 X 和 Y 思想中移动得很好...... 初始化 OpenGL 时是否需要激活一些选项?谢谢!
更新: 我已经上传了一个例子。这大致是 XCode 生成的 OpenGL ES 模板,我只是添加了创建深度缓冲区的调用,以及 Shader.vsh 中的 gl_Position.x 到 gl_Position.z += sin(translate) / 2.0f。
我希望看到正方形在 Z 坐标上以正弦形式移动,但事实并非如此。要么它保持静止,要么,如果我乘以 sin(),它就会循环出现和消失。
如果有人能帮助我,我将非常感激,因为真诚地我不知道还能做什么,相信我,我尝试了很多......
源代码位于:http://cl.ly/24240x2D1t2A3I0c1l1P
谢谢!
I'm playing with OpenGL ES (2.0) Application (iOS) source code in XCode and was trying to make the colorful square move in the Z coordinate, so I tried to change the shader code from
gl_Position.y += sin(translate) / 2.0;
to
gl_Position.z += sin(translate) / 2.0;
with no success.
The square doesn't move at all.
It moves well in X and Y thought...
Is there some option I need to activate when initializing OpenGL? Thanks!
UPDATE:
I've uploaded an example. This is roughly the OpenGL ES template that XCode generates, I just added the calls to create the depth buffer, and the gl_Position.x to gl_Position.z += sin(translate) / 2.0f in the Shader.vsh.
I wish to see the square move in a sinusoidal form on the Z coordinate but it just won't. Either it keeps still or, if I multiply the sin(), it will appear and disappear in a cycle.
If anyone can help me out I'll be most grateful, since sincerely I do not know what else to do, and believe me I tried alot...
The source is in a zip at: http://cl.ly/24240x2D1t2A3I0c1l1P
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在查看的示例没有深度缓冲区和用于 2D GL 的透视矩阵。请查看 aurioTouch 示例。在 EAGLView 类中,您会注意到一个用于实现深度缓冲区的选项。两者结合起来(因为 aurioTouch 不实现着色器)应该可以更好地理解
我认为您的方法中的操作顺序导致了问题。
这是我在应用程序“Live Effects Cam”中使用的代码,它将实时相机作为形状上的 GL 纹理放置:
The example you are looking at has no depth buffer and a perspective matrix intended for 2D GL. Look at the aurioTouch example instead. in the EAGLView class you will notice an option to implement the depth buffer. The two combined (since aurioTouch doesn't implement shaders) should give a better understanding
I think the order of operations you have in your method are causing the problem.
Here's the code I use in my app "Live Effects Cam" which places the live camera as a GL Texture on shapes:
我已将其添加到我的代码中(... <----),现在我得到一个粉红色的屏幕(笑)。有什么想法吗?这真是令人沮丧。我不应该在 setFrame..presentFrame.. 中做一些事情吗?
I've added that to my code (the ... <----) and now I get a pinkish screen (lol). Any ideas? This is really frustrating. Shouldn't I do something in the setFrame.. presentFrame..?