From 29658ef3de4c99b00a279e245ebde3c43e7b84f7 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Fri, 15 May 2020 20:43:55 +0100 Subject: [PATCH] Revert to more traditional GL depth values to fix ortho --- GL/draw.c | 14 +------------- samples/Makefile | 1 + samples/depth_funcs_ortho/main.c | 3 ++- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/GL/draw.c b/GL/draw.c index 1a3f4f1..527e7dd 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -939,24 +939,12 @@ GL_FORCE_INLINE void divide(SubmissionTarget* target) { /* Perform perspective divide on each vertex */ Vertex* vertex = _glSubmissionTargetStart(target); - /* PVR expects with invW or invZ as the final depth coordinate, - * but there are issues with that. Using invW means that orthographic - * projections fail (because W is always 1). invZ fails when stuff is near - * the near plane (because it ends up <= 0) so what we do is take invZ - * and add the near-plane distance (plus an epsilon value) to take it above 0 - * then invert that. */ - - Matrix4x4* proj = _glGetProjectionMatrix(); - float m22 = (*proj)[10]; - float m32 = (*proj)[14]; - float zNear = MATH_Fast_Divide((2.0f * m32), (2.0f * m22 - 2.0f)); - ITERATE(target->count) { float f = MATH_Fast_Invert(vertex->w); vertex->xyz[0] *= f; vertex->xyz[1] *= f; vertex->xyz[2] = MATH_Fast_Invert( - vertex->xyz[2] + zNear + 0.05f + (vertex->xyz[2] * f) * 0.5f + 0.55f ); ++vertex; } diff --git a/samples/Makefile b/samples/Makefile index 49a78d8..959e9d8 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -31,3 +31,4 @@ all: $(KOS_MAKE) -C mipmap all $(KOS_MAKE) -C lights all $(KOS_MAKE) -C depth_funcs_alpha_testing + $(KOS_MAKE) -C depth_funcs_ortho diff --git a/samples/depth_funcs_ortho/main.c b/samples/depth_funcs_ortho/main.c index 234a628..01a3639 100644 --- a/samples/depth_funcs_ortho/main.c +++ b/samples/depth_funcs_ortho/main.c @@ -30,7 +30,8 @@ void ReSizeGLScene(int Width, int Height) glMatrixMode(GL_PROJECTION); glLoadIdentity(); - //gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); + glOrtho(0.0, 640.0, 0.0, 480.0, 0.0, 1.0); + glMatrixMode(GL_MODELVIEW); }