我试着扭转我的gui。我有预测:
glm::mat4 my_projection = glm::mat4( 2.0/static_cast<float>(m_window->getSize().x), 0.0, 0.0, -1.0,
0.0, 2.0/static_cast<float>(m_window->getSize().y), 0.0, -1.0,
0.0, 0.0, -1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
着色器:
#version 330 core
in vec3 pos;
in vec2 UV;
in vec4 col;
uniform vec2 translation;
uniform mat4 my_projection;
out vec2 vecUV;
out vec4 vecColor;
void main()
{
vec3 tran_pos = vec3(pos + vec3(translation, 0.0f));
gl_Position = vec4(tran_pos, 1.0f) * my_projection;
vecUV = UV;
vecColor = col;
}
当我改变时,我不知道如何转身
m_window->getSize().x
到
-m_window->getSize().x
和
m_window->getSize().y
到
-m_window->getSize().y
一切都消失了。我怎么能扭转这个?
编辑:(解决方案)
glm::mat4 my_projection = glm::ortho(0.0f, (float)m_window->getSize().x, (float)m_window->getSize().y, 0.0f);
// Shader:
#version 330 core
in vec3 pos;
in vec2 UV;
in vec4 col;
uniform vec2 translation;
uniform mat4 my_projection;
out vec2 vecUV;
out vec4 vecColor;
void main()
{
vec3 tran_pos = vec3(pos + vec3(translation, 0.0f));
gl_Position = my_projection * vec4(tran_pos, 1.0f);
vecUV = UV;
vecColor = col;
}
只需使用glm函数进行矩阵投影,然后按位置乘以投影。