From 296300a9e1819c020b0e6c4332597e4965c33f60 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 25 Mar 2012 00:47:53 +0000 Subject: [PATCH] Updated color functions for selected and focused objects. --- common/camera.cpp | 19 +++++-- common/curve.cpp | 17 +++--- common/defines.h | 2 - common/lc_colors.cpp | 51 +++++++++-------- common/lc_colors.h | 28 +++++++++- common/light.cpp | 24 +++++--- common/opengl.h | 1 - common/piece.cpp | 129 ++++++++++++++++++------------------------- common/piece.h | 2 +- common/project.cpp | 25 ++++----- 10 files changed, 156 insertions(+), 142 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index b2b6a4aa..c2b3665a 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -1,6 +1,7 @@ // Camera object. #include "lc_global.h" +#include "lc_colors.h" #include #include #include @@ -610,37 +611,43 @@ void Camera::Render(float fLineWidth) // Create the display lists if this is the first time we're rendered. if (!m_nList) { - m_nList = glGenLists(1); + m_nList = glGenLists(1); UpdateBoundingBox(); } if (IsEyeSelected()) { glLineWidth(fLineWidth*2); - glColor3ubv(FlatColorArray[(m_nState & LC_CAMERA_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]); + if (m_nState & LC_CAMERA_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); glCallList(m_nList); glLineWidth(fLineWidth); } else { - glColor3f(0.5f, 0.8f, 0.5f); + lcSetColorCamera(); glCallList(m_nList); } if (IsTargetSelected()) { glLineWidth(fLineWidth*2); - glColor3ubv(FlatColorArray[(m_nState & LC_CAMERA_TARGET_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]); + if (m_nState & LC_CAMERA_TARGET_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); glCallList(m_nTargetList); glLineWidth(fLineWidth); } else { - glColor3f(0.5f, 0.8f, 0.5f); + lcSetColorCamera(); glCallList(m_nTargetList); } - glColor3f(0.5f, 0.8f, 0.5f); + lcSetColorCamera(); glBegin(GL_LINES); glVertex3fv(m_fEye); glVertex3fv(m_fTarget); diff --git a/common/curve.cpp b/common/curve.cpp index 5eaa0a39..068bbcbe 100755 --- a/common/curve.cpp +++ b/common/curve.cpp @@ -2,6 +2,7 @@ // #include "lc_global.h" +#include "lc_colors.h" #include #include #include "globals.h" @@ -215,13 +216,11 @@ void CurvePoint::Select (bool bSelecting, bool bFocus, bool bMultiple) void CurvePoint::Render (LC_RENDER_INFO* pInfo) { if (m_nState & LC_CURVE_POINT_FOCUSED) - glColor3ubv (FlatColorArray[LC_COL_FOCUSED]); + lcSetColorFocused(); else if (m_nState & LC_CURVE_POINT_SELECTED) - glColor3ubv (FlatColorArray[LC_COL_SELECTED]); + lcSetColorSelected(); else - glColor3f(0.5f, 0.8f, 0.5f); // FIXME: same as camera color, add to FlatColorArray - // glColor3ub (0, 0, 0); // FIXME: inverse of background - // FIXME: add a new color to the array and change the names from LC_COL to LC_COLOR ? + lcSetColorCamera(); // FIXME: same as camera color glPushMatrix (); glTranslatef (m_fPos[0], m_fPos[1], m_fPos[2]); @@ -661,13 +660,11 @@ void Curve::Render (LC_RENDER_INFO* pInfo) for (int i = 0; i < m_nNumPoints; i++) { if (m_pPoints[i].m_nFlags & LC_CURVE_POINT_FOCUSED) - glColor3ubv (FlatColorArray[LC_COL_FOCUSED]); + lcSetColorFocused(); else if (m_pPoints[i].m_nFlags & LC_CURVE_POINT_SELECTED) - glColor3ubv (FlatColorArray[LC_COL_SELECTED]); + lcSetColorSelected(); else - glColor3f(0.5f, 0.8f, 0.5f); // FIXME: same as camera color, add to FlatColorArray - // glColor3ub (0, 0, 0); // FIXME: inverse of background - // FIXME: add a new color to the array and change the names from LC_COL to LC_COLOR ? + lcSetColorCamera(); // FIXME: same as camera color glPushMatrix (); // RenderSegment (m_pPoints[i].m_fPos, m_pPoints[i+1].m_fPos, m_pSegments[i].m_fR1, m_pSegments[i].m_fR2); diff --git a/common/defines.h b/common/defines.h index 27989c7b..2dce7a4c 100644 --- a/common/defines.h +++ b/common/defines.h @@ -130,8 +130,6 @@ int stricmp(const char* str1, const char* str2); #define LC_MAXCOLORS 28 // Number of colors supported #define LC_COL_EDGES 28 // Piece edges -#define LC_COL_SELECTED 29 // Selected object -#define LC_COL_FOCUSED 30 // Focused object #define LC_COL_DEFAULT 31 // Default piece color diff --git a/common/lc_colors.cpp b/common/lc_colors.cpp index f5b48945..d3c9a05f 100644 --- a/common/lc_colors.cpp +++ b/common/lc_colors.cpp @@ -6,7 +6,6 @@ //#include "system.h" lcColor* gColorList; -//int gNumUserColors; int gNumColors; static const char sDefaultColors[] = @@ -14,12 +13,12 @@ static const char sDefaultColors[] = "0 LDraw.org Configuration File\n" "0 Name: LDConfig.ldr\n" "0 Author: LDraw.org\n" - "0 !LDRAW_ORG Configuration UPDATE 2011-06-03\n" + "0 !LDRAW_ORG Configuration UPDATE 2012-01-06\n" "\n" "0 // LDraw Solid Colours\n" "0 !COLOUR Black CODE 0 VALUE #05131D EDGE #595959\n" "0 !COLOUR Blue CODE 1 VALUE #0055BF EDGE #333333\n" - "0 !COLOUR Green CODE 2 VALUE #237841 EDGE #333333\n" + "0 !COLOUR Green CODE 2 VALUE #257A3E EDGE #333333\n" "0 !COLOUR Dark_Turquoise CODE 3 VALUE #008F9B EDGE #333333\n" "0 !COLOUR Red CODE 4 VALUE #C91A09 EDGE #333333\n" "0 !COLOUR Dark_Pink CODE 5 VALUE #C870A0 EDGE #333333\n" @@ -41,12 +40,14 @@ static const char sDefaultColors[] = "0 !COLOUR Dark_Blue_Violet CODE 23 VALUE #2032B0 EDGE #1E1E1E\n" "0 !COLOUR Orange CODE 25 VALUE #FE8A18 EDGE #333333\n" "0 !COLOUR Magenta CODE 26 VALUE #923978 EDGE #333333\n" - "0 !COLOUR Lime CODE 27 VALUE #BBE90B EDGE #333333\n" + "0 !COLOUR Lime CODE 27 VALUE #A5D426 EDGE #333333\n" "0 !COLOUR Dark_Tan CODE 28 VALUE #958A73 EDGE #333333\n" "0 !COLOUR Bright_Pink CODE 29 VALUE #E4ADC8 EDGE #333333\n" + "0 !COLOUR Medium_Lavender CODE 30 VALUE #AC78BA EDGE #333333\n" + "0 !COLOUR Lavender CODE 31 VALUE #E1D5ED EDGE #333333\n" "0 !COLOUR Very_Light_Orange CODE 68 VALUE #F3CF9B EDGE #333333\n" "0 !COLOUR Light_Purple CODE 69 VALUE #CD6298 EDGE #333333\n" - "0 !COLOUR Reddish_Brown CODE 70 VALUE #582A12 EDGE #333333\n" + "0 !COLOUR Reddish_Brown CODE 70 VALUE #582A12 EDGE #595959\n" "0 !COLOUR Light_Bluish_Gray CODE 71 VALUE #A0A5A9 EDGE #333333\n" "0 !COLOUR Dark_Bluish_Gray CODE 72 VALUE #6C6E68 EDGE #333333\n" "0 !COLOUR Medium_Blue CODE 73 VALUE #5A93DB EDGE #333333\n" @@ -68,16 +69,18 @@ static const char sDefaultColors[] = "0 !COLOUR Very_Light_Bluish_Gray CODE 151 VALUE #E6E3E0 EDGE #333333\n" "0 !COLOUR Bright_Light_Orange CODE 191 VALUE #F8BB3D EDGE #333333\n" "0 !COLOUR Bright_Light_Blue CODE 212 VALUE #9FC3E9 EDGE #333333\n" - "0 !COLOUR Rust CODE 216 VALUE #B31004 EDGE #333333\n" + "0 !COLOUR Rust CODE 216 VALUE #A52D0A EDGE #333333\n" "0 !COLOUR Bright_Light_Yellow CODE 226 VALUE #FFF03A EDGE #333333\n" "0 !COLOUR Sky_Blue CODE 232 VALUE #7DBFDD EDGE #333333\n" "0 !COLOUR Dark_Blue CODE 272 VALUE #0A3463 EDGE #1E1E1E\n" - "0 !COLOUR Dark_Green CODE 288 VALUE #184632 EDGE #333333\n" - "0 !COLOUR Dark_Brown CODE 308 VALUE #352100 EDGE #000000\n" + "0 !COLOUR Dark_Green CODE 288 VALUE #184632 EDGE #595959\n" + "0 !COLOUR Dark_Brown CODE 308 VALUE #352100 EDGE #595959\n" "0 !COLOUR Maersk_Blue CODE 313 VALUE #3592C3 EDGE #333333\n" "0 !COLOUR Dark_Red CODE 320 VALUE #720E0F EDGE #333333\n" - "0 !COLOUR Dark_Azure CODE 321 VALUE #078BC9 EDGE #088DCD\n" - "0 !COLOUR Light_Aqua CODE 323 VALUE #ADC3C0 EDGE #AFC9C2\n" + "0 !COLOUR Dark_Azure CODE 321 VALUE #078BC9 EDGE #333333\n" + "0 !COLOUR Medium_Azure CODE 322 VALUE #36AEBF EDGE #333333\n" + "0 !COLOUR Light_Aqua CODE 323 VALUE #ADC3C0 EDGE #333333\n" + "0 !COLOUR Olive_Green CODE 326 VALUE #9B9A5A EDGE #333333\n" "0 !COLOUR Sand_Red CODE 335 VALUE #D67572 EDGE #333333\n" "0 !COLOUR Medium_Dark_Pink CODE 351 VALUE #F785B1 EDGE #333333\n" "0 !COLOUR Earth_Orange CODE 366 VALUE #FA9C1C EDGE #333333\n" @@ -98,8 +101,8 @@ static const char sDefaultColors[] = "0 !COLOUR Trans_Neon_Yellow CODE 54 VALUE #DAB000 EDGE #C3BA3F ALPHA 128\n" "0 !COLOUR Trans_Yellow CODE 46 VALUE #F5CD2F EDGE #8E7400 ALPHA 128\n" "0 !COLOUR Trans_Neon_Green CODE 42 VALUE #C0FF00 EDGE #84C300 ALPHA 128\n" - "0 !COLOUR Trans_Bright_Green CODE 35 VALUE #D9E4A7 EDGE #9DA86B ALPHA 128\n" - "0 !COLOUR Trans_Green CODE 34 VALUE #84B68D EDGE #002800 ALPHA 128\n" + "0 !COLOUR Trans_Bright_Green CODE 35 VALUE #56E646 EDGE #9DA86B ALPHA 128\n" + "0 !COLOUR Trans_Green CODE 34 VALUE #237841 EDGE #1E6239 ALPHA 128\n" "0 !COLOUR Trans_Dark_Blue CODE 33 VALUE #0020A0 EDGE #000064 ALPHA 128\n" "0 !COLOUR Trans_Medium_Blue CODE 41 VALUE #559AB7 EDGE #196973 ALPHA 128\n" "0 !COLOUR Trans_Light_Blue CODE 43 VALUE #AEE9EF EDGE #72B3B0 ALPHA 128\n" @@ -113,7 +116,7 @@ static const char sDefaultColors[] = "0 !COLOUR Chrome_Gold CODE 334 VALUE #BBA53D EDGE #BBB23D CHROME\n" "0 !COLOUR Chrome_Silver CODE 383 VALUE #E0E0E0 EDGE #A4A4A4 CHROME\n" "0 !COLOUR Chrome_Antique_Brass CODE 60 VALUE #645A4C EDGE #281E10 CHROME\n" - "0 !COLOUR Chrome_Black CODE 64 VALUE #1B2A34 EDGE #000000 CHROME\n" + "0 !COLOUR Chrome_Black CODE 64 VALUE #1B2A34 EDGE #595959 CHROME\n" "0 !COLOUR Chrome_Blue CODE 61 VALUE #6C96BF EDGE #202A68 CHROME\n" "0 !COLOUR Chrome_Green CODE 62 VALUE #3CB371 EDGE #007735 CHROME\n" "0 !COLOUR Chrome_Pink CODE 63 VALUE #AA4D8E EDGE #6E1152 CHROME\n" @@ -134,8 +137,8 @@ static const char sDefaultColors[] = "0 !COLOUR Metallic_Silver CODE 80 VALUE #A5A9B4 EDGE #333333 METAL\n" "0 !COLOUR Metallic_Green CODE 81 VALUE #899B5F EDGE #333333 METAL\n" "0 !COLOUR Metallic_Gold CODE 82 VALUE #DBAC34 EDGE #333333 METAL\n" - "0 !COLOUR Metallic_Black CODE 83 VALUE #1A2831 EDGE #000000 METAL\n" - "0 !COLOUR Metallic_Dark_Gray CODE 87 VALUE #6D6E5C EDGE #5D5B53 METAL\n" + "0 !COLOUR Metallic_Black CODE 83 VALUE #1A2831 EDGE #333333 METAL\n" + "0 !COLOUR Metallic_Dark_Gray CODE 87 VALUE #6D6E5C EDGE #333333 METAL\n" "\n" "0 // LDraw Milky Colours\n" "0 !COLOUR Milky_White CODE 79 VALUE #FFFFFF EDGE #C3C3C3 ALPHA 224\n" @@ -144,24 +147,24 @@ static const char sDefaultColors[] = "\n" "0 // LDraw Glitter Colours\n" "0 !COLOUR Glitter_Trans_Dark_Pink CODE 114 VALUE #DF6695 EDGE #9A2A66 ALPHA 128 MATERIAL GLITTER VALUE #923978 FRACTION 0.17 VFRACTION 0.2 SIZE 1\n" - "0 !COLOUR Glitter_Trans_Clear CODE 117 VALUE #FFFFFF EDGE #C3C3C3 ALPHA 128 MATERIAL GLITTER VALUE #FFFFFF FRACTION 0.08 VFRACTION 0.1 SIZE 1\n" + "0 !COLOUR Glitter_Trans_Clear CODE 117 VALUE #FCFCFC EDGE #C3C3C3 ALPHA 128 MATERIAL GLITTER VALUE #FFFFFF FRACTION 0.08 VFRACTION 0.1 SIZE 1\n" "0 !COLOUR Glitter_Trans_Purple CODE 129 VALUE #640061 EDGE #280025 ALPHA 128 MATERIAL GLITTER VALUE #8C00FF FRACTION 0.3 VFRACTION 0.4 SIZE 1\n" "\n" "0 // LDraw Speckle Colours\n" - "0 !COLOUR Speckle_Black_Silver CODE 132 VALUE #000000 EDGE #595959 MATERIAL SPECKLE VALUE #595959 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" - "0 !COLOUR Speckle_Black_Gold CODE 133 VALUE #000000 EDGE #DBAC34 MATERIAL SPECKLE VALUE #AE7A59 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" - "0 !COLOUR Speckle_Black_Copper CODE 75 VALUE #000000 EDGE #595959 MATERIAL SPECKLE VALUE #AE7A59 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" - "0 !COLOUR Speckle_Dark_Bluish_Gray_Silver CODE 76 VALUE #635F61 EDGE #595959 MATERIAL SPECKLE VALUE #595959 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" + "0 !COLOUR Speckle_Black_Silver CODE 132 VALUE #000000 EDGE #898788 MATERIAL SPECKLE VALUE #898788 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" + "0 !COLOUR Speckle_Black_Gold CODE 133 VALUE #000000 EDGE #DBAC34 MATERIAL SPECKLE VALUE #DBAC34 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" + "0 !COLOUR Speckle_Black_Copper CODE 75 VALUE #000000 EDGE #AB6038 MATERIAL SPECKLE VALUE #AB6038 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" + "0 !COLOUR Speckle_Dark_Bluish_Gray_Silver CODE 76 VALUE #635F61 EDGE #898788 MATERIAL SPECKLE VALUE #898788 FRACTION 0.4 MINSIZE 1 MAXSIZE 3\n" "\n" "0 // LDraw Rubber Colours\n" - "0 !COLOUR Rubber_Yellow CODE 65 VALUE #F5CD2F EDGE #333333 RUBBER\n" + "0 !COLOUR Rubber_Yellow CODE 65 VALUE #ECC935 EDGE #333333 RUBBER\n" "0 !COLOUR Rubber_Trans_Yellow CODE 66 VALUE #CAB000 EDGE #8E7400 ALPHA 128 RUBBER\n" "0 !COLOUR Rubber_Trans_Clear CODE 67 VALUE #FFFFFF EDGE #C3C3C3 ALPHA 128 RUBBER\n" "0 !COLOUR Rubber_Black CODE 256 VALUE #212121 EDGE #595959 RUBBER\n" "0 !COLOUR Rubber_Blue CODE 273 VALUE #0033B2 EDGE #333333 RUBBER\n" "0 !COLOUR Rubber_Red CODE 324 VALUE #C40026 EDGE #333333 RUBBER\n" "0 !COLOUR Rubber_Light_Gray CODE 375 VALUE #C1C2C1 EDGE #333333 RUBBER\n" - "0 !COLOUR Rubber_Dark_Blue CODE 406 VALUE #001D68 EDGE #333333 RUBBER\n" + "0 !COLOUR Rubber_Dark_Blue CODE 406 VALUE #001D68 EDGE #595959 RUBBER\n" "0 !COLOUR Rubber_Purple CODE 449 VALUE #81007B EDGE #333333 RUBBER\n" "0 !COLOUR Rubber_Lime CODE 490 VALUE #D7F000 EDGE #333333 RUBBER\n" "0 !COLOUR Rubber_Light_Bluish_Gray CODE 496 VALUE #A3A2A4 EDGE #333333 RUBBER\n" @@ -171,9 +174,11 @@ static const char sDefaultColors[] = "0 // LDraw Internal Common Material Colours\n" "0 !COLOUR Main_Colour CODE 16 VALUE #7F7F7F EDGE #333333\n" "0 !COLOUR Edge_Colour CODE 24 VALUE #7F7F7F EDGE #333333\n" - "0 !COLOUR Trans_Black_IR_Lens CODE 32 VALUE #000000 EDGE #05131D ALPHA 220\n" + "0 !COLOUR Trans_Black_IR_Lens CODE 32 VALUE #000000 EDGE #333333 ALPHA 200\n" + "0 !COLOUR Magnet CODE 493 VALUE #656761 EDGE #595959 METAL\n" "0 !COLOUR Electric_Contact_Alloy CODE 494 VALUE #D0D0D0 EDGE #6E6E6E METAL\n" "0 !COLOUR Electric_Contact_Copper CODE 495 VALUE #AE7A59 EDGE #723E1D METAL\n" + "0\n" }; static void GetToken(char*& Ptr, char* Token) diff --git a/common/lc_colors.h b/common/lc_colors.h index d03548ea..78ff2e99 100644 --- a/common/lc_colors.h +++ b/common/lc_colors.h @@ -15,6 +15,32 @@ struct lcColor extern lcColor* gColorList; extern int gNumColors; +inline void lcSetColor(int ColorIndex) +{ + float* Color = gColorList[ColorIndex].Value; + glColor4f(Color[0], Color[1], Color[2], Color[3]); +} + +inline void lcSetColorFocused() +{ + glColor4f(0.4000f, 0.2980f, 0.8980f, 1.0000f); +} + +inline void lcSetColorSelected() +{ + glColor4f(0.8980f, 0.2980f, 0.4000f, 1.0000f); +} + +inline void lcSetColorCamera() +{ + glColor4f(0.5f, 0.8f, 0.5f, 1.0f); +} + +inline void lcSetColorLight() +{ + glColor4f(0.5f, 0.8f, 0.5f, 1.0f); +} + /* void lcColorInit(const char* FileName); void lcColorShutdown(); @@ -24,8 +50,6 @@ void lcColorShutdown(); //#define LC_MAXCOLORS 28 // Number of colors supported //#define LC_COL_EDGES 28 // Piece edges -//#define LC_COL_SELECTED 29 // Selected object -//#define LC_COL_FOCUSED 30 // Focused object //#define LC_COL_DEFAULT 31 // Default piece color */ diff --git a/common/light.cpp b/common/light.cpp index 7d276447..eca0337f 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -1,6 +1,7 @@ // Light object. #include "lc_global.h" +#include "lc_colors.h" #include #include #include @@ -432,30 +433,36 @@ void Light::Render (float fLineWidth) if (IsEyeSelected()) { glLineWidth(fLineWidth*2); - glColor3ubv(FlatColorArray[(m_nState & LC_LIGHT_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]); + if (m_nState & LC_LIGHT_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); glCallList(m_nList); glLineWidth(fLineWidth); } else { - glColor3f(0.5f, 0.8f, 0.5f); + lcSetColorLight(); glCallList(m_nList); } if (IsTargetSelected()) { glLineWidth(fLineWidth*2); - glColor3ubv(FlatColorArray[(m_nState & LC_LIGHT_TARGET_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]); + if (m_nState & LC_LIGHT_TARGET_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); glCallList(m_nTargetList); glLineWidth(fLineWidth); } else { - glColor3f(0.5f, 0.8f, 0.5f); + lcSetColorLight(); glCallList(m_nTargetList); } - glColor3f(0.5f, 0.8f, 0.5f); + lcSetColorLight(); glBegin(GL_LINES); glVertex3fv(m_fPos); glVertex3fv(m_fTarget); @@ -526,13 +533,16 @@ void Light::Render (float fLineWidth) if (IsEyeSelected ()) { glLineWidth (fLineWidth*2); - glColor3ubv (FlatColorArray[(m_nState & LC_LIGHT_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]); + if (m_nState & LC_LIGHT_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); glCallList (m_nSphereList); glLineWidth (fLineWidth); } else { - glColor3f (0.5f, 0.8f, 0.5f); + lcSetColorLight(); glCallList (m_nSphereList); } diff --git a/common/opengl.h b/common/opengl.h index 8556daeb..32067aa5 100755 --- a/common/opengl.h +++ b/common/opengl.h @@ -2,7 +2,6 @@ #define _OPENGL_H_ #ifdef LC_WINDOWS -#include "stdafx.h" #include #include "win_gl.h" #else diff --git a/common/piece.cpp b/common/piece.cpp index 809ed9c1..f3ab6a67 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -2,6 +2,7 @@ // #include "lc_global.h" +#include "lc_colors.h" #include #include #include @@ -27,7 +28,7 @@ static LC_OBJECT_KEY_INFO piece_key_info[LC_PK_COUNT] = ///////////////////////////////////////////////////////////////////////////// // Static functions -inline static void SetCurrentColor(unsigned char nColor, bool* bTrans, bool bLighting) +inline static void SetCurrentColor(unsigned char nColor, bool bLighting) { bool Transparent = (nColor > 13 && nColor < 22); @@ -41,22 +42,14 @@ inline static void SetCurrentColor(unsigned char nColor, bool* bTrans, bool bLig if (Transparent) { - if (!*bTrans) - { - *bTrans = true; - glEnable(GL_BLEND); - glDepthMask(GL_FALSE); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } + glEnable(GL_BLEND); + glDepthMask(GL_FALSE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else { - if (*bTrans) - { - *bTrans = false; - glDepthMask(GL_TRUE); - glDisable(GL_BLEND); - } + glDepthMask(GL_TRUE); + glDisable(GL_BLEND); } } @@ -1147,7 +1140,10 @@ void Piece::RenderBox(bool bHilite, float fLineWidth) if (bHilite && ((m_nState & LC_PIECE_SELECTED) != 0)) { - glColor3ubv(FlatColorArray[m_nState & LC_PIECE_FOCUSED ? LC_COL_FOCUSED : LC_COL_SELECTED]); + if (m_nState & LC_PIECE_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); glLineWidth(2*fLineWidth); glPushAttrib(GL_POLYGON_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -1163,7 +1159,7 @@ void Piece::RenderBox(bool bHilite, float fLineWidth) glPopMatrix(); } -void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* bTrans) +void Piece::Render(bool bLighting, bool bEdges) { glPushMatrix(); glTranslatef(m_fPosition[0], m_fPosition[1], m_fPosition[2]); @@ -1176,10 +1172,7 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* m_pPieceInfo->m_pTextures[sh].texture->MakeCurrent(); if (m_pPieceInfo->m_pTextures[sh].color == LC_COL_DEFAULT) - { - SetCurrentColor(m_nColor, bTrans, bLighting); - *nLastColor = m_nColor; - } + SetCurrentColor(m_nColor, bLighting); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); @@ -1205,19 +1198,10 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* { bool lock = lockarrays && (*info == LC_COL_DEFAULT || *info == LC_COL_EDGES); - if (*info != *nLastColor) - { - if (*info == LC_COL_DEFAULT) - { - SetCurrentColor(m_nColor, bTrans, bLighting); - *nLastColor = m_nColor; - } - else - { - SetCurrentColor((unsigned char)*info, bTrans, bLighting); - *nLastColor = (unsigned char)*info; - } - } + if (*info == LC_COL_DEFAULT) + SetCurrentColor(m_nColor, bLighting); + else + SetCurrentColor((unsigned char)*info, bLighting); info++; if (lock) @@ -1241,24 +1225,26 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* if (*info) { - if (m_nState & LC_PIECE_SELECTED) - { - if (lock) - glUnlockArraysEXT(); + if (m_nState & LC_PIECE_SELECTED) + { + if (lock) + glUnlockArraysEXT(); - SetCurrentColor(m_nState & LC_PIECE_FOCUSED ? LC_COL_FOCUSED : LC_COL_SELECTED, bTrans, bLighting); - *nLastColor = m_nState & LC_PIECE_FOCUSED ? LC_COL_FOCUSED : LC_COL_SELECTED; + if (m_nState & LC_PIECE_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); - if (lock) - glLockArraysEXT(0, m_pPieceInfo->m_nVertexCount); + if (lock) + glLockArraysEXT(0, m_pPieceInfo->m_nVertexCount); - glDrawElements(GL_LINES, *info, GL_UNSIGNED_INT, info+1); - } - else - if (bEdges) - glDrawElements(GL_LINES, *info, GL_UNSIGNED_INT, info+1); + glDrawElements(GL_LINES, *info, GL_UNSIGNED_INT, info+1); + } + else + if (bEdges) + glDrawElements(GL_LINES, *info, GL_UNSIGNED_INT, info+1); - info += *info + 1; + info += *info + 1; } else info++; @@ -1277,19 +1263,10 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* { bool lock = lockarrays && (*info == LC_COL_DEFAULT || *info == LC_COL_EDGES); - if (*info != *nLastColor) - { - if (*info == LC_COL_DEFAULT) - { - SetCurrentColor(m_nColor, bTrans, bLighting); - *nLastColor = m_nColor; - } - else - { - SetCurrentColor((unsigned char)*info, bTrans, bLighting); - *nLastColor = (unsigned char)*info; - } - } + if (*info == LC_COL_DEFAULT) + SetCurrentColor(m_nColor, bLighting); + else + SetCurrentColor((unsigned char)*info, bLighting); info++; if (lock) @@ -1313,23 +1290,25 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* if (*info) { - if (m_nState & LC_PIECE_SELECTED) - { - if (lock) - glUnlockArraysEXT(); - SetCurrentColor((m_nState & LC_PIECE_FOCUSED) ? LC_COL_FOCUSED : LC_COL_SELECTED, bTrans, bLighting); - *nLastColor = m_nState & LC_PIECE_FOCUSED ? LC_COL_FOCUSED : LC_COL_SELECTED; - - if (lock) - glLockArraysEXT(0, m_pPieceInfo->m_nVertexCount); + if (m_nState & LC_PIECE_SELECTED) + { + if (lock) + glUnlockArraysEXT(); + if (m_nState & LC_PIECE_FOCUSED) + lcSetColorFocused(); + else + lcSetColorSelected(); - glDrawElements(GL_LINES, *info, GL_UNSIGNED_SHORT, info+1); - } - else - if (bEdges) - glDrawElements(GL_LINES, *info, GL_UNSIGNED_SHORT, info+1); + if (lock) + glLockArraysEXT(0, m_pPieceInfo->m_nVertexCount); - info += *info + 1; + glDrawElements(GL_LINES, *info, GL_UNSIGNED_SHORT, info+1); + } + else + if (bEdges) + glDrawElements(GL_LINES, *info, GL_UNSIGNED_SHORT, info+1); + + info += *info + 1; } else info++; diff --git a/common/piece.h b/common/piece.h index b899d90c..363e1641 100644 --- a/common/piece.h +++ b/common/piece.h @@ -109,7 +109,7 @@ public: void GetRotation (float* rotation) { memcpy(rotation, m_fRotation, sizeof(m_fRotation)); } - void Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool* bTrans); + void Render(bool bLighting, bool bEdges); void RenderBox(bool bHilite, float fLineWidth); inline bool IsTransparent() diff --git a/common/project.cpp b/common/project.cpp index 80aef51a..88b8a4c7 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1750,7 +1750,7 @@ typedef struct LC_BSPNODE } } LC_BSPNODE; -static void RenderBSP(LC_BSPNODE* node, float* eye, bool* bSel, bool bLighting, bool bEdges, unsigned char* nLastColor, bool* bTrans) +static void RenderBSP(LC_BSPNODE* node, float* eye, bool* bSel, bool bLighting, bool bEdges) { if (node->piece) { @@ -1771,20 +1771,20 @@ static void RenderBSP(LC_BSPNODE* node, float* eye, bool* bSel, bool bLighting, } } - node->piece->Render(bLighting, bEdges, nLastColor, bTrans); + node->piece->Render(bLighting, bEdges); return; } if (eye[0]*node->plane[0] + eye[1]*node->plane[1] + eye[2]*node->plane[2] + node->plane[3] > 0.0f) { - RenderBSP(node->back, eye, bSel, bLighting, bEdges, nLastColor, bTrans); - RenderBSP(node->front, eye, bSel, bLighting, bEdges, nLastColor, bTrans); + RenderBSP(node->back, eye, bSel, bLighting, bEdges); + RenderBSP(node->front, eye, bSel, bLighting, bEdges); } else { - RenderBSP(node->front, eye, bSel, bLighting, bEdges, nLastColor, bTrans); - RenderBSP(node->back, eye, bSel, bLighting, bEdges, nLastColor, bTrans); + RenderBSP(node->front, eye, bSel, bLighting, bEdges); + RenderBSP(node->back, eye, bSel, bLighting, bEdges); } } @@ -1921,8 +1921,6 @@ void Project::RenderScenePieces(View* view) if (m_nScene & LC_SCENE_FLOOR) m_pTerrain->Render(view->m_Camera, AspectRatio); - unsigned char nLastColor = 255; - bool bTrans = false; bool bSel = false; bool bCull = false; Piece* pPiece; @@ -1956,7 +1954,7 @@ void Project::RenderScenePieces(View* view) } } - pPiece->Render((m_nDetail & LC_DET_LIGHTING) != 0, (m_nDetail & LC_DET_BRICKEDGES) != 0, &nLastColor, &bTrans); + pPiece->Render((m_nDetail & LC_DET_LIGHTING) != 0, (m_nDetail & LC_DET_BRICKEDGES) != 0); } else { @@ -1970,14 +1968,11 @@ void Project::RenderScenePieces(View* view) float eye[3]; view->m_Camera->GetEyePos (eye); BuildBSP(&tree, pList); - RenderBSP(&tree, eye, &bSel, (m_nDetail & LC_DET_LIGHTING) != 0, (m_nDetail & LC_DET_BRICKEDGES) != 0, &nLastColor, &bTrans); + RenderBSP(&tree, eye, &bSel, (m_nDetail & LC_DET_LIGHTING) != 0, (m_nDetail & LC_DET_BRICKEDGES) != 0); } - if (bTrans) - { - glDepthMask(GL_TRUE); - glDisable(GL_BLEND); - } + glDepthMask(GL_TRUE); + glDisable(GL_BLEND); if (bSel) glLineWidth(m_fLineWidth);