假设我的屏幕是(800*600)并且我使用Triangle_Strip(在NDC中)使用以下顶点位置绘制了Quad(2D ):
float[] vertices = {-0.2f,0.2f,-0.2f,-0.2f,0.2f,0.2f,0.2f,-0.2f};
Run Code Online (Sandbox Code Playgroud)
我以这种方式设置了转换矩阵:
Vector2f position = new Vector2f(0,0);
Vector2f size = new Vector2f(1.0f,1.0f);
Matrix4f tranMatrix = new Matrix4f();
tranMatrix.setIdentity();
Matrix4f.translate(position, tranMatrix, tranMatrix);
Matrix4f.scale(new Vector3f(size.x, size.y, 1f), tranMatrix, tranMatrix);
Run Code Online (Sandbox Code Playgroud)
我的顶点着色器:
#version 150 core
in vec2 in_Position;
uniform mat4 transMatrix;
void main(void) {
gl_Position = transMatrix * vec4(in_Position,0,1.0);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我应该使用哪个公式来修改我的四边形的坐标转换(以像素为单位)?
例如 :
- 设置比例:(50px,50px)=>Vector2f(width,height)
- 设置位置:(100px,100px)=>Vector2f(x,y)
为了更好地理解,我将创建一个函数将我的像素数据转换为NDC,将它们发送到顶点着色器旁边.我被建议使用正交投影,但我不知道如何正确创建它,你可以看到我的顶点着色器我不使用任何投影矩阵.谢谢 !
这是一个类似于我的主题,但不是很清楚:
我按照公式创建了我的正交投影矩阵但似乎没有出现,这是我继续进行的方式:
public static Matrix4f glOrtho(float left, float right, float bottom, …
Run Code Online (Sandbox Code Playgroud)