Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using WebGL, I'm initialising my projection matrix with the following code, using gl-matrix;

JavaScript
const matrix = mat4.create();
mat4.ortho(matrix, -width / 2, width / 2, -height / 2, height / 2, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
where width and height are the window dimensions.

The viewport is set up as such;
JavaScript
gl.viewport(0, 0, width, height);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clearDepth(1.0);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

For some reason, the faces' depths are being calculated incorrectly, but it works fine with a perspective projection. How can I fix this?

See image here[^]

What I have tried:

Playing around with depth parameters and methods, googling for an hour
Posted
Updated 14-Nov-22 13:42pm
v4
Comments
Kornfeld Eliyahu Peter 17-Nov-22 5:47am    
There is a nice tutorial here: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Creating_3D_objects_using_WebGL

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900