static void Main() { try { using (AntRenderForm window = new AntRenderForm("Insight Library Sample")) { using (Renderer renderer = new Renderer(window)) { RenderLoop.Run(window, () => { renderer.Update(); renderer.Render(); }); } } } catch (Exception ex) { Console.WriteLine(ex); // TODO: better error reporting later on MessageBox.Show(ex.Message, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Prints a page of the current note /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { // Translate the graphics by the printable margin IntPtr hDC = e.Graphics.GetHdc(); const int PHYSICALOFFSETX = 112; /* Physical Printable Area x margin */ const int PHYSICALOFFSETY = 113; /* Physical Printable Area y margin */ int offsetX = GetDeviceCaps(hDC, PHYSICALOFFSETX); int offsetY = GetDeviceCaps(hDC, PHYSICALOFFSETY); e.Graphics.ReleaseHdc( hDC ); e.Graphics.PageUnit = GraphicsUnit.Pixel; // Build paper clip rectangle Rectangle paper = new Rectangle( (int)((e.Graphics.DpiX/4)-offsetX), (int)((e.Graphics.DpiY/4)-offsetY), (int)((e.PageBounds.Width*e.Graphics.DpiX/100)-(e.Graphics.DpiX/2)), (int)((e.PageBounds.Height*e.Graphics.DpiY/100)-(e.Graphics.DpiY*3/4))); // Convert width and height to hi-metric int pageWidth = (int)(paper.Width*2540/e.Graphics.DpiX); int pageHeight = (int)(paper.Height*2540/e.Graphics.DpiY); // Adjust document position if it is smaller than clip rectangle int offset = Math.Min(Math.Max(pageWidth-fNoteBox.Document.Stationery.MinWidth, 0)/2, 2540*3/4); int dx = (int)(offset*e.Graphics.DpiX/2540); int dy = (int)(offset*e.Graphics.DpiY/2540); paper.Inflate(-dx, -dy); // Transform graphics to map hi-metric units to paper pixels e.Graphics.TranslateTransform(paper.X, paper.Y); e.Graphics.ScaleTransform(e.Graphics.DpiX/2540f, e.Graphics.DpiY/2540f); e.Graphics.TranslateTransform(0, -pageHeight*fPrintPage); // Convert paper rectangle to hi-metric for clip rectangle Point[] pts = { paper.Location, new Point(paper.Right, paper.Bottom) }; Matrix invert = e.Graphics.Transform; invert.Invert(); invert.TransformPoints(pts); Rectangle clipRectangle = Rectangle.FromLTRB(pts[0].X, pts[0].Y, pts[1].X, pts[1].Y); // Render a physical page of the note Renderer renderer = new Renderer(fNoteBox.Document); renderer.Draw(e.Graphics, clipRectangle, fNoteBox.Document.Size); // Check to see if the whole note has printed or if it requires more physical pages if ((fPrintPage+1)*pageHeight < fNoteBox.Document.Height) { e.HasMorePages = true; fPrintPage++; } }
public static void Main(string[] args) { using (var device = new Device(DriverType.Hardware)) { using (var form = new ATBRenderForm("DX11 AntTweakBar Sample")) { using (var renderer = new Renderer(device, form)) { // At this point we can initialize the AntTweakBar context // (since the renderer has now created the D3D device) using (var context = new Context(Tw.GraphicsAPI.D3D11, renderer.DevicePointer)) { form.Context = context; // Add a bar with some variables in it var exampleBar = new Bar(form.Context); exampleBar.Label = "Example Bar"; exampleBar.Contained = true; // here we bind the variables to the renderer variables with their Changed event // (their initial value is whatever the renderer currently has set them to) var color1Var = new ColorVariable(exampleBar, renderer.P1Color.X, renderer.P1Color.Y, renderer.P1Color.Z); color1Var.Label = "P1 color"; color1Var.Changed += delegate { renderer.P1Color = new Vector3(color1Var.R, color1Var.G, color1Var.G); }; var color2Var = new ColorVariable(exampleBar, renderer.P2Color.X, renderer.P2Color.Y, renderer.P2Color.Z); color2Var.Label = "P2 color"; color2Var.Changed += delegate { renderer.P2Color = new Vector3(color2Var.R, color2Var.G, color2Var.G); }; var color3Var = new ColorVariable(exampleBar, renderer.P3Color.X, renderer.P3Color.Y, renderer.P3Color.Z); color3Var.Label = "P3 color"; color3Var.Changed += delegate { renderer.P3Color = new Vector3(color3Var.R, color3Var.G, color3Var.G); }; // Put the color selection variables in their own group var colorGroup = new Group(exampleBar, "Colors", color1Var, color2Var, color3Var); var wireframeVar = new BoolVariable(exampleBar); wireframeVar.Label = "Wireframe"; wireframeVar.Changed += delegate { renderer.Wireframe = wireframeVar.Value; }; var scaleVar = new FloatVariable(exampleBar, renderer.Scale); scaleVar.Label = "Scale"; scaleVar.Changed += delegate { renderer.Scale = scaleVar.Value; }; scaleVar.SetDefinition("min=-2 max=2 step=0.01 precision=2"); var separator = new Separator(exampleBar); var testButton = new AntTweakBar.Button(exampleBar); testButton.Label = "Click me!"; testButton.Clicked += delegate { MessageBox.Show("Button Clicked!"); }; // The renderer needs to recreate some resources on window resize form.Resize += delegate { renderer.Resize(form.ClientSize); }; // In the main loop, render stuff, then the bar(s), then present to screen RenderLoop.Run(form, () => { renderer.Render(); form.Context.Draw(); renderer.Present(); }); } } } } }
/// <summary> /// Entry point - pass "verbose" as a command-line /// argument to initialize Embree in verbose mode. /// </summary> public static int Main(String[] args) { try { var verbose = (args.Length == 1 && args[0].ToLower() == "verbose"); if (verbose) { Console.WriteLine("Embree.NET Sample [VERBOSE]"); Console.WriteLine("==========================="); RTC.Register("verbose=999"); // max verbosity? } else { Console.WriteLine("Embree.NET Sample"); Console.WriteLine("================="); } Console.WriteLine(""); // this is for debugging Console.WriteLine("[+] " + Bits + "-bit mode."); Console.WriteLine("[+] Building a test scene."); using (var renderer = new Renderer()) { var pixBuf = new PixelBuffer(1920, 1080); Console.WriteLine("[+] Now rendering."); renderer.Render(pixBuf); // benchmark? Console.WriteLine("[+] Saving image to 'render.png'."); pixBuf.SaveToFile("render.png"); // save to png format } if (verbose) RTC.Unregister(); return EXIT_SUCCESS; } catch (Exception e) { var msg = e is AggregateException ? e.InnerException.Message : e.Message; Console.WriteLine(String.Format("[!] Error: {0}.", msg)); Console.WriteLine("\n========= STACK TRACE =========\n"); Console.WriteLine(e.StackTrace); return EXIT_FAILURE; } }
private void PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PrintDocument doc = (sender as PrintDocument); // Convert to HiMetric Rectangle paper = new Rectangle(0, 0, e.MarginBounds.Width * 2540 / 100, e.MarginBounds.Height * 2540 / 100); Renderer renderer = new Renderer(fScribble.Document); // Paginate the first time through if (fPrintPhysicalRectangles.Count == 0) { for(int page=doc.PrinterSettings.FromPage-1; page<Math.Min(fScribble.Document.Pages.Count, doc.PrinterSettings.ToPage); page++) { // Adjust the size of the margins Rectangle pagePaper = GetAdjustedSize(fScribble.Document.Pages[page],paper); pagePaper.Location = new Point(0,0); fPrintPhysicalRectangles.Add(renderer.GetPhysicalPages(page, pagePaper.Size, pagePaper.Size)); } } if (fPrintPage >= Math.Min(fScribble.Document.Pages.Count, doc.PrinterSettings.ToPage)) return; Rectangle[] clipRectangles = ((Rectangle[])fPrintPhysicalRectangles[fPrintPage-(doc.PrinterSettings.FromPage-1)]); Rectangle clipRectangle = clipRectangles[fPrintRectangle]; Rectangle adjustedPaper = GetAdjustedSize(fScribble.Document.Pages[fPrintPage],paper); GraphicsState state = e.Graphics.Save(); // The clipRectangle may be larger than what we asked for, // As the GetPhysicalPages call automatically scales to fit the width float scale = (float)adjustedPaper.Width/(float)clipRectangle.Width; // Set the graphics context to HiMetric, and translate so that the print origin is at (0,0) SizeF offset = new SizeF(e.Graphics.Transform.OffsetX,e.Graphics.Transform.OffsetY); e.Graphics.TranslateTransform(-offset.Width,-offset.Height); e.Graphics.PageUnit = GraphicsUnit.Pixel; e.Graphics.ScaleTransform(e.Graphics.DpiX/2540f*scale, e.Graphics.DpiY/2540f*scale); e.Graphics.TranslateTransform((offset.Width * 25.4f + adjustedPaper.X)/scale,(offset.Height * 25.4f + adjustedPaper.Y)/scale,MatrixOrder.Prepend); e.Graphics.TranslateTransform(0, -clipRectangle.Top); renderer.Draw(e.Graphics, fPrintPage, clipRectangle, fScribble.Document.Pages[fPrintPage].Size); e.Graphics.Restore(state); if(++fPrintRectangle != clipRectangles.Length) { e.HasMorePages = true; } else { fPrintRectangle = 0; if(++fPrintPage < Math.Min(fScribble.Document.Pages.Count, doc.PrinterSettings.ToPage)) { e.HasMorePages = true; } else { e.HasMorePages = false; fPrintPage = 0; } } }