Hey so I have a few questions about Shaders, Matrices, and the perspective projection.
I’m trying to change the camera for a Triangle I’m rendering
So I have a vertex Shader, that takes in a MVP matrix
#version 330 core
layout(location = 0) in vec3 position;
uniform mat4 MVP;
void main()
{
gl_Position = MVP * vec4(position, 1);
}
When I attempt to set the projection matrix to a calculated perspective [ 45.0f FOV, 4.0/3.0 aspect, .01f nearPlane, 100.0 farPlane].
I get nothing on the screen
If I do nothing to my Matrix, the triangle shows since I did nothing with my Matrix (They’re all just identities)
//Works but the Projection Matrix and everything is set to defaults :(
matrixID = GL20.glGetUniformLocation(programID, "MVP");
Matrix4f projection = new Matrix4f();
Matrix4f view = new Matrix4f();
Matrix4f model = new Matrix4f();
Matrix4f MVP = Matrix4f.mul(view, model, null);
Matrix4f.mul(projection, MVP, MVP);
mvpBuffer = BufferUtils.createFloatBuffer(16);
MVP.store(mvpBuffer);
mvpBuffer.flip();
So my question is there something ‘special’ I have to do to use a perspective matrix?
Using this code I get nothing on the screen
Matrix4f projection = projectionPerspectiveMatrix(45.0f, 4.0f/3.0f, 0.01f, 100.0f);
//Full method
public Matrix4f projectionPerspectiveMatrix(float fieldOfView, float aspectRatio, float nearPlane, float farPlane)
{
Matrix4f mat = new Matrix4f();
float yScale = coTan(degreeToRadians(fieldOfView / 2.0f));
float xScale = yScale / aspectRatio;
mat.m00 = xScale;
mat.m11 = yScale;
mat.m22 = (farPlane + nearPlane) / (nearPlane - farPlane);
mat.m23 = -1;
mat.m32 = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
return mat;
}