Re: Embedded GL

Norbert Danneberg (norbert.danneberg@psi.ch)
Sat, 24 Jul 1999 12:48:52 +0200


Hi Michael,

I had the same problem. We are using OpenGL now for our
Online Event Display. We solved the problem of coloring
our detector elements with a energy proportional color paletete the
folowing way.
You have to make sure that your computer has enough colors
(Millions) and switch the OPenGL window by hand to
truecolor mode.

hope tis helps

Norbert

#define COLORTABLE_START 240 //Start of color palette
#define NBGOCOLORS 5 // number of custom colors

++++++++++++++++++++++++++++++++++++
1.) define your own colors :
++++++++++++++++++++++++++++++++++++
TColor *Color;

for(Int_t i=0; i<NBGOCOLORS; i++)
{
Float_t r=0,g=0,b=0,light;

light=0.7+0.6*i/NBgoColors;
r=(1-(i/NBgoColors-0.4)*(i/NBgoColors-0.4))*light;
g=(1-(i/NBgoColors-0.7)*(i/NBgoColors-0.7))*light*0.5;
b=(1-(i/NBgoColors-0.9)*(i/NBgoColors-0.9))*light*0.8;

if(r>1) r=1; if(g>1) g=1; if(b>1) b=1;

Color= new TColor();
Color->SetNumber(COLORTABLE_START+i);
Color->SetRGB(r,g,b);
ColorList->Add(Color);

RootColorList->Add(Color); // this is important
}

ActiveNodes = new TList();

+++++++++++++++++++++++++++++++++++++++++++++
2.) Change the Color of the Object
++++++++++++++++++++++++++++++++++++++++++++++
void MTDetector::ColorBgo(Int_t Module, Int_t Color){
// changes the color of one BGO Module to
// indicate a hit.
Char_t NodeName[255];

sprintf(NodeName,"BGOD%i",Module+1);
TNode* BgoNode = MuPTGeom->GetNode(NodeName);

if(BgoNode){

BgoNode->SetLineColor(Color);
ActiveNodes->Add(BgoNode);

}else{

cout << "Error in MTDetector::ColorBGO: Node not found:"
<< NodeName << endl;

}
gPad->Modified();
}

+++++++++++++++++++++++++++++++++++++++++
3.) Draw the Hits
+++++++++++++++++++++++++++++++++++++++++

void MTDetector::DrawBgos(TClonesArray* BgoList){

MTBgoExtract* Bgo;
Int_t Module;
Float_t Energy;
Int_t Color;

TIter NextBgoEvent(BgoList);

while((Bgo=(MTBgoExtract *)NextBgoEvent()))
{
Module=Bgo->GetModuleNo();
if(Module>MAX_MULT_BGO)
{
cerr<<"No BGO-Module "<<Module
<<" in MTDeetctor::DrawEvent()"<<endl;
Module=0;
return;
}

Energy=Bgo->GetEnergy();


Color = (Int_t)(Energy/MAX_ENERGY * NBGOCOLORS+COLORTABLE_START);
ColorBgo(Module, Color);
}
}

+++++++++++++++++++++++++++++++++++++++++++
4.) Switch to truecolormode in the openGL window
++++++++++++++++++++++++++++++++++++++++++++

// Root uses a differnet color palette
// with only eight colors.
// One hase to switch to trucolor by hand.
gPad->x3d("OPENGL");
viewGL3D = (TPadOpenGLView*)gPad->GetView3D();
viewGL3D->MoveModelView('t'); // switch to natural light mode


Michael Katz-Hyman wrote:
>
> My quest for an embedded, smooth 3D display continues....
>
> Can OpenGL view be embedded in a TPad?
>
> Mike