From accc5bbd8d9f9cfaa5e6e21d762542256fa2cf39 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Sun, 5 Oct 2008 23:51:04 -0700 Subject: [PATCH] Trying out using alpha test to emulate color keying. The original D3D code used SetColorKey to remove the transparent bits from certain textures, like the HUD alien tail. As there's no straightforward way to do this in OpenGL without using fragment programs, enable alpha test to reject fragments with zero alpha. This might break a few things that have alpha set to zero when translucency is off -- I fixed the few cases that I found. --- src/kshape.c | 2 +- src/opengl.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/kshape.c b/src/kshape.c index 312d8ca..7107c0b 100644 --- a/src/kshape.c +++ b/src/kshape.c @@ -1229,7 +1229,7 @@ static void PredatorSeeAliensVisionPolygon_Construct(POLYHEADER *polyPtr) } else { - alpha = 0; + alpha = 255; RenderPolygon.TranslucencyMode = TRANSLUCENCY_OFF; } diff --git a/src/opengl.c b/src/opengl.c index 89bb7de..f4f041b 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -87,11 +87,14 @@ static int svarrc, starrc; /* Do not call this directly! */ static void SetTranslucencyMode(enum TRANSLUCENCY_TYPE mode) { + pglDisable(GL_ALPHA_TEST); + switch(mode) { case TRANSLUCENCY_OFF: if (TRIPTASTIC_CHEATMODE||MOTIONBLUR_CHEATMODE) { pglBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); } else { + pglEnable(GL_ALPHA_TEST); pglBlendFunc(GL_ONE, GL_ZERO); } break; @@ -132,6 +135,8 @@ void InitOpenGL() CurrentTranslucencyMode = TRANSLUCENCY_OFF; pglBlendFunc(GL_ONE, GL_ZERO); + pglAlphaFunc(GL_GREATER, 0.0f); + CurrentFilteringMode = FILTERING_BILINEAR_OFF; pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -2341,7 +2346,7 @@ void D3D_DrawColourBar(int yTop, int yBottom, int rScale, int gScale, int bScale unsigned int c; c = GammaValues[i]; - pglColor4ub(MUL_FIXED(c,rScale), MUL_FIXED(c,gScale), MUL_FIXED(c,bScale), 0); + pglColor4ub(MUL_FIXED(c,rScale), MUL_FIXED(c,gScale), MUL_FIXED(c,bScale), 255); x[0] = (Global_VDB_Ptr->VDB_ClipRight*i)/255; x[0] = (x[0] - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX; @@ -2355,7 +2360,7 @@ void D3D_DrawColourBar(int yTop, int yBottom, int rScale, int gScale, int bScale i++; c = GammaValues[i]; - pglColor4ub(MUL_FIXED(c,rScale), MUL_FIXED(c,gScale), MUL_FIXED(c,bScale), 0); + pglColor4ub(MUL_FIXED(c,rScale), MUL_FIXED(c,gScale), MUL_FIXED(c,bScale), 255); x[2] = (Global_VDB_Ptr->VDB_ClipRight*i)/255; x[2] = (x[2] - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX; y[2] = yBottom; @@ -2409,7 +2414,7 @@ void ColourFillBackBufferQuad(int FillColour, int x0, int y0, int x1, int y1) r = ((FillColour >> 16) & 0xFF); a = ((FillColour >> 24) & 0xFF); - pglColor4ub(r, g, b, a); + pglColor4ub(r, g, b, 255); x[0] = x0; x[0] = (x[0] - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX; @@ -2517,7 +2522,8 @@ void BltImage(RECT *dest, DDSurface *image, RECT *src) pglDisable(GL_BLEND); pglDisable(GL_DEPTH_TEST); pglDisable(GL_TEXTURE_2D); - + pglDisable(GL_ALPHA_TEST); + pglPixelStorei(GL_UNPACK_ALIGNMENT, 1); pglPixelStorei(GL_UNPACK_ROW_LENGTH, image->w); pglPixelZoom((double)width/(double)width1, (double)height/(double)height1);