From ae2906ca8302cd41f05582232799b35e0b05414d Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Sun, 12 Aug 2001 01:26:18 +0000 Subject: [PATCH] Fixed particle blending. --- src/fixer.h | 3 ++- src/opengl.c | 45 ++++++++++++++++++++++++++----------------- src/win95/awiffld.cpp | 16 +-------------- src/win95/awtexld.cpp | 20 +++++++++---------- 4 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/fixer.h b/src/fixer.h index 0c81f88..d5c1549 100644 --- a/src/fixer.h +++ b/src/fixer.h @@ -41,7 +41,8 @@ extern "C" { /* #define _mbclen strlen */ size_t _mbclen(const unsigned char *s); -#define RGBA_MAKE(r,g,b,a) (((r) << 24) | ((g) << 16) | ((b) << 8) | (a)) +//#define RGBA_MAKE(r,g,b,a) (((r) << 24) | ((g) << 16) | ((b) << 8) | (a)) +#define RGBA_MAKE(r,g,b,a) ((((unsigned char)a) << 24) | (((unsigned char)b) << 16) | (((unsigned char)g) << 8) | ((unsigned char)r)) #define MAX_PATH PATH_MAX diff --git a/src/opengl.c b/src/opengl.c index b7ca1c3..21bda70 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -33,7 +33,7 @@ static D3DTexture *CurrTextureHandle; #define TRANSLUCENCY_ONEONE 33 -static int CurrentTranslucencyMode = TRANSLUCENCY_OFF; /* opengl state variable */ +static enum TRANSLUCENCY_TYPE CurrentTranslucencyMode = TRANSLUCENCY_OFF; /* opengl state variable */ static GLuint CurrentlyBoundTexture = 0; /* opengl state variable */ static void CheckBoundTextureIsCorrect(GLuint tex) @@ -46,14 +46,20 @@ static void CheckBoundTextureIsCorrect(GLuint tex) CurrentlyBoundTexture = tex; } -static void CheckTranslucencyModeIsCorrect(int mode) /* TODO: use correct enum */ +static void CheckTranslucencyModeIsCorrect(enum TRANSLUCENCY_TYPE mode) { if (CurrentTranslucencyMode == mode) return; - switch(RenderPolygon.TranslucencyMode) { + switch(mode) { case TRANSLUCENCY_OFF: - glBlendFunc(GL_ONE, GL_ZERO); + if (TRIPTASTIC_CHEATMODE||MOTIONBLUR_CHEATMODE) { + // glBlendMode(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); + /* TODO: this may not be properly set... */ + } else { + glDisable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ZERO); + } break; case TRANSLUCENCY_NORMAL: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -81,6 +87,9 @@ static void CheckTranslucencyModeIsCorrect(int mode) /* TODO: use correct enum * return; } + if (mode != TRANSLUCENCY_OFF && CurrentTranslucencyMode == TRANSLUCENCY_OFF) + glEnable(GL_BLEND); + CurrentTranslucencyMode = mode; } @@ -119,7 +128,7 @@ GLuint CreateOGLTexture(D3DTexture *tex, unsigned char *buf) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex->w, tex->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->w, tex->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -149,7 +158,7 @@ void D3D_DecalSystem_Setup() void D3D_DecalSystem_End() { - glDepthMask(GL_TRUE); + glDepthMask(GL_TRUE); } /* ** */ @@ -281,21 +290,21 @@ void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDER void D3D_Particle_Output(PARTICLE *particlePtr, RENDERVERTEX *renderVerticesPtr) { - PARTICLE_DESC *particleDescPtr = &ParticleDescription[particlePtr->ParticleID]; + PARTICLE_DESC *particleDescPtr = &ParticleDescription[particlePtr->ParticleID]; int texoffset = SpecialFXImageNumber; GLfloat ZNear; int i; float RecipW, RecipH; D3DTexture *TextureHandle; - + TextureHandle = ImageHeaderArray[texoffset].D3DTexture; ZNear = (GLfloat) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale); CheckBoundTextureIsCorrect(TextureHandle->id); CheckTranslucencyModeIsCorrect(particleDescPtr->TranslucencyType); - + // if(ImageHeaderArray[texoffset].ImageWidth==256) { if (TextureHandle->w == 256) { RecipW = 1.0 / 256.0; @@ -324,15 +333,15 @@ void D3D_Particle_Output(PARTICLE *particlePtr, RENDERVERTEX *renderVerticesPtr) { int r, g, b, a; - r = (particlePtr->Colour >> 24) & 0xFF; - g = (particlePtr->Colour >> 16) & 0xFF; - b = (particlePtr->Colour >> 8) & 0xFF; - a = (particlePtr->Colour >> 0) & 0xFF; + r = (particlePtr->Colour >> 0) & 0xFF; + g = (particlePtr->Colour >> 8) & 0xFF; + b = (particlePtr->Colour >> 16) & 0xFF; + a = (particlePtr->Colour >> 24) & 0xFF; glColor4ub( MUL_FIXED(intensity,r), MUL_FIXED(intensity,g), - MUL_FIXED(intensity,g), + MUL_FIXED(intensity,b), a ); } else { @@ -346,10 +355,10 @@ void D3D_Particle_Output(PARTICLE *particlePtr, RENDERVERTEX *renderVerticesPtr) } else { int r, g, b, a; - r = (particlePtr->Colour >> 24) & 0xFF; - g = (particlePtr->Colour >> 16) & 0xFF; - b = (particlePtr->Colour >> 8) & 0xFF; - a = (particlePtr->Colour >> 0) & 0xFF; + r = (particlePtr->Colour >> 0) & 0xFF; + g = (particlePtr->Colour >> 8) & 0xFF; + b = (particlePtr->Colour >> 16) & 0xFF; + a = (particlePtr->Colour >> 24) & 0xFF; glColor4ub(r, g, b, a); } diff --git a/src/win95/awiffld.cpp b/src/win95/awiffld.cpp index e281079..1076937 100644 --- a/src/win95/awiffld.cpp +++ b/src/win95/awiffld.cpp @@ -52,7 +52,7 @@ class AwIffConvTransp if (*pCol == iTranspCol) return rawTranspCol; unsigned rv = AwIffConvNonTransp::DoConv(pCol,pPalette db_code1(DB_COMMA nPaletteSize)); if (rv != rawTranspCol) return rv; - + // make the colour non-transparent (nb: only an occasional case) // OK, Here's the plan: @@ -100,15 +100,7 @@ class AwIffConvTransp : (1<= 1100 - // VC5.0 gives inane warnings when += type operators - // are used on types smaller than int (even with - // explicit casting!) - #pragma warning(disable:4244) - #endif if ( nBlueDiffUp <= nBlueDiffDown @@ -155,12 +147,6 @@ class AwIffConvTransp { colAdj.g -= static_cast(1< itFormat(&listTextureFormats); !itFormat.done(); itFormat.next()) { - AdditionalPixelFormat const * pThisFormat = &itFormat(); + AdditionalPixelFormat * pThisFormat = &itFormat(); // is this format suitable? // ignoring alpha for now if @@ -495,12 +493,12 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR { // use display surface format pixelFormat = pfSurfaceFormat; + #endif - } - -/* Just convert the texture to 32bpp */ + /* Just convert the texture to 32bpp */ pixelFormat.palettizedB = 0; - pixelFormat.alphaB = 0; + + pixelFormat.alphaB = 1; pixelFormat.validB = 1; pixelFormat.bitsPerPixel = 32; pixelFormat.redLeftShift = 0; @@ -509,8 +507,8 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR pixelFormat.redRightShift = 0; pixelFormat.greenRightShift = 0; pixelFormat.blueRightShift = 0; - pixelFormat.dwRGBAlphaBitMask = 0x00000000; - + pixelFormat.dwRGBAlphaBitMask = 0xFF000000; + } } extern "C" { @@ -569,7 +567,7 @@ AwTl::SurfUnion AwBackupTexture::CreateTexture(AwTl::CreateTextureParms const & ++y; } - + /* temp junk */ Tex->w = m_nWidth; Tex->h = m_nHeight; @@ -1404,7 +1402,7 @@ void AwBackupTexture::ConvertRow(AwTl::PtrUnion pDest, unsigned nDestWidth, AwTl } } else - { + { if (m_bTranspMask) GenericConvertRow::Do(pDest,nDestWidth,pSrc.colourP+nSrcOffset,nSrcWidth); else