切换到 OpenGLES 2.0 并遇到顶点着色器问题。如果我没有更正着色器内部的顶点位置并在 (-1) - 1 范围内指定顶点,那么一切正常,我看到了我的三角形,但是当我尝试修改位置时,我得到了空白屏幕。请看一下代码,如果我是白痴,请告诉我。
static float[] squareVertices2 = {
512f, 0f, 0.0f,
1024f, 768f, 0.0f,
0f, 768f, 0.0f
};
平行投影
projection[0] = 2 / 1024;
projection[1] = (2 / 768);
projection[2] = 1;
projection[3] = -1;
获取句柄
int m_a_positionHandle = GL.GetAttribLocation(CurrentShaderProgram, "a_position");
int m_a_colorHandle = GL.GetAttribLocation(CurrentShaderProgram, "a_color");
int m_u_mvpHandle = GL.GetUniformLocation(CurrentShaderProgram, "uv_Projection");
使用
GL.UseProgram(CurrentShaderProgram);
GL.VertexAttribPointer(m_a_positionHandle, 3, VertexAttribPointerType.Float , false, 0, squareVertices2);
GL.EnableVertexAttribArray(m_a_positionHandle);
GL.VertexAttribPointer(m_a_colorHandle, 4, VertexAttribPointerType.Float, false, 0, squareColors);
GL.EnableVertexAttribArray(m_a_colorHandle);
GL.Uniform4(m_u_mvpHandle, projection[0], projection[1], projection[2], projection[3]);
GL.DrawArrays(BeginMode.Triangles, 0, 3);
着色器来源:
@"uniform vec4 uv_Projection;
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
void main()
{
gl_Position = vec4(a_position.xy * uv_Projection.xy, a_position.z, a_position.w);
v_color = a_color;
}"
我在 Windows 平台上使用 C# 和 OpenTK。任何帮助表示赞赏。谢谢。