From e0617af5e655d10a2ad5cb9709611d4c9529f2ba Mon Sep 17 00:00:00 2001 From: Cyp Date: Sun, 20 Feb 2011 20:24:00 +0100 Subject: [PATCH] Hack in the team colour when shaders aren't supported. Ugly, but better than nothing. --- lib/ivis_opengl/piedef.h | 2 +- lib/ivis_opengl/piedraw.cpp | 16 +++++++++++----- lib/ivis_opengl/screen.cpp | 3 +++ lib/ivis_opengl/screen.h | 2 ++ src/component.cpp | 10 +++++----- src/display3d.cpp | 12 ++++++------ 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/ivis_opengl/piedef.h b/lib/ivis_opengl/piedef.h index 8c6f5c1c6..46e333a8f 100644 --- a/lib/ivis_opengl/piedef.h +++ b/lib/ivis_opengl/piedef.h @@ -55,7 +55,7 @@ typedef struct {SDWORD texPage; SWORD tu, tv, tw, th;} PIEIMAGE; /**< An area of * Global ProtoTypes */ /***************************************************************************/ -extern void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int pieFlag, int pieFlagData); +extern void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int pieFlag, int pieFlagData, int shaderlessTeamColourHackAmount = 0); extern void pie_DrawImage(const PIEIMAGE *image, const PIERECT *dest); extern void pie_GetResetCounts(unsigned int* pPieCount, unsigned int* pTileCount, unsigned int* pPolyCount, unsigned int* pStateCount); diff --git a/lib/ivis_opengl/piedraw.cpp b/lib/ivis_opengl/piedraw.cpp index a4fc3d5c1..df4e1bf3a 100644 --- a/lib/ivis_opengl/piedraw.cpp +++ b/lib/ivis_opengl/piedraw.cpp @@ -129,13 +129,19 @@ static transluscent_shape_t* tshapes = NULL; static unsigned int tshapes_size = 0; static unsigned int nb_tshapes = 0; -static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT teamcolour, int pieFlag, int pieFlagData) +static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT teamcolour, int pieFlag, int pieFlagData, int shaderlessTeamColourHackAmount = 0) { + if (bShaderlessTeamcolourHack) + { + colour.byte.r = (colour.byte.r*(256 - shaderlessTeamColourHackAmount) + teamcolour.byte.r*shaderlessTeamColourHackAmount) / 256; // Ugly, but better than being colourblind. + colour.byte.g = (colour.byte.g*(256 - shaderlessTeamColourHackAmount) + teamcolour.byte.g*shaderlessTeamColourHackAmount) / 256; + colour.byte.b = (colour.byte.b*(256 - shaderlessTeamColourHackAmount) + teamcolour.byte.b*shaderlessTeamColourHackAmount) / 256; + } + iIMDPoly *pPolys; bool light = true; pie_SetAlphaTest(true); - /* Set fog status */ if (!(pieFlag & pie_FORCE_FOG) && (pieFlag & pie_ADDITIVE || pieFlag & pie_TRANSLUCENT || pieFlag & pie_BUTTON)) @@ -462,7 +468,7 @@ void pie_CleanUp( void ) scshapes = NULL; } -void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int pieFlag, int pieFlagData) +void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int pieFlag, int pieFlagData, int shaderlessTeamColourHackAmount) { PIELIGHT teamcolour; @@ -479,7 +485,7 @@ void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int if (drawing_interface || !shadows) { - pie_Draw3DShape2(shape, frame, colour, teamcolour, pieFlag, pieFlagData); + pie_Draw3DShape2(shape, frame, colour, teamcolour, pieFlag, pieFlagData, shaderlessTeamColourHackAmount); } else { @@ -559,7 +565,7 @@ void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int } } - pie_Draw3DShape2(shape, frame, colour, teamcolour, pieFlag, pieFlagData); + pie_Draw3DShape2(shape, frame, colour, teamcolour, pieFlag, pieFlagData, shaderlessTeamColourHackAmount); } } } diff --git a/lib/ivis_opengl/screen.cpp b/lib/ivis_opengl/screen.cpp index 6fe7dccd2..23cff3299 100644 --- a/lib/ivis_opengl/screen.cpp +++ b/lib/ivis_opengl/screen.cpp @@ -48,6 +48,8 @@ UDWORD screenWidth = 0; UDWORD screenHeight = 0; UDWORD screenDepth = 0; +bool bShaderlessTeamcolourHack = false; + /* global used to indicate preferred internal OpenGL format */ int wz_texture_compression; @@ -262,6 +264,7 @@ bool screenInitialise( { debug(LOG_POPUP, "OpenGL 2.0 is not supported by your system, current shaders require this."); debug(LOG_POPUP, "Team colors will not function correctly on your system."); + bShaderlessTeamcolourHack = true; } glViewport(0, 0, width, height); diff --git a/lib/ivis_opengl/screen.h b/lib/ivis_opengl/screen.h index 039860433..a01e079f3 100644 --- a/lib/ivis_opengl/screen.h +++ b/lib/ivis_opengl/screen.h @@ -35,6 +35,8 @@ #include "lib/framework/types.h" +extern bool bShaderlessTeamcolourHack; + /* ------------------------------------------------------------------------------------------- */ /* Legacy stuff diff --git a/src/component.cpp b/src/component.cpp index c95338acd..672f032f6 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -212,7 +212,7 @@ void displayStructureButton(STRUCTURE *psStructure, Vector3i *rotation, Vector3i if(baseImd!=NULL) { pie_Draw3DShape(baseImd, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, pie_BUTTON, 0); } - pie_Draw3DShape(psStructure->sDisplay.imd, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, pie_BUTTON, 0); + pie_Draw3DShape(psStructure->sDisplay.imd, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, pie_BUTTON, 0, 64); //and draw the turret if(psStructure->sDisplay.imd->nconnectors) { @@ -310,7 +310,7 @@ void displayStructureStatButton(STRUCTURE_STATS *Stats, Vector3i *Rotation, Vect { pie_Draw3DShape(baseImd, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, pie_BUTTON, 0); } - pie_Draw3DShape(Stats->pIMD, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, pie_BUTTON, 0); + pie_Draw3DShape(Stats->pIMD, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, pie_BUTTON, 0, 64); //and draw the turret if(Stats->pIMD->nconnectors) @@ -565,7 +565,7 @@ static void displayCompObj(DROID *psDroid, BOOL bButton) psShapeTemp = (leftFirst ? getLeftPropulsionIMD(psDroid) : getRightPropulsionIMD(psDroid)); if(psShapeTemp!=NULL) { - pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData); + pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData, 256); } /* set default components transparent */ @@ -601,7 +601,7 @@ static void displayCompObj(DROID *psDroid, BOOL bButton) /* draw body if cyborg not animating */ if ( psDroid->psCurAnim == NULL || psDroid->psCurAnim->bVisible == false ) { - pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData); + pie_Draw3DShape(psShapeTemp, 0, colour, brightness, pieFlag, iPieData, 256); } } else @@ -936,7 +936,7 @@ static void displayCompObj(DROID *psDroid, BOOL bButton) psShape = (leftFirst ? getRightPropulsionIMD(psDroid) : getLeftPropulsionIMD(psDroid)); if(psShape!=NULL) { - pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData); + pie_Draw3DShape(psShape, 0, colour, brightness, pieFlag, iPieData, 256); } } diff --git a/src/display3d.cpp b/src/display3d.cpp index 83174d3fd..50294470d 100644 --- a/src/display3d.cpp +++ b/src/display3d.cpp @@ -1374,7 +1374,7 @@ void renderAnimComponent( const COMPONENT_OBJECT *psObj ) pie_MatRotZ(-psObj->orientation.y); pie_MatRotX(-psObj->orientation.x); - pie_Draw3DShape(psObj->psShape, 0, iPlayer, brightness, pie_STATIC_SHADOW, 0); + pie_Draw3DShape(psObj->psShape, 0, iPlayer, brightness, pie_STATIC_SHADOW, 0, 256); /* clear stack */ pie_MatEnd(); @@ -2172,7 +2172,7 @@ void renderStructure(STRUCTURE *psStructure) pieFlag = pie_TRANSLUCENT | pie_FORCE_FOG; pieFlagData = 255; } - pie_Draw3DShape(psStructure->pStructureType->pBaseIMD, 0, colour, buildingBrightness, pieFlag, pieFlagData); + pie_Draw3DShape(psStructure->pStructureType->pBaseIMD, 0, colour, buildingBrightness, pieFlag, pieFlagData, 64); } // override @@ -2190,7 +2190,7 @@ void renderStructure(STRUCTURE *psStructure) //first check if partially built - ANOTHER HACK! if (psStructure->status == SS_BEING_BUILT || psStructure->status == SS_BEING_DEMOLISHED) { - pie_Draw3DShape(strImd, 0, colour, buildingBrightness, pie_HEIGHT_SCALED | pie_SHADOW, structHeightScale(psStructure) * pie_RAISE_SCALE); + pie_Draw3DShape(strImd, 0, colour, buildingBrightness, pie_HEIGHT_SCALED | pie_SHADOW, structHeightScale(psStructure) * pie_RAISE_SCALE, 64); } else { @@ -2208,7 +2208,7 @@ void renderStructure(STRUCTURE *psStructure) { pie_SetShaderStretchDepth(psStructure->pos.z - psStructure->foundationDepth); } - pie_Draw3DShape(strImd, animFrame, colour, buildingBrightness, pieFlag, pieFlagData); + pie_Draw3DShape(strImd, animFrame, colour, buildingBrightness, pieFlag, pieFlagData, 64); pie_SetShaderStretchDepth(0); // It might have weapons on it @@ -2616,7 +2616,7 @@ static BOOL renderWallSection(STRUCTURE *psStructure) (psStructure->status == SS_BEING_BUILT && psStructure->pStructureType->type == REF_RESOURCE_EXTRACTOR) ) { pie_Draw3DShape(psStructure->sDisplay.imd, 0, getPlayerColour(psStructure->player), - brightness, pie_HEIGHT_SCALED|pie_SHADOW, structHeightScale(psStructure) * pie_RAISE_SCALE); + brightness, pie_HEIGHT_SCALED|pie_SHADOW, structHeightScale(psStructure) * pie_RAISE_SCALE, 64); } else { @@ -2638,7 +2638,7 @@ static BOOL renderWallSection(STRUCTURE *psStructure) } pieFlagData = 0; } - pie_Draw3DShape(imd, 0, getPlayerColour(psStructure->player), brightness, pieFlag, pieFlagData); + pie_Draw3DShape(imd, 0, getPlayerColour(psStructure->player), brightness, pieFlag, pieFlagData, 64); } imd->points = temp;