Problem with OpenGL

Hi,

I have a simple code which displays 12 wires with TGeo objects. Everything looks fine in the 2D view. But when I start the opengl mode in the MenuClicked method only one wire is displayed in the opengl window.

What’s wrong with my code?

code:

void DCTDriftChamber::Init()
{
int i,j;
char volumeName[100];
char shapeName[100];

fCanvas = new TRootEmbeddedCanvas(“DriftChamberCanvas”, this, 800, 400);

AddFrame(fCanvas,
new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 1, 1));

// manager
fGeoManager = new TGeoManager( “Example”, “Example geometry” );
// define materials
fGeoMaterialVacuum = new TGeoMaterial( “Vacuum”, 0, 0, 0 );
fGeoMaterialAl = new TGeoMaterial( “Al”, 26.98, 13, 2.7 );
// define mediums
fGeoMediumVacuum = new TGeoMedium( “MediumVacuum”, 0, fGeoMaterialVacuum );
fGeoMediumAl = new TGeoMedium( “MediumAl”, 1, fGeoMaterialAl );
// define vacuum
fGeoVolumeVacuum = fGeoManager->MakeBox( “VolumeVacuum”, fGeoMediumVacuum, 800., 800., 800. );
// add vacuum
fGeoManager->SetTopVolume( fGeoVolumeVacuum );

TGeoRotation *rot = new TGeoRotation(“rot”,0,90,90);

// wires
fAnodeWire = new TGeoVolume**[4];
for (i=0;i<4;i++) {
fAnodeWire[i] = new TGeoVolume*[3];
for (j=0;j<3;j++) {
sprintf(volumeName,“volumeAnodeWire_%d_%d”,i,j);
sprintf(shapeName,“shapeAnodeWire_%d_%d”,i,j);
fAnodeWire[i][j] = new TGeoVolume(volumeName,new TGeoTube( shapeName, 0, 0.5, 115) , fGeoMediumAl);
fGeoVolumeVacuum->AddNode(fAnodeWire[i][j],1,new TGeoCombiTrans(9j,0,20i,rot));
}
}

// close and draw
fGeoManager->CloseGeometry();
fGeoVolumeVacuum->Draw();

}
void DCTDriftChamber::MenuClicked(TGPopupMenu *menu,Long_t param)
{
int exitID=1,i,j;
bool flag = true;
switch (param) {
case gWindow->M_VIEW_OPENGL:
TViewerOpenGL gl = new TViewerOpenGL(fCanvas->GetCanvas());
gl->BeginScene();
for (i=0;i<4;i++) {
for (j=0;j<3;j++) {
gl->AddObject(i
3+j,fAnodeWire[i][j]->GetShape()->GetBuffer3D(0,0));
}
}
gl->EndScene();
break;
}
}

Hi,

I’m not able to test this as I don’t have a full DCTDriftChamber definition - however you don’t need to explictly create the viewer or call BeginScene, AddObject etc.

At the end of Init() you call:

fGeoVolumeVacuum->Draw();

this will attach the TVolume to the current pad (gPad). The pad paints these objects via the current 3D viewer

So in MenuClicked() you can just put:

gPad->GetViewer3D(“ogl”); // Create OpenGL viewer

The TVolume/TGeoPainter objects will take responsiblity for sending the objects to the GL viewer via TVirtualViewer3D, in correct reference frame etc - which is probably the cause of you only seeing one object.

Please let me know if this helps.

Best wishes

Richard

That solved it.

Thanks