From 5befa0b1ab212d2ab5f35f4a1e185e7dcca2abdb Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Tue, 24 Oct 2006 14:20:41 +0000
Subject: [PATCH] From Timur, Extend the TVirtualGL interface to support 16 &
 32 bit display mode. This is required for the new slicing algorithm (eg to
 run the tutorial glbox.C under Windows in 16 bits display mode)

git-svn-id: http://root.cern.ch/svn/root/trunk@16607 27541ba8-7e3a-0410-8455-c3a389f83636
---
 base/inc/TVirtualGL.h                  |  4 +-
 gl/inc/TGLPlotBox.h                    |  3 +-
 gl/inc/TGLPlotPainter.h                |  3 +-
 gl/inc/TGLUtil.h                       |  6 +-
 gl/inc/TX11GL.h                        |  4 +-
 gl/src/TGLBoxPainter.cxx               | 18 +++---
 gl/src/TGLLegoPainter.cxx              | 57 ++++++++++-------
 gl/src/TGLPlotBox.cxx                  |  9 +--
 gl/src/TGLPlotPainter.cxx              | 15 +++--
 gl/src/TGLSurfacePainter.cxx           | 18 ++++--
 gl/src/TGLTF3Painter.cxx               |  4 +-
 gl/src/TGLUtil.cxx                     | 85 ++++++++++++++++++++++++--
 win32gdk/inc/TGWin32GL.h               |  4 +-
 win32gdk/inc/TGWin32VirtualGLProxy.h   |  3 +-
 win32gdk/src/TGWin32GL.cxx             | 20 +++++-
 win32gdk/src/TGWin32VirtualGLProxy.cxx |  3 +-
 16 files changed, 191 insertions(+), 65 deletions(-)

diff --git a/base/inc/TVirtualGL.h b/base/inc/TVirtualGL.h
index d1adbb36259..70e4589039b 100644
--- a/base/inc/TVirtualGL.h
+++ b/base/inc/TVirtualGL.h
@@ -1,4 +1,4 @@
-// @(#)root/base:$Name:  $:$Id: TVirtualGL.h,v 1.32 2006/06/06 11:49:01 couet Exp $
+// @(#)root/base:$Name:  $:$Id: TVirtualGL.h,v 1.33 2006/08/31 13:42:14 couet Exp $
 // Author: Valery Fine(fine@vxcern.cern.ch)   05/03/97
 
 /*************************************************************************
@@ -254,6 +254,8 @@ public:
    virtual Bool_t   PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py) = 0;
    virtual char    *GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py) = 0;
 
+   virtual Bool_t   HighColorFormat(Int_t ctxInd) = 0;
+
    static TGLManager *&Instance();
 
 private:
diff --git a/gl/inc/TGLPlotBox.h b/gl/inc/TGLPlotBox.h
index 1018618cb99..79ca669d7d9 100644
--- a/gl/inc/TGLPlotBox.h
+++ b/gl/inc/TGLPlotBox.h
@@ -28,7 +28,8 @@ public:
    virtual ~TGLPlotBox();
 
    void DrawBox(Int_t selectedPart, Bool_t selectionPass, 
-                const std::vector<Double_t> &zLevels)const;
+                const std::vector<Double_t> &zLevels, 
+                Bool_t highColor)const;
 
    void SetPlotBox(const Rgl::Range_t &xRange, 
                    const Rgl::Range_t &yRange, 
diff --git a/gl/inc/TGLPlotPainter.h b/gl/inc/TGLPlotPainter.h
index b80af4da0f1..c48008ac09b 100644
--- a/gl/inc/TGLPlotPainter.h
+++ b/gl/inc/TGLPlotPainter.h
@@ -1,4 +1,4 @@
-// @(#)root/gl:$Name:  $:$Id: TGLPlotPainter.h,v 1.5 2006/08/31 16:03:10 brun Exp $
+// @(#)root/gl:$Name:  $:$Id: TGLPlotPainter.h,v 1.6 2006/10/02 12:55:47 couet Exp $
 // Author:  Timur Pocheptsov  14/06/2006
                                                                                 
 /*************************************************************************
@@ -65,6 +65,7 @@ protected:
    TGLPlotBox            fBackBox;
 
    std::vector<Double_t> fZLevels;
+   Bool_t                fHighColor;
 
 public:
    TGLPlotPainter(TH1 *hist, TGLOrthoCamera *camera, TGLPlotCoordinates *coord, Int_t context = -1,
diff --git a/gl/inc/TGLUtil.h b/gl/inc/TGLUtil.h
index fabb0730722..7515f8cbcf1 100644
--- a/gl/inc/TGLUtil.h
+++ b/gl/inc/TGLUtil.h
@@ -1,4 +1,4 @@
-// @(#)root/gl:$Name:  $:$Id: TGLUtil.h,v 1.32 2006/10/02 12:55:47 couet Exp $
+// @(#)root/gl:$Name:  $:$Id: TGLUtil.h,v 1.33 2006/10/11 10:26:23 rdm Exp $
 // Author:  Richard Maunder  25/05/2005
 
 /*************************************************************************
@@ -943,8 +943,8 @@ namespace Rgl {
    typedef std::pair<Int_t, Int_t> BinRange_t;
    typedef std::pair<Double_t, Double_t> Range_t;
 
-   void ObjectIDToColor(Int_t objectID);
-   Int_t ColorToObjectID(const UChar_t *color);
+   void ObjectIDToColor(Int_t objectID, Bool_t highColor);
+   Int_t ColorToObjectID(const UChar_t *color, Bool_t highColor);
    void DrawQuadOutline(const TGLVertex3 &v1, const TGLVertex3 &v2, 
                         const TGLVertex3 &v3, const TGLVertex3 &v4);
    void DrawQuadFilled(const TGLVertex3 &v0, const TGLVertex3 &v1, 
diff --git a/gl/inc/TX11GL.h b/gl/inc/TX11GL.h
index 729eb904b21..fb13a4305f6 100644
--- a/gl/inc/TX11GL.h
+++ b/gl/inc/TX11GL.h
@@ -1,4 +1,4 @@
-// @(#)root/x11:$Name:  $:$Id: TX11GL.h,v 1.13 2006/06/06 11:49:01 couet Exp $
+// @(#)root/x11:$Name:  $:$Id: TX11GL.h,v 1.14 2006/08/31 13:42:14 couet Exp $
 // Author: Timur Pocheptsov 09/08/2004
 
 /*************************************************************************
@@ -104,6 +104,8 @@ public:
    void     PanObject(TVirtualGLPainter *o, Int_t x, Int_t y);
    void     PrintViewer(TVirtualViewer3D *vv);
 
+   Bool_t   HighColorFormat(Int_t /*ctxInd*/){return kFALSE;}
+
    struct TGLContext_t;
    
 private:
diff --git a/gl/src/TGLBoxPainter.cxx b/gl/src/TGLBoxPainter.cxx
index 075d57b2a04..7a4be2e4163 100644
--- a/gl/src/TGLBoxPainter.cxx
+++ b/gl/src/TGLBoxPainter.cxx
@@ -39,7 +39,7 @@ char *TGLBoxPainter::GetPlotInfo(Int_t, Int_t)
             fPlotInfo += fHist->Class()->GetName();
          fPlotInfo += "::";
          fPlotInfo += fHist->GetName();
-      } else {
+      } else if (!fHighColor){
          const Int_t arr2Dsize = fCoord->GetNYBins() * fCoord->GetNZBins();
          const Int_t binI = (fSelectedPart - 6) / arr2Dsize + fCoord->GetFirstXBin();
          const Int_t binJ = (fSelectedPart - 6) % arr2Dsize / fCoord->GetNZBins() + fCoord->GetFirstYBin();
@@ -47,7 +47,8 @@ char *TGLBoxPainter::GetPlotInfo(Int_t, Int_t)
 
          fPlotInfo.Form("(binx = %d; biny = %d; binz = %d; binc = %f)", binI, binJ, binK,
                         fHist->GetBinContent(binI, binJ, binK));
-      }
+      } else
+         fPlotInfo = "Switch to true color mode to get correct info";
    }
 
    return (Char_t *)fPlotInfo.Data();
@@ -173,7 +174,7 @@ void TGLBoxPainter::DrawPlot()const
 {
    // Draw set of boxes (spheres)
 
-   fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels);
+   fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
    glDisable(GL_CULL_FACE);
    DrawSections();
    glEnable(GL_CULL_FACE);
@@ -210,6 +211,9 @@ void TGLBoxPainter::DrawPlot()const
    const TAxis   *yA = fYAxis;
    const TAxis   *zA = fZAxis;
 
+   if (fSelectionPass && fHighColor)
+      Rgl::ObjectIDToColor(7, fHighColor);
+
    for(Int_t ir = irInit, i = iInit; addI > 0 ? i < nX : i >= 0; ir += addI, i += addI) {
       for(Int_t jr = jrInit, j = jInit; addJ > 0 ? j < nY : j >= 0; jr += addJ, j += addJ) {
          for(Int_t kr = krInit, k = kInit; addK > 0 ? k < nZ : k >= 0; kr += addK, k += addK) {
@@ -219,9 +223,9 @@ void TGLBoxPainter::DrawPlot()const
 
             const Int_t binID = 6 + i * fCoord->GetNZBins() * fCoord->GetNYBins() + j * fCoord->GetNZBins() + k;
 
-            if (fSelectionPass)
-               Rgl::ObjectIDToColor(binID);
-            else if(fSelectedPart == binID)
+            if (fSelectionPass && !fHighColor)
+               Rgl::ObjectIDToColor(binID, fHighColor);
+            else if(!fHighColor && fSelectedPart == binID)
                glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gOrangeEmission);
 
                if (fType == kBox)
@@ -242,7 +246,7 @@ void TGLBoxPainter::DrawPlot()const
                                   zScale * (zA->GetBinLowEdge(kr) / 2 + zA->GetBinUpEdge(kr) / 2 + w * zA->GetBinWidth(kr) / 2)
                                  );
 
-            if (!fSelectionPass && fSelectedPart == binID)
+            if (!fSelectionPass && !fHighColor && fSelectedPart == binID)
                glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gNullEmission);
          }
       }
diff --git a/gl/src/TGLLegoPainter.cxx b/gl/src/TGLLegoPainter.cxx
index 09708c037fa..6bab0d44464 100644
--- a/gl/src/TGLLegoPainter.cxx
+++ b/gl/src/TGLLegoPainter.cxx
@@ -1,4 +1,4 @@
-// @(#)root/gl:$Name:  $:$Id: TGLLegoPainter.cxx,v 1.4 2006/08/31 13:42:14 couet Exp $
+// @(#)root/gl:$Name:  $:$Id: TGLLegoPainter.cxx,v 1.5 2006/10/02 12:55:47 couet Exp $
 // Author:  Timur Pocheptsov  14/06/2006
                                                                                 
 /*************************************************************************
@@ -47,12 +47,13 @@ char *TGLLegoPainter::GetPlotInfo(Int_t /*px*/, Int_t /*py*/)
             fBinInfo += fHist->Class()->GetName();
          fBinInfo += "::";
          fBinInfo += fHist->GetName();
-      } else {
+      } else if (!fHighColor) {
          const Int_t binI = (fSelectedPart - 6) / fCoord->GetNYBins() + fCoord->GetFirstXBin();
          const Int_t binJ = (fSelectedPart - 6) % fCoord->GetNYBins() + fCoord->GetFirstYBin();
          fBinInfo.Form("(binx = %d; biny = %d; binc = %f)", binI, binJ, 
                        fHist->GetBinContent(binI, binJ));
-      }
+      } else
+         fBinInfo = "Switch to true-color mode to obtain correct info";
    }
 
    return (Char_t *)fBinInfo.Data();
@@ -454,7 +455,7 @@ void TGLLegoPainter::DrawLegoCartesian()const
 {
    //Lego in cartesian system.
    if (fCoord->GetCoordType() == kGLCartesian) {
-      fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels);
+      fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
       const TGLDisableGuard cullGuard(GL_CULL_FACE);
       DrawSections();
    }
@@ -484,6 +485,9 @@ void TGLLegoPainter::DrawLegoCartesian()const
       if (!PreparePalette() || !fPalette.EnableTexture(GL_MODULATE))
          fLegoType = kColorSimple;         
 
+   if (fSelectionPass && fHighColor)
+      Rgl::ObjectIDToColor(6, kTRUE);
+
    for(Int_t i = iInit, ir = irInit; addI > 0 ? i < nX : i >= 0; i += addI, ir += addI) {
       for(Int_t j = jInit, jr = jrInit; addJ > 0 ? j < nY : j >= 0; j += addJ, jr += addJ) {
          Double_t zMax = fHist->GetCellContent(ir, jr) * fCoord->GetFactor();
@@ -492,9 +496,9 @@ void TGLLegoPainter::DrawLegoCartesian()const
 
          const Int_t binID = 6 + i * fCoord->GetNYBins() + j;
 
-         if (fSelectionPass)
-            Rgl::ObjectIDToColor(binID);
-         else if(fSelectedPart == binID)
+         if (fSelectionPass && !fHighColor)
+            Rgl::ObjectIDToColor(binID, kFALSE);
+         else if(!fHighColor && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gOrangeEmission);
          
          if (fLegoType == kCylindricBars) {
@@ -509,7 +513,7 @@ void TGLLegoPainter::DrawLegoCartesian()const
                               fYEdges[j].second, fMinZ, zMax, frontPoint);
          } 
 
-         if (!fSelectionPass && fSelectedPart == binID)
+         if (!fHighColor && !fSelectionPass && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gNullEmission);
       }
    }
@@ -573,6 +577,9 @@ void TGLLegoPainter::DrawLegoPolar()const
       if (!PreparePalette() || !fPalette.EnableTexture(GL_MODULATE))
          fLegoType = kColorSimple;         
 
+   if (fHighColor && fSelectionPass)
+      Rgl::ObjectIDToColor(6, kTRUE);
+
    for(Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
       for(Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
          Double_t zMax = fHist->GetCellContent(ir, jr);
@@ -589,9 +596,9 @@ void TGLLegoPainter::DrawLegoPolar()const
 
          const Int_t binID = 6 + i * fCoord->GetNYBins() + j;
 
-         if (fSelectionPass)
-            Rgl::ObjectIDToColor(binID);
-         else if(fSelectedPart == binID)
+         if (!fHighColor && fSelectionPass)
+            Rgl::ObjectIDToColor(binID, kFALSE);
+         else if(!fHighColor && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gOrangeEmission);
 
          if (fLegoType == kColorLevel && !fSelectionPass)
@@ -600,7 +607,7 @@ void TGLLegoPainter::DrawLegoPolar()const
          else
             Rgl::DrawTrapezoid(points, fMinZ, zMax);
 
-         if (!fSelectionPass && fSelectedPart == binID)
+         if (!fHighColor && !fSelectionPass && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gNullEmission);
       }
    }
@@ -663,7 +670,10 @@ void TGLLegoPainter::DrawLegoCylindrical()const
 
    if (fLegoType == kColorLevel && !fSelectionPass)
       if (!PreparePalette() || !fPalette.EnableTexture(GL_MODULATE))
-         fLegoType = kColorSimple;         
+         fLegoType = kColorSimple;      
+
+   if (fHighColor && fSelectionPass) 
+      Rgl::ObjectIDToColor(6, kTRUE); 
 
    for(Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
       for(Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
@@ -683,9 +693,9 @@ void TGLLegoPainter::DrawLegoCylindrical()const
 
          const Int_t binID = 6 + i * fCoord->GetNYBins() + j;
 
-         if (fSelectionPass)
-            Rgl::ObjectIDToColor(binID);
-         else if(fSelectedPart == binID)
+         if (fSelectionPass && !fHighColor)
+            Rgl::ObjectIDToColor(binID, kFALSE);
+         else if(!fHighColor && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gOrangeEmission);
 
          if (fLegoType == kColorLevel && !fSelectionPass){
@@ -694,7 +704,7 @@ void TGLLegoPainter::DrawLegoCylindrical()const
          }else
             Rgl::DrawTrapezoid(points, fYEdges[j].first, fYEdges[j].second);
 
-         if (!fSelectionPass && fSelectedPart == binID)
+         if(!fSelectionPass && !fHighColor && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gNullEmission);
       }
    }
@@ -759,7 +769,10 @@ void TGLLegoPainter::DrawLegoSpherical()const
 
    if (fLegoType == kColorLevel && !fSelectionPass)
       if (!PreparePalette() || !fPalette.EnableTexture(GL_MODULATE))
-         fLegoType = kColorSimple;         
+         fLegoType = kColorSimple;     
+
+   if (fSelectionPass && fHighColor)    
+      Rgl::ObjectIDToColor(6, kTRUE);
 
    for(Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
       for(Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
@@ -795,9 +808,9 @@ void TGLLegoPainter::DrawLegoSpherical()const
 
          const Int_t binID = 6 + i * fCoord->GetNYBins() + j;
          
-         if (fSelectionPass)
-            Rgl::ObjectIDToColor(binID);
-         else if(fSelectedPart == binID)
+         if (fSelectionPass && !fHighColor)
+            Rgl::ObjectIDToColor(binID, kFALSE);
+         else if(!fHighColor && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gOrangeEmission);
          if (fLegoType == kColorLevel && !fSelectionPass)
             Rgl::DrawTrapezoidTextured(points, fPalette.GetTexCoord(fMinZ), 
@@ -805,7 +818,7 @@ void TGLLegoPainter::DrawLegoSpherical()const
          else
             Rgl::DrawTrapezoid(points);
 
-         if(fSelectedPart == binID)
+         if(!fHighColor && fSelectedPart == binID)
             glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gNullEmission);
       }
    }
diff --git a/gl/src/TGLPlotBox.cxx b/gl/src/TGLPlotBox.cxx
index 8cb19faa303..2abad9b990f 100644
--- a/gl/src/TGLPlotBox.cxx
+++ b/gl/src/TGLPlotBox.cxx
@@ -50,7 +50,8 @@ TGLPlotBox::~TGLPlotBox()
 
 
 //______________________________________________________________________________
-void TGLPlotBox::DrawBox(Int_t selected, Bool_t selectionPass, const std::vector<Double_t> &zLevels)const
+void TGLPlotBox::DrawBox(Int_t selected, Bool_t selectionPass, const std::vector<Double_t> &zLevels,
+                         Bool_t highColor)const
 {
    // Draw back box for a plot.
 
@@ -79,7 +80,7 @@ void TGLPlotBox::DrawBox(Int_t selected, Bool_t selectionPass, const std::vector
                          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gRedEmission);
       }
    } else
-      ObjectIDToColor(1);//Bottom plane, encoded as 1 in a selection buffer.
+      ObjectIDToColor(1, highColor);//Bottom plane, encoded as 1 in a selection buffer.
 
    DrawQuadFilled(f3DBox[0], f3DBox[1], f3DBox[2], f3DBox[3], TGLVector3(0., 0., 1.));
 
@@ -89,7 +90,7 @@ void TGLPlotBox::DrawBox(Int_t selected, Bool_t selectionPass, const std::vector
       else if (selected == 2)
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gGreenEmission);
    } else
-      ObjectIDToColor(2);//Left plane, encoded as 2 in a selection buffer.
+      ObjectIDToColor(2, highColor);//Left plane, encoded as 2 in a selection buffer.
 
    DrawBackPlane(fgBackPairs[fFrontPoint][0], selectionPass, zLevels);
 
@@ -99,7 +100,7 @@ void TGLPlotBox::DrawBox(Int_t selected, Bool_t selectionPass, const std::vector
       else if (selected == 3)
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gGreenEmission);
    } else
-      ObjectIDToColor(3); //Right plane, encoded as 3 in a selection buffer.
+      ObjectIDToColor(3, highColor); //Right plane, encoded as 3 in a selection buffer.
    
    DrawBackPlane(fgBackPairs[fFrontPoint][1], selectionPass, zLevels);
 
diff --git a/gl/src/TGLPlotPainter.cxx b/gl/src/TGLPlotPainter.cxx
index c73111207cf..d978bf20eb9 100644
--- a/gl/src/TGLPlotPainter.cxx
+++ b/gl/src/TGLPlotPainter.cxx
@@ -1,4 +1,4 @@
-// @(#)root/gl:$Name:  $:$Id: TGLPlotPainter.cxx,v 1.5 2006/08/31 16:03:10 brun Exp $
+// @(#)root/gl:$Name:  $:$Id: TGLPlotPainter.cxx,v 1.6 2006/10/02 12:55:47 couet Exp $
 // Author:  Timur Pocheptsov  14/06/2006
                                                                                 
 /*************************************************************************
@@ -43,7 +43,8 @@ TGLPlotPainter::TGLPlotPainter(TH1 *hist, TGLOrthoCamera *camera, TGLPlotCoordin
                     fXOZSectionPos(0.),
                     fYOZSectionPos(0.),
                     fXOYSectionPos(0.),
-                    fBackBox(xoy)
+                    fBackBox(xoy),
+                    fHighColor(kFALSE)
 {
    //TGLPlotPainter's ctor.
    if (MakeGLContextCurrent())
@@ -57,6 +58,8 @@ void TGLPlotPainter::Paint()
    if (!MakeGLContextCurrent())
       return;
 
+   fHighColor = gGLManager->HighColorFormat(GetGLContext())? kTRUE : kFALSE;
+
    InitGL();
    //Save material/light properties in a stack.
    glPushAttrib(GL_LIGHTING_BIT);
@@ -149,7 +152,7 @@ Bool_t TGLPlotPainter::PlotSelected(Int_t px, Int_t py)
    py = fCamera->GetHeight() - py;
    //Y is a number of a row, x - column.
    std::swap(px, py);
-   Int_t newSelected(Rgl::ColorToObjectID(fSelection.GetPixelColor(px, py)));
+   Int_t newSelected(Rgl::ColorToObjectID(fSelection.GetPixelColor(px, py), fHighColor));
 
    if (newSelected != fSelectedPart) {
       //New object was selected (or surface deselected) - re-paint.
@@ -295,7 +298,7 @@ void TGLPlotPainter::DrawSections()const
       const TGLVertex3 v4(frame[1].X(), fXOZSectionPos, frame[1].Z());
 
       if (fSelectionPass)
-         Rgl::ObjectIDToColor(4);
+         Rgl::ObjectIDToColor(4, fHighColor);
       else if (fSelectedPart == 4)
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gBlueEmission);
   
@@ -338,7 +341,7 @@ void TGLPlotPainter::DrawSections()const
       TGLVertex3 v4(fYOZSectionPos, frame[4].Y(), frame[4].Z());
       
       if (fSelectionPass) {
-         Rgl::ObjectIDToColor(5);
+         Rgl::ObjectIDToColor(5, fHighColor);
       } else if (fSelectedPart == 5)
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gBlueEmission);
       
@@ -380,7 +383,7 @@ void TGLPlotPainter::DrawSections()const
       TGLVertex3 v4(frame[3].X(), frame[3].Y(), fXOYSectionPos);
       
       if (fSelectionPass) {
-         Rgl::ObjectIDToColor(6);
+         Rgl::ObjectIDToColor(6, fHighColor);
       } else if (fSelectedPart == 6)
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gBlueEmission);
       
diff --git a/gl/src/TGLSurfacePainter.cxx b/gl/src/TGLSurfacePainter.cxx
index 7c945db80ae..97bfef2fd2f 100644
--- a/gl/src/TGLSurfacePainter.cxx
+++ b/gl/src/TGLSurfacePainter.cxx
@@ -41,8 +41,11 @@ TGLSurfacePainter::TGLSurfacePainter(TH1 *hist, TGLOrthoCamera *camera, TGLPlotC
 char *TGLSurfacePainter::GetPlotInfo(Int_t px, Int_t py)
 {
    //Coords for point on surface under cursor.
-   if (fSelectedPart)
+   if (fSelectedPart) {
+      if (fHighColor)
+         return fSelectedPart < 7 ? (char *)"TF2" : (char *)"Switch to true-color mode to obtain correct info";
       return fSelectedPart < 7 ? (char *)"TF2" : WindowPointTo3DPoint(px, py);
+   }
    return "";
 }
 
@@ -248,7 +251,7 @@ void TGLSurfacePainter::DrawPlot()const
 {
    //Draw surf/surf1/surf2/surf4
    if (fCoord->GetCoordType() == kGLCartesian) {
-      fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels);
+      fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
       DrawSections();
       DrawProjections();
    }
@@ -280,11 +283,14 @@ void TGLSurfacePainter::DrawPlot()const
    const Int_t addI = frontPoint == 2 || frontPoint == 1 ? i = 0, 1 : (i = nX - 2, -1);
    const Int_t addJ = frontPoint == 2 || frontPoint == 3 ? firstJ = 0, 1 : (firstJ = nY - 2, -1);
 
+   if (fHighColor && fSelectionPass)
+      Rgl::ObjectIDToColor(7, kTRUE);
+
    for (; addI > 0 ? i < nX - 1 : i >= 0; i += addI) {
       for (Int_t j = firstJ; addJ > 0 ? j < nY - 1 : j >= 0; j += addJ) {
          Int_t triNumber = 2 * i * (nY - 1) + j * 2 + 7;
-         if (fSelectionPass)
-            Rgl::ObjectIDToColor(triNumber);
+         if (fSelectionPass && !fHighColor)
+            Rgl::ObjectIDToColor(triNumber, kFALSE);
 
          if ((fType == kSurf1 || fType == kSurf2 || fType == kSurf5) && !fSelectionPass)
              Rgl::DrawFaceTextured(fMesh[i][j + 1], fMesh[i][j], fMesh[i + 1][j],
@@ -298,8 +304,8 @@ void TGLSurfacePainter::DrawPlot()const
 
          ++triNumber;
 
-         if (fSelectionPass)
-            Rgl::ObjectIDToColor(triNumber);
+         if (fSelectionPass && !fHighColor)
+            Rgl::ObjectIDToColor(triNumber, kFALSE);
 
          if ((fType == kSurf1 || fType == kSurf2 || fType == kSurf5) && !fSelectionPass)
              Rgl::DrawFaceTextured(fMesh[i + 1][j], fMesh[i + 1][j + 1], fMesh[i][j + 1],
diff --git a/gl/src/TGLTF3Painter.cxx b/gl/src/TGLTF3Painter.cxx
index ac1562eef75..92f38d3582a 100644
--- a/gl/src/TGLTF3Painter.cxx
+++ b/gl/src/TGLTF3Painter.cxx
@@ -147,7 +147,7 @@ namespace {
 void TGLTF3Painter::DrawPlot()const
 {
    //Draw mesh.
-   fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels);
+   fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
 
    //Draw TF3 surface
    if (!fSelectionPass)
@@ -179,7 +179,7 @@ void TGLTF3Painter::DrawPlot()const
          glVertex3dv(fMesh[i].fXYZ[2].CArr());
       }
    } else {
-      Rgl::ObjectIDToColor(7);
+      Rgl::ObjectIDToColor(7, fHighColor);
       for (UInt_t i = 0, e = fMesh.size(); i < e; ++i) {
          glVertex3dv(fMesh[i].fXYZ[0].CArr());
          glVertex3dv(fMesh[i].fXYZ[1].CArr());
diff --git a/gl/src/TGLUtil.cxx b/gl/src/TGLUtil.cxx
index 7d0f433dd70..a7f3d6bc692 100644
--- a/gl/src/TGLUtil.cxx
+++ b/gl/src/TGLUtil.cxx
@@ -1,4 +1,4 @@
-// @(#)root/gl:$Name:  $:$Id: TGLUtil.cxx,v 1.29 2006/08/31 13:42:14 couet Exp $
+// @(#)root/gl:$Name:  $:$Id: TGLUtil.cxx,v 1.30 2006/10/02 12:55:47 couet Exp $
 // Author:  Richard Maunder  25/05/2005
 
 /*************************************************************************
@@ -11,6 +11,7 @@
 
 #include <algorithm>
 #include <string>
+#include <map>
 
 #include "THLimitsFinder.h"
 #include "TVirtualPad.h"
@@ -997,17 +998,91 @@ namespace Rgl {
    const Float_t gGrayEmission[]   = {0.3f,0.3f, 0.3f,1.f};
    const Float_t gNullEmission[]   = {0.f, 0.f,  0.f, 1.f};
 
+   namespace {
+      struct RGB_t {
+         Int_t fRGB[3];
+      };
+
+      RGB_t gColorTriplets[] = {{{255, 0, 0}}, 
+                                {{0, 255, 0}}, 
+                                {{0, 0, 255}}, 
+                                {{255, 255, 0}}, 
+                                {{255, 0, 255}}, 
+                                {{0, 255, 255}}, 
+                                {{128, 128, 128}}};
+
+      Bool_t operator < (const RGB_t &lhs, const RGB_t &rhs)
+      {
+         if (lhs.fRGB[0] < rhs.fRGB[0])
+            return kTRUE;
+         else if (lhs.fRGB[0] > rhs.fRGB[0])
+            return kFALSE;
+         else if (lhs.fRGB[1] < rhs.fRGB[1])
+            return kTRUE;
+         else if (lhs.fRGB[1] > rhs.fRGB[1])
+            return kFALSE;
+         else if (lhs.fRGB[2] < rhs.fRGB[2])
+            return kTRUE;
+
+         return kFALSE;
+      }
+
+      typedef std::map<Int_t, RGB_t> ColorLookupTable_t;
+      typedef ColorLookupTable_t::const_iterator CLTCI_t;
+
+      ColorLookupTable_t gObjectIDToColor;
+
+      typedef std::map<RGB_t, Int_t> ObjectLookupTable_t;
+      typedef ObjectLookupTable_t::const_iterator OLTCI_t;
+
+      ObjectLookupTable_t gColorToObjectID;
+   }
    //______________________________________________________________________________
-   void ObjectIDToColor(Int_t objectID)
+   void ObjectIDToColor(Int_t objectID, Bool_t highColor)
    {
       //Object id encoded as rgb triplet.
-      glColor3ub(objectID & 0xff, (objectID & 0xff00) >> 8, (objectID & 0xff0000) >> 16);
+      if (!highColor)
+         glColor3ub(objectID & 0xff, (objectID & 0xff00) >> 8, (objectID & 0xff0000) >> 16);
+      else {
+         if (!gObjectIDToColor.size()) {
+         //Initialize lookup tables.
+            for (Int_t i = 0, id = 1; i < Int_t(sizeof gColorTriplets / sizeof(RGB_t)); ++i, ++id)
+               gObjectIDToColor[id] = gColorTriplets[i];
+            //6 is a number of "clean" colors, which cannot be distorted in high-color.
+            for (Int_t i = 0, id = 1; i < 6; ++i, ++id)
+               gColorToObjectID[gColorTriplets[i]] = id;
+         }
+
+         CLTCI_t it = gObjectIDToColor.find(objectID);
+
+         if (it != gObjectIDToColor.end())
+            glColor3ub(it->second.fRGB[0], it->second.fRGB[1], it->second.fRGB[2]);
+         else {
+            Error("ObjectIDToColor", "No color for such object ID: %d", objectID);
+            glColor3ub(0, 0, 0);
+         }
+      }
    }
 
    //______________________________________________________________________________
-   Int_t ColorToObjectID(const UChar_t *color)
+   Int_t ColorToObjectID(const UChar_t *pixel, Bool_t highColor)
    {
-      return color[0] | (color[1] << 8) | (color[2] << 16);
+      if (!highColor)
+         return pixel[0] | (pixel[1] << 8) | (pixel[2] << 16);
+      else {
+         if (!gObjectIDToColor.size())
+            return 0;
+
+         RGB_t triplet = {{pixel[0], pixel[1], pixel[2]}};
+         OLTCI_t it = gColorToObjectID.find(triplet);
+
+         if (it != gColorToObjectID.end())
+            return it->second;
+         else if(pixel[0] && pixel[1] && pixel[2])
+            return 7;
+         else
+            return 0;
+      }
    }
 
 
diff --git a/win32gdk/inc/TGWin32GL.h b/win32gdk/inc/TGWin32GL.h
index a717564f006..2f7d337c015 100644
--- a/win32gdk/inc/TGWin32GL.h
+++ b/win32gdk/inc/TGWin32GL.h
@@ -1,4 +1,4 @@
-// @(#)root/win32gdk:$Name:  $:$Id: TGWin32GL.h,v 1.11 2006/06/06 11:49:01 couet Exp $
+// @(#)root/win32gdk:$Name:  $:$Id: TGWin32GL.h,v 1.12 2006/08/31 13:42:14 couet Exp $
 // Author: Valeriy Onuchin  05/08/04
 
 /*************************************************************************
@@ -97,6 +97,8 @@ public:
    void     PanObject(TVirtualGLPainter *o, Int_t x, Int_t y);
    void     PrintViewer(TVirtualViewer3D *vv);
 
+   Bool_t   HighColorFormat(Int_t ctx);
+
 private:
    struct TGLContext;
    Bool_t   CreateDIB(TGLContext &ctx)const;
diff --git a/win32gdk/inc/TGWin32VirtualGLProxy.h b/win32gdk/inc/TGWin32VirtualGLProxy.h
index 821ac8ce8cf..9910271a7b3 100644
--- a/win32gdk/inc/TGWin32VirtualGLProxy.h
+++ b/win32gdk/inc/TGWin32VirtualGLProxy.h
@@ -1,4 +1,4 @@
-// @(#)root/win32gdk:$Name:  $:$Id: TGWin32VirtualGLProxy.h,v 1.19 2006/06/06 11:49:01 couet Exp $
+// @(#)root/win32gdk:$Name:  $:$Id: TGWin32VirtualGLProxy.h,v 1.20 2006/08/31 13:42:14 couet Exp $
 // Author: Valeriy Onuchin   05/08/04
 
 /*************************************************************************
@@ -154,6 +154,7 @@ public:
    void     PrintViewer(TVirtualViewer3D *vv);
    Bool_t   PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py);
    char    *GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py);
+   Bool_t   HighColorFormat(Int_t ctx);
 
    static TGLManager *ProxyObject();
    static TGLManager *RealObject();
diff --git a/win32gdk/src/TGWin32GL.cxx b/win32gdk/src/TGWin32GL.cxx
index fdfde6fe425..5e28214343b 100644
--- a/win32gdk/src/TGWin32GL.cxx
+++ b/win32gdk/src/TGWin32GL.cxx
@@ -1,4 +1,4 @@
-// @(#)root/win32gdk:$Name:  $:$Id: TGWin32GL.cxx,v 1.14 2006/06/13 15:43:39 couet Exp $
+// @(#)root/win32gdk:$Name:  $:$Id: TGWin32GL.cxx,v 1.15 2006/08/31 13:42:14 couet Exp $
 // Author: Valeriy Onuchin(TGWin32GL)/ Timur Pocheptsov (TGWin32GLManager)
 
 /*************************************************************************
@@ -173,6 +173,8 @@ struct TGWin32GLManager::TGLContext {
    Int_t        fX;
    Int_t        fY;
    //
+   Bool_t       fHighColor;
+   //
    Bool_t       fDirect;
    //
    UChar_t     *fDIBData;
@@ -391,6 +393,9 @@ Int_t TGWin32GLManager::CreateGLContext(Int_t winInd)
          }
 
          TGLContext newDevice = {winInd, -1, hDC, 0, glCtx};
+         PIXELFORMATDESCRIPTOR testFormat = {};
+         DescribePixelFormat(hDC, pixFormat, sizeof testFormat, &testFormat);
+         newDevice.fHighColor = testFormat.cColorBits < 24 ? kTRUE : kFALSE;
 
          if (TGLContext *ctx = fPimpl->fNextFreeContext) {
             Int_t ind = ctx->fWindowIndex;
@@ -450,7 +455,7 @@ Bool_t TGWin32GLManager::CreateDIB(TGLContext &ctx)const
 Bool_t TGWin32GLManager::AttachOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
 {
    TGLContext &ctx = fPimpl->fGLContexts[ctxInd];
-   TGLContext newCtx = {ctx.fWindowIndex, -1, ctx.fDC, 0, ctx.fGLContext, w, h, x, y};
+   TGLContext newCtx = {ctx.fWindowIndex, -1, ctx.fDC, 0, ctx.fGLContext, w, h, x, y, ctx.fHighColor};
 
    if (CreateDIB(newCtx)) {
       ctx = newCtx;
@@ -468,7 +473,7 @@ Bool_t TGWin32GLManager::ResizeOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, U
 
    if (ctx.fPixmapIndex != -1)
       if (TMath::Abs(Int_t(w) - Int_t(ctx.fW)) > 1 || TMath::Abs(Int_t(h) - Int_t(ctx.fH)) > 1) {
-         TGLContext newCtx = {ctx.fWindowIndex, -1, ctx.fDC, 0, ctx.fGLContext, w, h, x, y};
+         TGLContext newCtx = {ctx.fWindowIndex, -1, ctx.fDC, 0, ctx.fGLContext, w, h, x, y, ctx.fHighColor};
          if (CreateDIB(newCtx)) {
             //new DIB created
             gVirtualX->SelectWindow(ctx.fPixmapIndex);
@@ -633,3 +638,12 @@ char *TGWin32GLManager::GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py)
 {
     return plot->GetPlotInfo(px, py);
 }
+
+//______________________________________________________________________________
+Bool_t TGWin32GLManager::HighColorFormat(Int_t ctxInd)
+{
+   if (ctxInd == -1)
+      return kFALSE;
+
+   return fPimpl->fGLContexts[ctxInd].fHighColor;
+}
diff --git a/win32gdk/src/TGWin32VirtualGLProxy.cxx b/win32gdk/src/TGWin32VirtualGLProxy.cxx
index 6960c6f0a1d..2b41bd97a78 100644
--- a/win32gdk/src/TGWin32VirtualGLProxy.cxx
+++ b/win32gdk/src/TGWin32VirtualGLProxy.cxx
@@ -1,4 +1,4 @@
-// @(#)root/win32gdk:$Name:  $:$Id: TGWin32VirtualGLProxy.cxx,v 1.21 2006/06/06 11:49:01 couet Exp $
+// @(#)root/win32gdk:$Name:  $:$Id: TGWin32VirtualGLProxy.cxx,v 1.22 2006/08/31 13:42:14 couet Exp $
 // Author: Valeriy Onuchin   05/08/04
 
 /*************************************************************************
@@ -157,3 +157,4 @@ RETURN_METHOD_ARG2(GLManager, Bool_t, SelectViewer, TVirtualViewer3D *, viewer,
 RETURN_METHOD_ARG3(GLManager, Bool_t, PlotSelected, TVirtualGLPainter *, plot, Int_t, x, Int_t, y)
 RETURN_METHOD_ARG3(GLManager, char *, GetPlotInfo, TVirtualGLPainter *, plot, Int_t, x, Int_t, y)
 RETURN_METHOD_ARG4(GLManager, Bool_t, SelectManip, TVirtualGLManip *, manip, const TGLCamera *, camera, const TGLRect *, rect, const TGLBoundingBox *, box)
+RETURN_METHOD_ARG1(GLManager, Bool_t, HighColorFormat, Int_t, ctx)
-- 
GitLab