我正在尝试使用着色器和 VBO 绘制两个简单的四边形。但作为输出,我只得到一个四边形。
我在哪里遗漏了什么?
初始化代码(跳过着色器和矩阵初始化代码):
gl.GenBuffers((int) VAO_IDs.NumVAOs, VAOs);
gl.BindVertexArray(VAOs[(int) VAO_IDs.Guads]);
float[] vertices =
{
-0.095f, 0.095f, 0.695f, //first quad
-0.095f, 0.0475f, 0.695f,
-0.095f, 0.00475f, 0.7455f,
-0.095f, 0.095f, 0.7455f,
-0.095f, 0.0475f, 0.695f, //second quad
-0.095f, 0f, 0.695f,
-0.095f, 0f, 0.7455f,
-0.095f, 0.0475f, 0.7455f
};
gl.GenBuffers((int) Buffer_IDs.NumBuffers, Buffers);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, Buffers[(int) Buffer_IDs.ArrayBuffer]);
unsafe
{
fixed (float* verts = vertices)
{
var prt = new IntPtr(verts);
gl.BufferData(OpenGL.GL_ARRAY_BUFFER, vertices.Length*sizeof (float), prt, OpenGL.GL_STATIC_DRAW);
}
}
gl.VertexAttribPointer((uint)Attrib_IDs.vPosition, 3, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
gl.EnableVertexAttribArray((uint)Attrib_IDs.vPosition);
显示代码:
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);
shaderProgram.Bind(gl);
shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
gl.BindVertexArray(VAOs[(int)VAO_IDs.Guads]);
gl.DrawArrays(OpenGL.GL_QUADS, 0, 8);
shaderProgram.Unbind(gl);
gl.Flush();