ROOT logo
// Various surfaces rendered with GL.
// This example draws 6 surfaces using OpenGL in pad (one is remake
// of a classic surfaces.C, another contains 4 surfaces).
//
// The commands used are exactly the same as with a normal pad. 
// The only command to add is: gStyle->SetCanvasPreferGL(true);
// Authors: Rene Brun, Timur Pocheptsov

void glsurfaces()
{
   gStyle->SetPalette(0);
   
   // after this command all legos surfaces (surf/srf1/surf2/surf4/tf3
   // options) are automatically rendered with OpenGL.
   gStyle->SetCanvasPreferGL(kTRUE);

   TCanvas *c1 = new TCanvas("glc1","Surfaces Drawing Options",200,10,700,900);
   c1->SetFillColor(42);
   gStyle->SetFrameFillColor(42);
   title = new TPaveText(0.2, 0.96, 0.8, 0.995);
   title->SetFillColor(33);
   title->AddText("Examples of Surface options");
   title->Draw();

   TPad *pad1 = new TPad("pad1","Gouraud shading", 0.03, 0.50, 0.98, 0.95, 21);
   TPad *pad2 = new TPad("pad2","Color mesh", 0.03, 0.02, 0.98, 0.48, 21);
   pad1->Draw();
   pad2->Draw();
   // We generate a 2-D function
   TF2 *f2 = new TF2("f2","x**2 + y**2 - x**3 -8*x*y**4", -1., 1.2, -1.5, 1.5);
   // Draw this function in pad1 with Gouraud shading option
   pad1->cd();
   pad1->SetLogz();
   f2->SetFillColor(45);
   f2->Draw("glsurf4");

   TF2 *f2clone = new TF2("f2clone","x**2 + y**2 - x**3 -8*x*y**4",
                          -1., 1.2, -1.5, 1.5);
   // Draw this function in pad2 with color mesh option
   pad2->cd();
   pad2->SetLogz();
   f2clone->Draw("glsurf1");
   
   //add axis titles. The titles are set on the intermediate
   //histogram used for visualisation. We must force this histogram
   //to be created, then force the redrawing of the two pads
   pad2->Update();
   f2->GetHistogram()->GetXaxis()->SetTitle("x title");
   f2->GetHistogram()->GetYaxis()->SetTitle("y title");
   f2->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
   f2->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
   f2clone->GetHistogram()->GetXaxis()->SetTitle("x title");
   f2clone->GetHistogram()->GetYaxis()->SetTitle("y title");
   f2clone->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
   f2clone->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
   pad1->Modified();
   pad2->Modified();

   TCanvas *c2 = new TCanvas("glc2","Surfaces Drawing Options with gl",
                             700,10,700,700);
   c2->SetFillColor(42);
   gStyle->SetFrameFillColor(42);

   c2->Divide(2, 2);

   c2->cd(1);
   TF2 *fun1 = new TF2("fun1","1000*((sin(x)/x)*(sin(y)/y))+200",
                       -6., 6., -6., 6.);
   fun1->SetNpx(30);
   fun1->SetNpy(30);
   fun1->SetFillColor(kGreen);
   fun1->Draw("glsurf3");

   c2->cd(2);
   TF2 *fun2 = new TF2("fun2","cos(y)*sin(x)+cos(x)*sin(y)",
                       -6., 6., -6., 6.);
   fun2->Draw("glsurf1cyl");

   c2->cd(3);
   TF2 *fun3 = new TF2("fun3","sin(x) / x * cos(y) * y", -6., 6., -6., 6.);
   fun3->Draw("glsurfpol");

   c2->cd(4);
   TF3 *fun4 = new TF3("TF3 sample","sin(x * x + y * y + z * z - 4)",
                       -2.5, 2.5, -2.5, 2.5, -2.5, 2.5);
   Int_t colInd = TColor::GetColor(1.f, 0.5f, 0.f);
   fun4->SetFillColor(colInd);
   fun4->Draw("gl");//tf3 option
}
 glsurfaces.C:1
 glsurfaces.C:2
 glsurfaces.C:3
 glsurfaces.C:4
 glsurfaces.C:5
 glsurfaces.C:6
 glsurfaces.C:7
 glsurfaces.C:8
 glsurfaces.C:9
 glsurfaces.C:10
 glsurfaces.C:11
 glsurfaces.C:12
 glsurfaces.C:13
 glsurfaces.C:14
 glsurfaces.C:15
 glsurfaces.C:16
 glsurfaces.C:17
 glsurfaces.C:18
 glsurfaces.C:19
 glsurfaces.C:20
 glsurfaces.C:21
 glsurfaces.C:22
 glsurfaces.C:23
 glsurfaces.C:24
 glsurfaces.C:25
 glsurfaces.C:26
 glsurfaces.C:27
 glsurfaces.C:28
 glsurfaces.C:29
 glsurfaces.C:30
 glsurfaces.C:31
 glsurfaces.C:32
 glsurfaces.C:33
 glsurfaces.C:34
 glsurfaces.C:35
 glsurfaces.C:36
 glsurfaces.C:37
 glsurfaces.C:38
 glsurfaces.C:39
 glsurfaces.C:40
 glsurfaces.C:41
 glsurfaces.C:42
 glsurfaces.C:43
 glsurfaces.C:44
 glsurfaces.C:45
 glsurfaces.C:46
 glsurfaces.C:47
 glsurfaces.C:48
 glsurfaces.C:49
 glsurfaces.C:50
 glsurfaces.C:51
 glsurfaces.C:52
 glsurfaces.C:53
 glsurfaces.C:54
 glsurfaces.C:55
 glsurfaces.C:56
 glsurfaces.C:57
 glsurfaces.C:58
 glsurfaces.C:59
 glsurfaces.C:60
 glsurfaces.C:61
 glsurfaces.C:62
 glsurfaces.C:63
 glsurfaces.C:64
 glsurfaces.C:65
 glsurfaces.C:66
 glsurfaces.C:67
 glsurfaces.C:68
 glsurfaces.C:69
 glsurfaces.C:70
 glsurfaces.C:71
 glsurfaces.C:72
 glsurfaces.C:73
 glsurfaces.C:74
 glsurfaces.C:75
 glsurfaces.C:76
 glsurfaces.C:77
 glsurfaces.C:78
 glsurfaces.C:79
 glsurfaces.C:80
 glsurfaces.C:81
 glsurfaces.C:82
 glsurfaces.C:83
 glsurfaces.C:84
 glsurfaces.C:85
 glsurfaces.C:86
 glsurfaces.C:87
 glsurfaces.C:88
 glsurfaces.C:89
 glsurfaces.C:90
thumb
thumb