I spent most of yesterday debugging because I couldn’t implement perspective projection. Anyway, I thought my issue was the fact that my matrix multiplication was incorrect, which I fixed (I then spent an hour this morning fixing orthographic projection). Now I’m having trouble getting perspective projection to work, which I’ve tried to debug but I’m not sure how to fix it.
t = top, b = bottom, l = left, r = right, n = zNear, f = zFar
Debugging results - n = 1, f = 100 (nothing is displayed):
What could the problem be? I’m not really sure what I’m doing wrong. I’ve tried translating the Z coordinate and extending the far pane, but I see nothing. I’m clearing the depth buffer and I tried enabling depth testing. None of those things worked.
EDIT: I think it must be something to do with the Z coordinate, since when I translate it, the W coordinate changes but nothing is displayed.
The viewport is being set as the width and the height of the screen.
This is the render method (it uses my LWJGL wrapper/library). This is the same for orthographic projection (except for clearing depth buffer):
I’m updating my view*Projection uniform variable with this method (you can see the values of the matrices (column major) in my OP), this is the same for orthographic projection:
public Matrix4 update() {
return scale.copy().multiply(rotation).multiply(translation)
.multiply(projection);
}
This is how I’m setting the data for the attribute (it shouldn’t really matter since orthographic projection works and uses the same data):
data = FloatBufferIO.create(0f, 0f, 100f, 0f, 0f, 100f, 100f, 100f);
vertices = new BufferObject(Target.ARRAY_BUFFER, data,
Usage.STATIC_DRAW);
vao = new VertexArrayObject();
vao.attach();
vertices.attach();
vao.formatAttributeData(program.getAttributeIndex("position"), 2, // enables the attribute & calls glVertexAttribPointer
DataType.SIGNED_FLOAT, false, 8, 0);
VertexArrayObject.detach();
When resized (and when the camera is created), this is called in the PerspectiveCamera class:
Edit2: I’ll try transposing the projection matrix, since the page you linked me to has the exact same matrix transposed. It doesn’t display, however this is the result:
Edit3: Never-mind, that was based on row major order. It gives the exact same matrix. I think that the issue must be related to something else.