我不确定为什么这段代码不能简单地在屏幕上绘制一个三角形(正交)。我正在使用OpenTK 1.1,它与OpenGL 1.1相同。
List<Vector3> simpleVertices = new List<Vector3>();
simpleVertices.Add(new Vector3(0,0,0));
simpleVertices.Add(new Vector3(100,0,0));
simpleVertices.Add(new Vector3(100,100,0));
GL.MatrixMode(All.Projection);
GL.LoadIdentity();
GL.MatrixMode(All.Projection);
GL.Ortho(0, 480, 320, 0,0,1000);
GL.MatrixMode(All.Modelview);
GL.LoadIdentity();
GL.Translate(0,0,10);
unsafe
{
Vector3* data = (Vector3*)Marshal.AllocHGlobal(
Marshal.SizeOf(typeof(Vector3)) * simpleVertices.Count);
for(int i = 0; i < simpleVertices.Count; i++)
{
((Vector3*)data)[i] = simpleVertices[i];
}
GL.VertexPointer(3, All.Float, sizeof(Vector3), new IntPtr(data));
GL.DrawArrays(All.Triangles, 0, simpleVertices.Count);
}
这段代码在绘制函数中每个更新周期执行一次。我认为我正在做的事情(但显然并没有)是创建一组位置顶点来形成一个三角形,并将其绘制在相机前方10个单位处。
为什么这段代码没有绘制出三角形?
GL.Ortho(0, 480, 0, 320, 0, 1000);
? - Jackson Pope