在 OpenGL ES 2.0 中缩放和旋转
有没有一种方法可以在不使用 OpenGL ES 中矩阵的情况下包含宽高比校正?
我正在编写一个简单的着色器来旋转纹理。
void main()
{
mat2 rotX = mat2(cosA, sinA, -sinA, cosA);
vec4 a_pos = a_position;
a_pos.xy = a_position.xy * rotZ;
gl_Position = a_pos;
}
但问题是旋转时图像会倾斜。
在普通的 openGL 中,我们使用类似 gluPerspective(fov, (float)windowWidth/(float)windowHeight, zNear, zFar);
我如何使用着色器做同样的事情?
注意:我不想使用矩阵。
Is there a way to include aspect ratio correction without using matrices in OpenGL ES?
I am writing a simple shader to rotate a texture.
void main()
{
mat2 rotX = mat2(cosA, sinA, -sinA, cosA);
vec4 a_pos = a_position;
a_pos.xy = a_position.xy * rotZ;
gl_Position = a_pos;
}
But the problem is that the image is getting skewed when rotating.
In normal openGL, we use something like gluPerspective(fov, (float)windowWidth/(float)windowHeight, zNear, zFar);
How do i do the same with shaders?
Note: I'd prefer not using a matrix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在渲染对象的几何形状中包含纵横比修复?我在我的字体渲染工具中这样做了,每个矩形中的顶点位置通过屏幕的纵横比进行校正,是的,我知道使用矩阵修复更好更容易,但当我编写这个工具时我不知道,而且它工作正常:)
Include aspect ratio fix in geometry of rendered object? I did so in my font rendering tool, position of verts in each rect is corrected by aspect ratio of screen, and yes i know that its better and easier do use matrix fix but i didnt know it when i was writing this tool, and it works fine:)
您可以手动将 GluPerspective 的代码翻译为着色器:
http://www.opengl.org/wiki/GluPerspective_code
但是计算这个效率并不高每个顶点的矩阵。因此您可以为您的设备屏幕手动计算它。查看这些帖子
You can manually translate a code of GluPerspective to shader:
http://www.opengl.org/wiki/GluPerspective_code
But it is not efficient to calcuelte this matrix for each vertex. So you can manually calculate it for your device screen. Look at these posts
只需更改旋转的矩阵乘法顺序即可:
Just change the matrix multiplication order for rotation: