diff --git a/Source/Glitch64/geometry.cpp b/Source/Glitch64/geometry.cpp index 12d53a937..adfcc52b7 100644 --- a/Source/Glitch64/geometry.cpp +++ b/Source/Glitch64/geometry.cpp @@ -228,9 +228,13 @@ grDepthMask( FxBool mask ) float biasFactor = 0; void FindBestDepthBias() { + GLfloat vertices[4][3]; float f, bestz = 0.25f; int x; - if (biasFactor) return; + + if (biasFactor) + return; + biasFactor = 64.0f; // default value glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_DEPTH_TEST); @@ -242,14 +246,28 @@ void FindBestDepthBias() glDisable(GL_ALPHA_TEST); glColor4ub(255,255,255,255); glDepthMask(GL_TRUE); - for (x=0, f=1.0f; f<=65536.0f; x+=4, f*=2.0f) { + + for (x = 0; x < 4; x++) + vertices[x][2] = 0.5; + + for (x = 0, f = 1.0f; f <= 65536.0f; x += 4, f *= 2.0f) { float z; + + vertices[0][0] = float(x + 4 - widtho) / (width / 2); + vertices[0][1] = float(0 + 0 - heighto) / (height / 2); + vertices[1][0] = float(x + 0 - widtho) / (width / 2); + vertices[1][1] = float(0 + 0 - heighto) / (height / 2); + vertices[2][0] = float(x + 4 - widtho) / (width / 2); + vertices[2][1] = float(0 + 4 - heighto) / (height / 2); + vertices[3][0] = float(x + 0 - widtho) / (width / 2); + vertices[3][1] = float(0 + 4 - heighto) / (height / 2); glPolygonOffset(0, f); + glBegin(GL_TRIANGLE_STRIP); - glVertex3f(float(x+4 - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5); - glVertex3f(float(x - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5); - glVertex3f(float(x+4 - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5); - glVertex3f(float(x - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5); + glVertex3fv(vertices[0]); + glVertex3fv(vertices[1]); + glVertex3fv(vertices[2]); + glVertex3fv(vertices[3]); glEnd(); glReadPixels(x+2, 2+viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); diff --git a/Source/Glitch64/main.cpp b/Source/Glitch64/main.cpp index a3bfaa9ef..660b86386 100644 --- a/Source/Glitch64/main.cpp +++ b/Source/Glitch64/main.cpp @@ -1786,26 +1786,41 @@ static void render_rectangle(int texture_number, int src_width, int src_height, int tex_width, int tex_height, int invert) { + GLfloat planar_vertices[5][2]; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + planar_vertices[0][0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertices[0][1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + planar_vertices[1][0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertices[1][1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; + planar_vertices[2][0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); + planar_vertices[2][1] = -((int)dst_y + (int)src_height - heighto) / (float)(height / 2) * invert; + planar_vertices[3][0] = ((int)dst_x + (int)src_width - widtho) / (float)(width / 2); + planar_vertices[3][1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + planar_vertices[4][0] = ((int)dst_x - widtho) / (float)(width / 2); + planar_vertices[4][1] = -((int)dst_y - heighto) / (float)(height / 2) * invert; + glBegin(GL_QUADS); + glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); + glVertex2fv(planar_vertices[0]); + glMultiTexCoord2fARB(texture_number, 0.0f, (float)src_height / (float)tex_height); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); + glVertex2fv(planar_vertices[1]); + glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, (float)src_height / (float)tex_height); - glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), - invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); + glVertex2fv(planar_vertices[2]); + glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, 0.0f); - glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); + glVertex2fv(planar_vertices[3]); + glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); + glVertex2fv(planar_vertices[4]); + glEnd(); compile_shader();