TEveTextGL.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveTextGL.cxx 36384 2010-10-20 14:26:41Z matevz $
00002 // Authors: Alja & Matevz Tadel 2008
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveTextGL.h"
00013 #include "TEveText.h"
00014 #include "TGLUtil.h"
00015 #include "TGLCamera.h"
00016 
00017 #include "TGLRnrCtx.h"
00018 #include "TGLIncludes.h"
00019 #include "TGLBoundingBox.h"
00020 
00021 //______________________________________________________________________________
00022 //
00023 // OpenGL renderer class for TEveText.
00024 //
00025 
00026 ClassImp(TEveTextGL);
00027 
00028 //______________________________________________________________________________
00029 TEveTextGL::TEveTextGL() :
00030    TGLObject(),
00031    fM(0),
00032    fFont()
00033 {
00034    // Constructor.
00035 
00036    fDLCache = kFALSE; // Disable display list.
00037 }
00038 
00039 //______________________________________________________________________________
00040 Bool_t TEveTextGL::SetModel(TObject* obj, const Option_t* /*opt*/)
00041 {
00042    // Set model object.
00043 
00044    fM = SetModelDynCast<TEveText>(obj);
00045    return kTRUE;
00046 }
00047 
00048 //______________________________________________________________________________
00049 void TEveTextGL::SetBBox()
00050 {
00051    // Set bounding box.
00052 
00053    fBoundingBox.SetEmpty();
00054 }
00055 
00056 /******************************************************************************/
00057 
00058 //______________________________________________________________________________
00059 void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const
00060 {
00061    // Actual rendering code.
00062    // Virtual from TGLLogicalShape.
00063 
00064    static const TEveException eH("TEveTextGL::DirectDraw ");
00065 
00066    Int_t fm = fM->GetFontMode();
00067    if (fm == TGLFont::kBitmap || fm == TGLFont::kPixmap || fm == TGLFont::kTexture)
00068       rnrCtx.RegisterFont(fM->GetFontSize(), fM->GetFontFile(), fM->GetFontMode(), fFont);
00069    else
00070       rnrCtx.RegisterFontNoScale(fM->GetFontSize(), fM->GetFontFile(), fM->GetFontMode(), fFont);
00071 
00072    fFont.SetDepth(fM->GetExtrude());
00073 
00074    //  bbox initialisation
00075    if (fBoundingBox.IsEmpty() && fFont.GetMode() > TGLFont::kPixmap)
00076    {
00077       Float_t bbox[6];
00078       fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2],
00079                  bbox[3], bbox[4], bbox[5]);
00080 
00081       if (fFont.GetMode() == TGLFont::kExtrude) {
00082          // Depth goes, the other z-way, swap.
00083          Float_t tmp = bbox[2];
00084          bbox[2] = bbox[5] * fM->GetExtrude();
00085          bbox[5] = tmp     * fM->GetExtrude();
00086       } else {
00087          bbox[2] = -0.005*(bbox[4] - bbox[1]);
00088          bbox[5] = -0.005*(bbox[4] - bbox[1]);
00089       }
00090 
00091       TGLVertex3 low (bbox[0], bbox[1], bbox[2]);
00092       TGLVertex3 high(bbox[3], bbox[4], bbox[5]);
00093 
00094       TEveTextGL* ncthis = const_cast<TEveTextGL*>(this);
00095       ncthis->fBoundingBox.SetAligned(low, high);
00096       ncthis->UpdateBoundingBoxesOfPhysicals();
00097    }
00098 
00099    // rendering
00100    glPushMatrix();
00101    fFont.PreRender(fM->GetAutoLighting(), fM->GetLighting());
00102    switch (fFont.GetMode())
00103    {
00104       case TGLFont::kBitmap:
00105       case TGLFont::kPixmap:
00106          if (rnrCtx.Selection()) {
00107             // calculate 3D coordinates for picking
00108             const GLdouble *pm = rnrCtx.RefCamera().RefLastNoPickProjM().CArr();
00109             GLdouble mm[16];
00110             GLint    vp[4];
00111             glGetDoublev(GL_MODELVIEW_MATRIX,  mm);
00112             glGetIntegerv(GL_VIEWPORT, vp);
00113 
00114             fX[0][0] = fX[0][1] = fX[0][2] = 0;
00115             GLdouble x, y, z;
00116             gluProject(fX[0][0], fX[0][1], fX[0][2], mm, pm, vp, &x, &y, &z);
00117             Float_t bbox[6];
00118             fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2],
00119                        bbox[3], bbox[4], bbox[5]);
00120             gluUnProject(x + bbox[0], y + bbox[1], z, mm, pm, vp, &fX[0][0], &fX[0][1], &fX[0][2]);
00121             gluUnProject(x + bbox[3], y + bbox[1], z, mm, pm, vp, &fX[1][0], &fX[1][1], &fX[1][2]);
00122             gluUnProject(x + bbox[3], y + bbox[4], z, mm, pm, vp, &fX[2][0], &fX[2][1], &fX[2][2]);
00123             gluUnProject(x + bbox[0], y + bbox[4], z, mm, pm, vp, &fX[3][0], &fX[3][1], &fX[3][2]);
00124 
00125             glBegin(GL_POLYGON);
00126             glVertex3dv(fX[0]);
00127             glVertex3dv(fX[1]);
00128             glVertex3dv(fX[2]);
00129             glVertex3dv(fX[3]);
00130             glEnd();
00131          } else {
00132             glRasterPos3i(0, 0, 0);
00133             fFont.Render(fM->GetText());
00134          }
00135          break;
00136       case TGLFont::kOutline:
00137       case TGLFont::kExtrude:
00138       case TGLFont::kPolygon:
00139          glPolygonOffset(fM->GetPolygonOffset(0), fM->GetPolygonOffset(1));
00140          if (fM->GetExtrude() != 1.0) {
00141             glPushMatrix();
00142             glScalef(1.0f, 1.0f, fM->GetExtrude());
00143             fFont.Render(fM->GetText());
00144             glPopMatrix();
00145          } else {
00146             fFont.Render(fM->GetText());
00147          }
00148          break;
00149       case TGLFont::kTexture:
00150          glPolygonOffset(fM->GetPolygonOffset(0), fM->GetPolygonOffset(1));
00151          fFont.Render(fM->GetText());
00152          break;
00153       default:
00154          throw(eH + "unsupported FTGL-type.");
00155    }
00156    fFont.PostRender();
00157    glPopMatrix();
00158 }

Generated on Tue Jul 5 14:16:14 2011 for ROOT_528-00b_version by  doxygen 1.5.1