如何在OpenGL ES 2.0中实现glOrthof [英] How to achieve glOrthof in OpenGL ES 2.0
问题描述
我正在尝试将我的 OpenGL ES 1
应用程序转换为 OpenGL ES 2
应用程序以便能够使用着色器。现在我使用glOrthof函数来创建一个真实大小的视口,这样我就可以将顶点放在OpenGL视图中的实际像素上。
I am trying to convert my OpenGL ES 1
application to a OpenGL ES 2
application to be able to use Shaders. Now I use the glOrthof function to have a "real sized viewport" so I can place the vertices at the "actual" pixel in the OpenGL View.
glOrthof(0, _frame.size.width, _frame.size.height, 0, -1, 1);
我无法在 OpenGL ES 2中找到如何实现这一点/ code>,是否有人可以告诉我该怎么做?
I am having trouble finding out how to achieve this in OpenGL ES 2
, is there anyone who can show me how to do this?
如果没有,是否有人有一个良好的 OpenGL ES 1到OpenGL ES 2
教程/解释?
If not, does anyone have a link to a good OpenGL ES 1 to OpenGL ES 2
tutorial/explanation?
推荐答案
glOrtho
方法除了创建一个新矩阵并将当前投影矩阵乘以此矩阵外别无其他。使用OpenGL ES 2.0,您必须自己管理矩阵。为了复制 glOrtho
行为,您需要在顶点着色器中为投影矩阵制作一个统一,然后将顶点乘以。通常你也有一个模型和一个视图矩阵(或一个组合的模型视图矩阵,就像在OpenGL ES 1中一样),你可以在投影变换之前转换你的顶点:
The glOrtho
method does nothing else than create a new matrix and multiply the current projection matrix by this matrix. With OpenGL ES 2.0 you have to manage matrices yourself. In order to replicate the glOrtho
behaviour you need a uniform for the projection matrix in your vertex shader, which you then multiply your vertices with. Usually you also have a model and a view matrix (or a combined modelview matrix, like in OpenGL ES 1) which you transform your vertices with before the projection transform:
uniform mat4 projection;
uniform mat4 modelview;
attribute vec4 vertex;
void main()
{
gl_Position = projection * (modelview * vertex);
}
glOrtho $ c的特定投影矩阵可以在此处找到$ c>构造。
The specific projection matrix that glOrtho
constructs can be found here.
这篇关于如何在OpenGL ES 2.0中实现glOrthof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!