00001 /* 00002 Test program for random GCL stuff 00003 00004 */ 00005 00006 #include "gcl/XGraphicsSystem.h" 00007 #include "gcl/EPSRenderer.h" 00008 #include "gcl/MesaRenderer.h" 00009 #include "gcl/Readers.h" 00010 #include <stdlib.h> 00011 #include "gcl/SceneLang.h" 00012 00013 static Void CubeScene(Renderer &pane) 00014 { 00015 pane 00016 .SetTransform(Rotation(vl_y, vl_pi / 2.0)) 00017 .Begin(renPoly) 00018 .SetColour(cRed) 00019 .SetPoint(Point(-1, -1, 1)) 00020 .SetPoint(Point(-1, 1, 1)) 00021 .SetPoint(Point( 1, 1, 1)) 00022 .SetPoint(Point( 1, -1, 1)) 00023 .End(); 00024 00025 pane 00026 .Push() 00027 .SetTransform(Rotation(vl_y, vl_pi / 2.0)) 00028 .Begin(renPoly) 00029 .SetColour(cBlue) 00030 .SetPoint(Point(-1, -1, 1)) 00031 .SetPoint(Point(-1, 1, 1)) 00032 .SetPoint(Point( 1, 1, 1)) 00033 .SetPoint(Point( 1, -1, 1)) 00034 .End(); 00035 00036 pane 00037 .SetTransform(Rotation(vl_y, vl_pi / 2.0)) 00038 .Begin(renPoly) 00039 .SetColour(cOrange) 00040 .SetPoint(Point(-1, -1, 1)) 00041 .SetPoint(Point(-1, 1, 1)) 00042 .SetPoint(Point( 1, 1, 1)) 00043 .SetPoint(Point( 1, -1, 1)) 00044 .End(); 00045 00046 pane 00047 .Pop() 00048 .SetTransform(Rotation(vl_x, vl_pi / 2.0)) 00049 .Begin(renPoly) 00050 .SetColour(cGreen) 00051 .SetPoint(Point(-1, -1, 1)) 00052 .SetPoint(Point(-1, 1, 1)) 00053 .SetPoint(Point( 1, 1, 1)) 00054 .SetPoint(Point( 1, -1, 1)) 00055 .End(); 00056 00057 pane 00058 .Pop() 00059 .Show(); 00060 } 00061 00062 Void ImageTest(Renderer &myPane1) 00063 { 00064 #if 0 00065 myPane1.GetImage(image); 00066 00067 00068 cout << "grabbed image of " << image.Rows() << " x " << image.Cols() << endl; 00069 cout << "starting pane 2" << endl; 00070 00071 myPane2.Clear().SetImage(image); 00072 myPane2.Show(); 00073 00074 #if 0 00075 Pixel::currentChannel = chRed; 00076 image.MakeBlock(1); 00077 myPane1.Clear().Image(image); 00078 myPane1.Show(); 00079 Pixel::currentChannel = chBlue; 00080 image.MakeBlock(0.5); 00081 myPane1.Clear(); 00082 myPane1.SetImage(image); 00083 myPane1.Show(); 00084 Pixel::currentChannel = chGreen; 00085 image.MakeBlock(0.2); 00086 myPane1.Clear(); 00087 myPane1.SetImage(image); 00088 myPane1.Show(); 00089 00090 blob.SetSize(50, 50); 00091 blob.MakeUnit(1); 00092 sub(image, 30, 40, 50, 50) = blob; 00093 00094 myPane1.Clear(); 00095 myPane1.SetImage(image); 00096 myPane1.Show(); 00097 00098 gs.Run(); 00099 #endif 00100 #endif 00101 } 00102 00103 Void GouraudTest(Renderer *r) 00104 { 00105 r->Clear().Show(); 00106 r->Begin(renPoly); 00107 r->SetColour(cRed).SetPoint(Point(-1, -1, 0)) 00108 .SetColour(cGreen).SetPoint(Point(1, -1, 0)) 00109 .SetColour(cBlue).SetPoint(Point(1, 1, 0)) 00110 .SetColour(cWhite).SetPoint(Point(-1, 1, 0)); 00111 r->End(); 00112 r->Show(); 00113 } 00114 00115 Void XWindowsTest() 00116 { 00117 XGraphicsSystem *xgs; 00118 XEventPane *window; 00119 RGBAImage image; 00120 Int x; 00121 00122 xgs = new XGraphicsSystem; 00123 xgs->DumpVisualInfo(); 00124 window = new XEventPane; 00125 xgs->CreateWindow(window, "bob", 200, 200); 00126 image.SetSize(200, 200); 00127 image.Clear(cRed); 00128 window->PutImage(image); 00129 00130 xgs->Run(); 00131 window->Hide(); 00132 xgs->Spin(); 00133 cin >> x; 00134 window->Resize(400, 400); 00135 window->Show(); 00136 window->PutImage(image); 00137 xgs->Run(); 00138 window->Resize(600, 600); 00139 cin >> x; 00140 xgs->Run(); 00141 00142 } 00143 00144 #include "gcl/Clipper.h" 00145 00146 class MyClip : public Clipper 00147 { 00148 public: 00149 Void ViewPoint(const HPoint &p, Bool draw); 00150 }; 00151 00152 Void MyClip::ViewPoint(const HPoint &p, Bool draw) 00153 { 00154 if (draw) 00155 cout << "to " << p << endl; 00156 else 00157 cout << "from " << p << endl; 00158 } 00159 00160 Void ClipTest() 00161 { 00162 MyClip clipper; 00163 00164 clipper.ClipPoint(HPoint(1.1, 2.2, 1.2, 1.0), false); 00165 clipper.ClipPoint(HPoint(2.0, 2.5, 1.5, 1.0), true); 00166 clipper.ClipPoint(HPoint(0.5, 0.5, 0.1, 1.0), true); 00167 clipper.ClipPoint(HPoint(0.4, -0.5, 0.1, 1.0), true); 00168 clipper.ClipPoint(HPoint(0.4, 0.5, -0.1, 1.0), true); 00169 cout << endl; 00170 } 00171 00172 #define ON 00173 00174 main(int argc, char **argv) 00175 { 00176 XGraphicsSystem *xgs; 00177 00178 EPSRenderer *epsRenderer; 00179 MesaRenderer *mesaRenderer; 00180 GLXPane *xglRenderer; 00181 Renderer *r; 00182 00183 Camera camera(false); 00184 Int i; 00185 RGBAImage image; 00186 scScenePtr scene; 00187 FileName file; 00188 00189 slInit(); 00190 00191 // XWindowsTest(); 00192 ClipTest(); 00193 00194 00195 #ifdef OFF 00196 image.SetSize(400, 400); 00197 image.Clear(cGrey); 00198 mesaRenderer = new MesaRenderer; 00199 mesaRenderer->Init(image); 00200 r = mesaRenderer; 00201 #endif 00202 00203 #ifdef OFF 00204 #define PAUSE gs.Run() 00205 xglRenderer = new GLXPane; 00206 gs.CreateWindow(xglRenderer, "blob", 400, 400); 00207 r = xglRenderer; 00208 #else 00209 #define PAUSE 00210 #endif 00211 00212 #ifdef OFF 00213 image.SetSize(100, 100); 00214 image.Clear(cPurple); 00215 r->SetBgColour(cGrey); 00216 r->Clear(); 00217 r->PutImage(image); 00218 r->Show(); 00219 PAUSE; 00220 #endif 00221 00222 #ifdef OFF 00223 image.SetSize(200, 200); 00224 image.Clear(cGreen); 00225 file.SetPath("green.ppm"); 00226 image.Save(file); 00227 #endif 00228 00229 #ifdef OFF 00230 image.Clear(cGrey75); 00231 for (i = 0; i < 20; i++) 00232 { 00233 PaintSky(image, Coord(0.45 - i / 20.0, 0.45 - i / 20.0)); 00234 file.SetPath(String().Printf("sky-%04d.tif", i)); 00235 image.Save(file); 00236 } 00237 #endif 00238 00239 #ifdef OFF 00240 // file.SetPath("Black Sun:reactor:scenes:scomplex_09.sl"); 00241 file.SetPath("/usr/people/ajw/reactor/exp/scenes/simple/complex_01_01.sl"); 00242 // file.SetPath("/usr/people/ajw/reactor/rad/scenes/box.sl"); 00243 if (!(scene = SceneReader::Load(file))) 00244 exit(1); 00245 00246 r->SetBgColour(cGrey); 00247 r->Clear(); 00248 r->Draw(*scene); 00249 r->Show(); 00250 00251 // r->GetImage(image); 00252 file.SetPath("test.ppm"); 00253 image.Save(file); 00254 PAUSE; 00255 #endif 00256 00257 #ifdef OFF 00258 r->SetBgColour(cYellow); 00259 r->Clear(); 00260 camera.SetZoom(0.5); 00261 r->SetCamera(camera); 00262 r->SetTransform(Shift(Vector(0.3, 0.2, 0)) * Rotation(vl_z, DegsToRads(30))); 00263 GouraudTest(r); 00264 r->Show(); 00265 #endif 00266 00267 #ifdef OFF 00268 r->SetBgColour(cCyan); 00269 r->Clear(); 00270 camera.SetZoom(2); 00271 r->SetCamera(camera); 00272 CubeScene(*r); 00273 r->Show(); 00274 #endif 00275 00276 }