0
\$\begingroup\$

I know: similar questions have been asked - but I didn't find a solution.


So at first the basic problem: It seems that convex Models (currently I load them from .obj files) render fine, but concave Models seem to have some kind of depth-problem:

1: right ear of blender-ape "shines through" 2: Should be a hollow cylinder

The inside of the cylinder renders fine (?!). So I guess here is some code: Eukild.java:

public static Matrix4f createProjectionMatrix(float fov, float far, float near){
    Matrix4f projectionMatrix = new Matrix4f();
    float aspectRatio = StaticVars.ratio;
    float y_scale = (float) ((1f / Math.tan(Math.toRadians(fov / 2f))));
    float x_scale = y_scale / aspectRatio;
    float frustum_length = far - near;

    projectionMatrix.setValue(x_scale, 0, 0);   
    projectionMatrix.setValue(y_scale, 1, 1);
    projectionMatrix.setValue(-((far + near) / frustum_length), 2, 2);
    projectionMatrix.setValue(-1, 2, 3);
    projectionMatrix.setValue(-((2 * near * far) / frustum_length), 3, 2);
    projectionMatrix.setValue(0, 3, 3);
    return projectionMatrix;
}

(called with:

Euklid.createProjectionMatrix(90, 0.1f, 1000);

) While rendering I enabled Depth Testing and Back Culling with:

GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCullFace(GL11.GL_BACK);

In GLSL I calculate the Position in the vertex shader with:

gl_Position = projection*transform*vec4(vertices, 1.0);

If you need any additional code just write what you need. I am used to develop with LWJGL 2 and just converted my engine to LWJGL 3.

Thank you very much for your help!!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.