Hi,
I tried to run the sample code /tutorials/gl/glvox1.C to create a 3D histogram plot with GL drawing option and save the plot into a file. The code works and the plot is saved to the disk if I run the code inside a root interpreter window. However, if I compile the code in visual studio 2010 as a function and run it, even though the plot was saved to the disk, when I open the plot, the plot is blank. Please find following the code. If I change the drawing option from hist->Draw(“glcol”); to hist->Draw(“bar”); The plot will be saved, but now the root is not using openGL and the plot is not colored. Could anyone help me out? Thanks.
void glvox1()
{
gStyle->SetCanvasPreferGL(true);
gStyle->SetPalette(1);
TCanvas *c1= new TCanvas(“c1”, “A Simple Graph Example”, 10, 10, 1000, 500);
const UInt_t nX = 30;
const Double_t xMin = -1., xMax = 1., xStep = (xMax - xMin) / (nX - 1);
const UInt_t nY = 30;
const Double_t yMin = -1., yMax = 1., yStep = (yMax - yMin) / (nY - 1);
const UInt_t nZ = 30;
const Double_t zMin = -1., zMax = 1., zStep = (zMax - zMin) / (nZ - 1);
TH3F *hist = new TH3F("glvoxel", "glvoxel", 30, -1., 1., 30, -1., 1., 30, -1., 1.);
//Fill the histogram to create a “sphere”.
for (UInt_t i = 0; i < nZ; ++i) {
const Double_t z = zMin + i * zStep;
for (UInt_t j = 0; j < nY; ++j) {
const Double_t y = yMin + j * yStep;
for (UInt_t k = 0; k < nX; ++k) {
const Double_t x = xMin + k * xStep;
const Double_t val = 1. - (x * x + y * y + z * z);
hist->SetBinContent(k + 1, j + 1, i + 1, val);
}
}
}
gStyle->SetCanvasPreferGL(1);
gStyle->SetPalette(1);
hist->Draw(“glcol”);
c1->SaveAs(“abcd.png”);