我正在尝试使用OpenTK和glControl在C#WinForms中为我的游戏引擎创建一个编辑器。我正在尝试在C#中实现相同的代码库。我被困在OpenTK的转换矩阵中。
这是顶点着色器
#version 330 core
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 color;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = model * view * projection * vec4(position, 1.0f);
}
这是C#中的代码
Matrix4 projectionMatrix;
Matrix4 modelMatrix;
Matrix4 viewMatrix;
modelMatrix = Matrix4.Identity;
viewMatrix = Matrix4.Identity;
projectionMatrix = Matrix4.Identity;
int modelLoc = GL.GetUniformLocation(shader.getProgram(), "model");
GL.UniformMatrix4(modelLoc, false, ref modelMatrix);
viewMatrix = Matrix4.LookAt(new Vector3(0, 0, 3), new Vector3(0, 0, 3) + new Vector3(0, 0, -1.0f), new Vector3(0, 1, 0));
int viewLoc = GL.GetUniformLocation(shader.getProgram(), "view");
GL.UniformMatrix4(viewLoc, false, ref viewMatrix);
projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(1.3f, glWindow.Width / (float)glWindow.Height, 1.0f, 40.0f);
int projectionLoc = GL.GetUniformLocation(shader.getProgram(), "projection");
GL.UniformMatrix4(viewLoc, false, ref projectionMatrix);
我不知道OpenTK如何处理矩阵。视口中未显示任何内容。我正确设置矩阵?我的代码在使用GLM的C ++中运行良好。